Keep position in calls history & chat rooms lists when going back
This commit is contained in:
parent
23dc18d41a
commit
f34a2f65c9
4 changed files with 10 additions and 22 deletions
|
@ -42,10 +42,6 @@ class ChatRoomsListAdapter(
|
|||
MutableLiveData<Event<ChatRoom>>()
|
||||
}
|
||||
|
||||
val toggledPositionForSelectionEvent: MutableLiveData<Event<Int>> by lazy {
|
||||
MutableLiveData<Event<Int>>()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding: ChatRoomListCellBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
|
|
|
@ -53,8 +53,10 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
|||
scrollToTop()
|
||||
}
|
||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||
if (positionStart == 0 && itemCount == 1) {
|
||||
scrollToTop()
|
||||
}
|
||||
}
|
||||
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
||||
scrollToTop()
|
||||
}
|
||||
|
@ -144,12 +146,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
|||
}
|
||||
})
|
||||
|
||||
adapter.toggledPositionForSelectionEvent.observe(viewLifecycleOwner, {
|
||||
it.consume { position ->
|
||||
listSelectionViewModel.onToggleSelect(position)
|
||||
}
|
||||
})
|
||||
|
||||
binding.setEditClickListener {
|
||||
listSelectionViewModel.isEditionEnabled.value = true
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class ChatRoomsListViewModel : ErrorReportingViewModel() {
|
|||
private var chatRoomsToDeleteCount = 0
|
||||
|
||||
init {
|
||||
chatRooms.value = getChatRooms()
|
||||
updateChatRooms()
|
||||
coreContext.core.addListener(listener)
|
||||
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
||||
}
|
||||
|
@ -144,16 +144,10 @@ class ChatRoomsListViewModel : ErrorReportingViewModel() {
|
|||
}
|
||||
|
||||
private fun updateChatRooms() {
|
||||
chatRooms.value = getChatRooms()
|
||||
}
|
||||
var list = arrayListOf<ChatRoom>()
|
||||
|
||||
private fun getChatRooms(): ArrayList<ChatRoom> {
|
||||
val list = arrayListOf<ChatRoom>()
|
||||
list.addAll(coreContext.core.chatRooms)
|
||||
|
||||
for (room in coreContext.core.chatRooms) {
|
||||
list.add(room)
|
||||
}
|
||||
|
||||
return list
|
||||
chatRooms.value = list
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,9 +49,11 @@ class MasterCallLogsFragment : MasterFragment<HistoryMasterFragmentBinding, Call
|
|||
|
||||
private val observer = object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||
if (positionStart == 0 && itemCount == 1) {
|
||||
scrollToTop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int = R.layout.history_master_fragment
|
||||
|
||||
|
|
Loading…
Reference in a new issue