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.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()
|
||||
}
|
||||
adapter.notifyItemChanged(positionStart - 1) // For grouping purposes
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,7 +185,10 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
|
||||
listViewModel.scrollToBottomOnMessageReceivedEvent.observe(viewLifecycleOwner, {
|
||||
it.consume {
|
||||
scrollToBottom()
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
delay(100)
|
||||
scrollToBottom()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue