From 9d5433a85747b4db5c95b84dba51469d8ab8218e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 8 Aug 2019 14:14:10 +0200 Subject: [PATCH] Show sync progress also in room detail screen (#403) --- CHANGES.md | 2 +- .../home/room/detail/RoomDetailFragment.kt | 9 +++++++ .../home/room/detail/RoomDetailViewModel.kt | 12 +++++++++ .../home/room/detail/RoomDetailViewState.kt | 5 ++-- .../main/res/layout/fragment_room_detail.xml | 27 +++++++++++++++++-- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3a9e37a511..f1eca45db1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,7 +14,7 @@ Improvements: - Add "View Edit History" item in the message bottom sheet (#401) Other changes: - - + - Show sync progress also in room detail screen (#403) Bugfix: - Edited message: link confusion when (edited) appears in body (#398) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index ebaa006b72..70793becce 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -65,6 +65,7 @@ import im.vector.matrix.android.api.session.room.send.SendState import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent import im.vector.matrix.android.api.session.room.timeline.getTextEditableContent +import im.vector.matrix.android.api.session.sync.SyncState import im.vector.matrix.android.api.session.user.model.User import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent @@ -247,6 +248,14 @@ class RoomDetailFragment : is SendMode.REPLY -> enterSpecialMode(mode.timelineEvent, R.drawable.ic_reply, false) } } + + roomDetailViewModel.selectSubscribe(RoomDetailViewState::syncState) { syncState -> + syncProgressBar.visibility = when (syncState) { + is SyncState.RUNNING -> if (syncState.afterPause) View.VISIBLE else View.GONE + else -> View.GONE + } + syncProgressBarWrap.visibility = syncProgressBar.visibility + } } private fun setupNotificationView() { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index fe87117dcd..ec372a4d62 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -103,6 +103,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } init { + observeSyncState() observeRoomSummary() observeEventDisplayedActions() observeSummaryState() @@ -631,6 +632,17 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro .disposeOnClear() } + private fun observeSyncState() { + session.rx() + .liveSyncState() + .subscribe { syncState -> + setState { + copy(syncState = syncState) + } + } + .disposeOnClear() + } + private fun observeRoomSummary() { room.rx().liveRoomSummary() .execute { async -> diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt index 77c1c63cb6..d8358efe16 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt @@ -21,9 +21,9 @@ import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.Uninitialized import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.model.RoomSummary -import im.vector.matrix.android.api.session.room.model.tombstone.RoomTombstoneContent import im.vector.matrix.android.api.session.room.timeline.Timeline import im.vector.matrix.android.api.session.room.timeline.TimelineEvent +import im.vector.matrix.android.api.session.sync.SyncState import im.vector.matrix.android.api.session.user.model.User /** @@ -50,7 +50,8 @@ data class RoomDetailViewState( val sendMode: SendMode = SendMode.REGULAR, val isEncrypted: Boolean = false, val tombstoneEvent: Event? = null, - val tombstoneEventHandling: Async = Uninitialized + val tombstoneEventHandling: Async = Uninitialized, + val syncState: SyncState = SyncState.IDLE ) : MvRxState { constructor(args: RoomDetailArgs) : this(roomId = args.roomId, eventId = args.eventId) diff --git a/vector/src/main/res/layout/fragment_room_detail.xml b/vector/src/main/res/layout/fragment_room_detail.xml index 81a5b33dad..dee37e9d0f 100644 --- a/vector/src/main/res/layout/fragment_room_detail.xml +++ b/vector/src/main/res/layout/fragment_room_detail.xml @@ -11,8 +11,8 @@ style="@style/VectorToolbarStyle" android:layout_width="0dp" android:layout_height="?actionBarSize" - android:transitionName="toolbar" android:elevation="4dp" + android:transitionName="toolbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> @@ -71,6 +71,29 @@ + + + + + +