Fix scrolling issues in chat

This commit is contained in:
Sylvain Berfini 2021-06-06 23:06:06 +02:00
parent fb916eeea3
commit 153932ba54
2 changed files with 11 additions and 11 deletions

View file

@ -39,6 +39,7 @@ import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import java.io.File
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
@ -70,12 +71,7 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
private val observer = object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
if (itemCount == 1 && positionStart > 0) {
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 textToShare = arguments?.getString("TextToShare")
val filestoShare = arguments?.getStringArrayList("FilesToShare")
val filesToShare = arguments?.getStringArrayList("FilesToShare")
arguments?.clear()
if (localSipUri != null && remoteSipUri != null) {
@ -189,8 +185,11 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
listViewModel.scrollToBottomOnMessageReceivedEvent.observe(viewLifecycleOwner, {
it.consume {
viewLifecycleOwner.lifecycleScope.launch {
delay(100)
scrollToBottom()
}
}
})
listViewModel.requestWriteExternalStoragePermissionEvent.observe(viewLifecycleOwner, {
@ -333,8 +332,8 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
Log.i("[Chat Room] Found text to share")
chatSendingViewModel.textToSend.value = textToShare
}
if (filestoShare?.isNotEmpty() == true) {
for (path in filestoShare) {
if (filesToShare?.isNotEmpty() == true) {
for (path in filesToShare) {
Log.i("[Chat Room] Found $path file to share")
chatSendingViewModel.addAttachment(path)
}

View file

@ -83,7 +83,6 @@ class ChatMessagesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
}
}
}
scrollToBottomOnMessageReceivedEvent.value = Event(true)
}
addEvent(eventLog)
@ -212,6 +211,8 @@ class ChatMessagesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
list.add(eventLog)
}
events.value = list
scrollToBottomOnMessageReceivedEvent.value = Event(true)
}
private fun getEvents(): ArrayList<EventLog> {