Fix scrolling issues in chat
This commit is contained in:
parent
fb916eeea3
commit
153932ba54
2 changed files with 11 additions and 11 deletions
|
@ -39,6 +39,7 @@ import androidx.navigation.fragment.findNavController
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
|
@ -70,12 +71,7 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
|
|
||||||
private val observer = object : RecyclerView.AdapterDataObserver() {
|
private val observer = object : RecyclerView.AdapterDataObserver() {
|
||||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
if (itemCount == 1 && positionStart > 0) {
|
|
||||||
adapter.notifyItemChanged(positionStart - 1) // For grouping purposes
|
adapter.notifyItemChanged(positionStart - 1) // For grouping purposes
|
||||||
scrollToBottom()
|
|
||||||
} else if (positionStart > 0) {
|
|
||||||
scrollToBottom()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +108,7 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
val remoteSipUri = arguments?.getString("RemoteSipUri")
|
val remoteSipUri = arguments?.getString("RemoteSipUri")
|
||||||
|
|
||||||
val textToShare = arguments?.getString("TextToShare")
|
val textToShare = arguments?.getString("TextToShare")
|
||||||
val filestoShare = arguments?.getStringArrayList("FilesToShare")
|
val filesToShare = arguments?.getStringArrayList("FilesToShare")
|
||||||
|
|
||||||
arguments?.clear()
|
arguments?.clear()
|
||||||
if (localSipUri != null && remoteSipUri != null) {
|
if (localSipUri != null && remoteSipUri != null) {
|
||||||
|
@ -189,8 +185,11 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
|
|
||||||
listViewModel.scrollToBottomOnMessageReceivedEvent.observe(viewLifecycleOwner, {
|
listViewModel.scrollToBottomOnMessageReceivedEvent.observe(viewLifecycleOwner, {
|
||||||
it.consume {
|
it.consume {
|
||||||
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
|
delay(100)
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
listViewModel.requestWriteExternalStoragePermissionEvent.observe(viewLifecycleOwner, {
|
listViewModel.requestWriteExternalStoragePermissionEvent.observe(viewLifecycleOwner, {
|
||||||
|
@ -333,8 +332,8 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
Log.i("[Chat Room] Found text to share")
|
Log.i("[Chat Room] Found text to share")
|
||||||
chatSendingViewModel.textToSend.value = textToShare
|
chatSendingViewModel.textToSend.value = textToShare
|
||||||
}
|
}
|
||||||
if (filestoShare?.isNotEmpty() == true) {
|
if (filesToShare?.isNotEmpty() == true) {
|
||||||
for (path in filestoShare) {
|
for (path in filesToShare) {
|
||||||
Log.i("[Chat Room] Found $path file to share")
|
Log.i("[Chat Room] Found $path file to share")
|
||||||
chatSendingViewModel.addAttachment(path)
|
chatSendingViewModel.addAttachment(path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,6 @@ class ChatMessagesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scrollToBottomOnMessageReceivedEvent.value = Event(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addEvent(eventLog)
|
addEvent(eventLog)
|
||||||
|
@ -212,6 +211,8 @@ class ChatMessagesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
|
||||||
list.add(eventLog)
|
list.add(eventLog)
|
||||||
}
|
}
|
||||||
events.value = list
|
events.value = list
|
||||||
|
|
||||||
|
scrollToBottomOnMessageReceivedEvent.value = Event(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEvents(): ArrayList<EventLog> {
|
private fun getEvents(): ArrayList<EventLog> {
|
||||||
|
|
Loading…
Reference in a new issue