🛠️ Always show refresh indicator in Browse

* Shows when searching, refreshing and adding
This commit is contained in:
Acclorite 2025-02-11 11:59:19 +02:00
parent 9afcbd237c
commit 93a06aef59
3 changed files with 41 additions and 13 deletions

View file

@ -20,7 +20,7 @@ import ua.acclorite.book_story.domain.library.book.SelectableNullableBook
@Immutable @Immutable
sealed class BrowseEvent { sealed class BrowseEvent {
data class OnRefreshList( data class OnRefreshList(
val showIndicator: Boolean, val loading: Boolean,
val hideSearch: Boolean val hideSearch: Boolean
) : BrowseEvent() ) : BrowseEvent()

View file

@ -57,7 +57,7 @@ class BrowseModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
onEvent( onEvent(
BrowseEvent.OnRefreshList( BrowseEvent.OnRefreshList(
showIndicator = true, loading = true,
hideSearch = true hideSearch = true
) )
) )
@ -66,7 +66,12 @@ class BrowseModel @Inject constructor(
/* Observe channel - - - - - - - - - - - */ /* Observe channel - - - - - - - - - - - */
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
BrowseScreen.refreshListChannel.receiveAsFlow().collectLatest { BrowseScreen.refreshListChannel.receiveAsFlow().collectLatest {
onEvent(BrowseEvent.OnRefreshList(showIndicator = false, hideSearch = false)) onEvent(
BrowseEvent.OnRefreshList(
loading = false,
hideSearch = false
)
)
} }
} }
/* - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - */
@ -85,8 +90,8 @@ class BrowseModel @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,
showSearch = if (event.hideSearch) false else it.showSearch showSearch = if (event.hideSearch) false else it.showSearch
) )
} }
@ -94,7 +99,7 @@ class BrowseModel @Inject constructor(
yield() yield()
getFilesFromDownloads() getFilesFromDownloads()
if (event.showIndicator) delay(500) delay(500)
_state.update { _state.update {
it.copy( it.copy(
isRefreshing = false, isRefreshing = false,
@ -107,7 +112,12 @@ class BrowseModel @Inject constructor(
is BrowseEvent.OnSearchVisibility -> { is BrowseEvent.OnSearchVisibility -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
if (!event.show) { if (!event.show) {
getFilesFromDownloads("") onEvent(
BrowseEvent.OnRefreshList(
loading = false,
hideSearch = true
)
)
} else { } else {
_state.update { _state.update {
it.copy( it.copy(
@ -156,7 +166,12 @@ class BrowseModel @Inject constructor(
is BrowseEvent.OnSearch -> { is BrowseEvent.OnSearch -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
getFilesFromDownloads() onEvent(
BrowseEvent.OnRefreshList(
loading = false,
hideSearch = false
)
)
} }
} }
@ -292,7 +307,7 @@ class BrowseModel @Inject constructor(
} }
onEvent( onEvent(
BrowseEvent.OnRefreshList( BrowseEvent.OnRefreshList(
showIndicator = true, loading = true,
hideSearch = false hideSearch = false
) )
) )
@ -318,7 +333,12 @@ class BrowseModel @Inject constructor(
if (permissionGranted) { if (permissionGranted) {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
getFilesFromDownloads() onEvent(
BrowseEvent.OnRefreshList(
loading = true,
hideSearch = false
)
)
} }
} }
} }
@ -412,7 +432,10 @@ class BrowseModel @Inject constructor(
) )
} }
onEvent( onEvent(
BrowseEvent.OnRefreshList(showIndicator = false, hideSearch = false) BrowseEvent.OnRefreshList(
loading = false,
hideSearch = false
)
) )
onEvent(BrowseEvent.OnClearSelectedFiles) onEvent(BrowseEvent.OnClearSelectedFiles)
@ -440,7 +463,12 @@ class BrowseModel @Inject constructor(
dialog = null dialog = null
) )
} }
onEvent(BrowseEvent.OnRefreshList(showIndicator = false, hideSearch = false)) onEvent(
BrowseEvent.OnRefreshList(
loading = false,
hideSearch = false
)
)
onEvent(BrowseEvent.OnClearSelectedFiles) onEvent(BrowseEvent.OnClearSelectedFiles)
} }
} }

View file

@ -87,7 +87,7 @@ object BrowseScreen : Screen, Parcelable {
onRefresh = { onRefresh = {
screenModel.onEvent( screenModel.onEvent(
BrowseEvent.OnRefreshList( BrowseEvent.OnRefreshList(
showIndicator = true, loading = false,
hideSearch = true hideSearch = true
) )
) )