From 14ac7dbc8289368fca3f6c4c9fe665b645e8d434 Mon Sep 17 00:00:00 2001 From: Acclorite <140836141+Acclorite@users.noreply.github.com> Date: Tue, 11 Feb 2025 13:03:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Always=20show=20refresh?= =?UTF-8?q?=20indicator=20in=20Library?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Shows when searching and refreshing --- .../book_story/ui/library/LibraryEvent.kt | 2 +- .../book_story/ui/library/LibraryModel.kt | 35 ++++++++++++++----- .../book_story/ui/library/LibraryScreen.kt | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryEvent.kt b/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryEvent.kt index 267b11ef..9216d5ec 100644 --- a/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryEvent.kt +++ b/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryEvent.kt @@ -15,7 +15,7 @@ import ua.acclorite.book_story.domain.library.category.CategoryWithBooks @Immutable sealed class LibraryEvent { data class OnRefreshList( - val showIndicator: Boolean, + val loading: Boolean, val hideSearch: Boolean ) : LibraryEvent() diff --git a/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryModel.kt b/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryModel.kt index d1caa08b..b9ada36a 100644 --- a/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryModel.kt +++ b/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryModel.kt @@ -46,7 +46,12 @@ class LibraryModel @Inject constructor( init { viewModelScope.launch(Dispatchers.IO) { - getBooksFromDatabase("") + onEvent( + LibraryEvent.OnRefreshList( + loading = true, + hideSearch = true + ) + ) } /* Observe channel - - - - - - - - - - - */ @@ -55,7 +60,12 @@ class LibraryModel @Inject constructor( delay(it) yield() - onEvent(LibraryEvent.OnRefreshList(showIndicator = false, hideSearch = false)) + onEvent( + LibraryEvent.OnRefreshList( + loading = false, + hideSearch = false + ) + ) } } /* - - - - - - - - - - - - - - - - - - - */ @@ -71,9 +81,8 @@ class LibraryModel @Inject constructor( refreshJob = viewModelScope.launch(Dispatchers.IO) { _state.update { it.copy( - isRefreshing = event.showIndicator, - isLoading = !event.showIndicator, - hasSelectedItems = false, + isRefreshing = true, + isLoading = event.loading, showSearch = if (event.hideSearch) false else it.showSearch ) } @@ -81,7 +90,7 @@ class LibraryModel @Inject constructor( yield() getBooksFromDatabase() - if (event.showIndicator) delay(500) + delay(500) _state.update { it.copy( isRefreshing = false, @@ -94,7 +103,12 @@ class LibraryModel @Inject constructor( is LibraryEvent.OnSearchVisibility -> { viewModelScope.launch(Dispatchers.IO) { if (!event.show) { - getBooksFromDatabase("") + onEvent( + LibraryEvent.OnRefreshList( + loading = false, + hideSearch = true + ) + ) } else { _state.update { it.copy( @@ -130,7 +144,12 @@ class LibraryModel @Inject constructor( is LibraryEvent.OnSearch -> { viewModelScope.launch(Dispatchers.IO) { - getBooksFromDatabase() + onEvent( + LibraryEvent.OnRefreshList( + loading = false, + hideSearch = false + ) + ) } } diff --git a/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryScreen.kt b/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryScreen.kt index e357a1dd..fae73161 100644 --- a/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryScreen.kt +++ b/app/src/main/java/ua/acclorite/book_story/ui/library/LibraryScreen.kt @@ -98,7 +98,7 @@ object LibraryScreen : Screen, Parcelable { onRefresh = { screenModel.onEvent( LibraryEvent.OnRefreshList( - showIndicator = true, + loading = false, hideSearch = true ) )