Convert to ViewEvents -> RoomDetailViewModel part 3

This commit is contained in:
Benoit Marty 2020-02-07 19:41:23 +01:00
parent bdb1f850b2
commit 27e217fce5
3 changed files with 14 additions and 15 deletions

View File

@ -261,16 +261,6 @@ class RoomDetailFragment @Inject constructor(
}
.disposeOnDestroyView()
roomDetailViewModel.navigateToEvent.observeEvent(this) {
val scrollPosition = timelineEventController.searchPositionOfEvent(it)
if (scrollPosition == null) {
scrollOnHighlightedEventCallback.scheduleScrollTo(it)
} else {
recyclerView.stopScroll()
layoutManager.scrollToPosition(scrollPosition)
}
}
roomDetailViewModel.fileTooBigEvent.observeEvent(this) {
displayFileTooBigWarning(it)
}
@ -309,6 +299,7 @@ class RoomDetailFragment @Inject constructor(
is RoomDetailViewEvents.ActionSuccess -> displayRoomDetailActionSuccess(it)
is RoomDetailViewEvents.ActionFailure -> displayRoomDetailActionFailure(it)
is RoomDetailViewEvents.ShowMessage -> showSnackWithMessage(it.message, Snackbar.LENGTH_LONG)
is RoomDetailViewEvents.NavigateToEvent -> navigateToEvent(it)
is RoomDetailViewEvents.SendMessageResult -> renderSendMessageResult(it)
}.exhaustive
}
@ -364,6 +355,16 @@ class RoomDetailFragment @Inject constructor(
jumpToReadMarkerView.callback = this
}
private fun navigateToEvent(action: RoomDetailViewEvents.NavigateToEvent) {
val scrollPosition = timelineEventController.searchPositionOfEvent(action.eventId)
if (scrollPosition == null) {
scrollOnHighlightedEventCallback.scheduleScrollTo(action.eventId)
} else {
recyclerView.stopScroll()
layoutManager.scrollToPosition(scrollPosition)
}
}
private fun displayFileTooBigWarning(error: FileTooBigError) {
AlertDialog.Builder(requireActivity())
.setTitle(R.string.dialog_title_error)

View File

@ -32,6 +32,8 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
data class ShowMessage(val message: String) : RoomDetailViewEvents()
data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents()
abstract class SendMessageResult : RoomDetailViewEvents()
object MessageSent : SendMessageResult()

View File

@ -314,10 +314,6 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}
// TODO Cleanup this and use ViewEvents
private val _navigateToEvent = MutableLiveData<LiveEvent<String>>()
val navigateToEvent: LiveData<LiveEvent<String>>
get() = _navigateToEvent
private val _fileTooBigEvent = MutableLiveData<LiveEvent<FileTooBigError>>()
val fileTooBigEvent: LiveData<LiveEvent<FileTooBigError>>
get() = _fileTooBigEvent
@ -735,7 +731,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
if (action.highlight) {
setState { copy(highlightedEventId = correctedEventId) }
}
_navigateToEvent.postLiveEvent(correctedEventId)
_viewEvents.post(RoomDetailViewEvents.NavigateToEvent(correctedEventId))
}
private fun handleResendEvent(action: RoomDetailAction.ResendMessage) {