Add loader to thread list

This commit is contained in:
ariskotsomitopoulos 2022-03-29 16:26:47 +03:00
parent abbf798ccf
commit 0f7d6a1946
4 changed files with 34 additions and 6 deletions

View file

@ -113,7 +113,15 @@ class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState
private fun fetchThreadList() {
viewModelScope.launch {
isLoading(true)
room?.fetchThreadSummaries()
isLoading(false)
}
}
private fun isLoading(show: Boolean) {
setState {
copy(isLoading = show)
}
}

View file

@ -27,6 +27,7 @@ data class ThreadListViewState(
val threadSummaryList: Async<List<ThreadSummary>> = Uninitialized,
val rootThreadEventList: Async<List<ThreadTimelineEvent>> = Uninitialized,
val shouldFilterThreads: Boolean = false,
val isLoading: Boolean = false,
val roomId: String
) : MavericksState {
constructor(args: ThreadListArgs) : this(roomId = args.roomId)

View file

@ -104,6 +104,11 @@ class ThreadListFragment @Inject constructor(
override fun invalidate() = withState(threadListViewModel) { state ->
renderEmptyStateIfNeeded(state)
threadListController.update(state)
renderLoaderIfNeeded(state)
}
private fun renderLoaderIfNeeded(state: ThreadListViewState) {
views.threadListProgressBar.isVisible = state.isLoading
}
private fun renderToolbar() {

View file

@ -37,6 +37,21 @@
tools:listitem="@layout/item_thread"
tools:visibility="gone" />
<ProgressBar
android:id="@+id/threadListProgressBar"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:indeterminate="true"
android:visibility="gone"
android:layout_marginTop="-6dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/threadListAppBarLayout"
tools:visibility="visible" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/threadListEmptyConstraintLayout"
android:layout_width="0dp"
@ -54,7 +69,6 @@
android:id="@+id/threadListEmptyImageView"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="24dp"
android:background="@drawable/bg_rounded_button"
@ -75,13 +89,13 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/thread_list_empty_title"
android:textColor="?vctr_content_primary"
app:layout_constraintBottom_toTopOf="@id/threadListEmptySubtitleTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@id/threadListEmptyImageView"
android:text="@string/thread_list_empty_title" />
app:layout_constraintTop_toBottomOf="@id/threadListEmptyImageView" />
<TextView
android:id="@+id/threadListEmptySubtitleTextView"
@ -90,12 +104,12 @@
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/thread_list_empty_subtitle"
android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toTopOf="@id/threadListEmptyNoticeTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/threadListEmptyTitleTextView"
android:text="@string/thread_list_empty_subtitle" />
app:layout_constraintTop_toBottomOf="@id/threadListEmptyTitleTextView" />
<TextView
android:id="@+id/threadListEmptyNoticeTextView"