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>>()
|
MutableLiveData<Event<ChatRoom>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
val toggledPositionForSelectionEvent: MutableLiveData<Event<Int>> by lazy {
|
|
||||||
MutableLiveData<Event<Int>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val binding: ChatRoomListCellBinding = DataBindingUtil.inflate(
|
val binding: ChatRoomListCellBinding = DataBindingUtil.inflate(
|
||||||
LayoutInflater.from(parent.context),
|
LayoutInflater.from(parent.context),
|
||||||
|
|
|
@ -53,7 +53,9 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
scrollToTop()
|
scrollToTop()
|
||||||
}
|
}
|
||||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
scrollToTop()
|
if (positionStart == 0 && itemCount == 1) {
|
||||||
|
scrollToTop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
||||||
scrollToTop()
|
scrollToTop()
|
||||||
|
@ -144,12 +146,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
adapter.toggledPositionForSelectionEvent.observe(viewLifecycleOwner, {
|
|
||||||
it.consume { position ->
|
|
||||||
listSelectionViewModel.onToggleSelect(position)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
binding.setEditClickListener {
|
binding.setEditClickListener {
|
||||||
listSelectionViewModel.isEditionEnabled.value = true
|
listSelectionViewModel.isEditionEnabled.value = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ class ChatRoomsListViewModel : ErrorReportingViewModel() {
|
||||||
private var chatRoomsToDeleteCount = 0
|
private var chatRoomsToDeleteCount = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
chatRooms.value = getChatRooms()
|
updateChatRooms()
|
||||||
coreContext.core.addListener(listener)
|
coreContext.core.addListener(listener)
|
||||||
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
||||||
}
|
}
|
||||||
|
@ -144,16 +144,10 @@ class ChatRoomsListViewModel : ErrorReportingViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateChatRooms() {
|
private fun updateChatRooms() {
|
||||||
chatRooms.value = getChatRooms()
|
var list = arrayListOf<ChatRoom>()
|
||||||
}
|
|
||||||
|
|
||||||
private fun getChatRooms(): ArrayList<ChatRoom> {
|
list.addAll(coreContext.core.chatRooms)
|
||||||
val list = arrayListOf<ChatRoom>()
|
|
||||||
|
|
||||||
for (room in coreContext.core.chatRooms) {
|
chatRooms.value = list
|
||||||
list.add(room)
|
|
||||||
}
|
|
||||||
|
|
||||||
return list
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,9 @@ class MasterCallLogsFragment : MasterFragment<HistoryMasterFragmentBinding, Call
|
||||||
|
|
||||||
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) {
|
||||||
scrollToTop()
|
if (positionStart == 0 && itemCount == 1) {
|
||||||
|
scrollToTop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue