🛠️ Always show refresh indicator in Library

* Shows when searching and refreshing
This commit is contained in:
Acclorite 2025-02-11 13:03:26 +02:00
parent 7be0fe6d0c
commit 14ac7dbc82
3 changed files with 29 additions and 10 deletions

View file

@ -15,7 +15,7 @@ import ua.acclorite.book_story.domain.library.category.CategoryWithBooks
@Immutable @Immutable
sealed class LibraryEvent { sealed class LibraryEvent {
data class OnRefreshList( data class OnRefreshList(
val showIndicator: Boolean, val loading: Boolean,
val hideSearch: Boolean val hideSearch: Boolean
) : LibraryEvent() ) : LibraryEvent()

View file

@ -46,7 +46,12 @@ class LibraryModel @Inject constructor(
init { init {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
getBooksFromDatabase("") onEvent(
LibraryEvent.OnRefreshList(
loading = true,
hideSearch = true
)
)
} }
/* Observe channel - - - - - - - - - - - */ /* Observe channel - - - - - - - - - - - */
@ -55,7 +60,12 @@ class LibraryModel @Inject constructor(
delay(it) delay(it)
yield() 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) { refreshJob = viewModelScope.launch(Dispatchers.IO) {
_state.update { _state.update {
it.copy( it.copy(
isRefreshing = event.showIndicator, isRefreshing = true,
isLoading = !event.showIndicator, isLoading = event.loading,
hasSelectedItems = false,
showSearch = if (event.hideSearch) false else it.showSearch showSearch = if (event.hideSearch) false else it.showSearch
) )
} }
@ -81,7 +90,7 @@ class LibraryModel @Inject constructor(
yield() yield()
getBooksFromDatabase() getBooksFromDatabase()
if (event.showIndicator) delay(500) delay(500)
_state.update { _state.update {
it.copy( it.copy(
isRefreshing = false, isRefreshing = false,
@ -94,7 +103,12 @@ class LibraryModel @Inject constructor(
is LibraryEvent.OnSearchVisibility -> { is LibraryEvent.OnSearchVisibility -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
if (!event.show) { if (!event.show) {
getBooksFromDatabase("") onEvent(
LibraryEvent.OnRefreshList(
loading = false,
hideSearch = true
)
)
} else { } else {
_state.update { _state.update {
it.copy( it.copy(
@ -130,7 +144,12 @@ class LibraryModel @Inject constructor(
is LibraryEvent.OnSearch -> { is LibraryEvent.OnSearch -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
getBooksFromDatabase() onEvent(
LibraryEvent.OnRefreshList(
loading = false,
hideSearch = false
)
)
} }
} }

View file

@ -98,7 +98,7 @@ object LibraryScreen : Screen, Parcelable {
onRefresh = { onRefresh = {
screenModel.onEvent( screenModel.onEvent(
LibraryEvent.OnRefreshList( LibraryEvent.OnRefreshList(
showIndicator = true, loading = false,
hideSearch = true hideSearch = true
) )
) )