🛠️ Always show refresh indicator in Browse
* Shows when searching, refreshing and adding
This commit is contained in:
parent
9afcbd237c
commit
93a06aef59
3 changed files with 41 additions and 13 deletions
|
|
@ -20,7 +20,7 @@ import ua.acclorite.book_story.domain.library.book.SelectableNullableBook
|
|||
@Immutable
|
||||
sealed class BrowseEvent {
|
||||
data class OnRefreshList(
|
||||
val showIndicator: Boolean,
|
||||
val loading: Boolean,
|
||||
val hideSearch: Boolean
|
||||
) : BrowseEvent()
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class BrowseModel @Inject constructor(
|
|||
viewModelScope.launch(Dispatchers.IO) {
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
showIndicator = true,
|
||||
loading = true,
|
||||
hideSearch = true
|
||||
)
|
||||
)
|
||||
|
|
@ -66,7 +66,12 @@ class BrowseModel @Inject constructor(
|
|||
/* Observe channel - - - - - - - - - - - */
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
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) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
isRefreshing = event.showIndicator,
|
||||
isLoading = !event.showIndicator,
|
||||
isRefreshing = true,
|
||||
isLoading = event.loading,
|
||||
showSearch = if (event.hideSearch) false else it.showSearch
|
||||
)
|
||||
}
|
||||
|
|
@ -94,7 +99,7 @@ class BrowseModel @Inject constructor(
|
|||
yield()
|
||||
getFilesFromDownloads()
|
||||
|
||||
if (event.showIndicator) delay(500)
|
||||
delay(500)
|
||||
_state.update {
|
||||
it.copy(
|
||||
isRefreshing = false,
|
||||
|
|
@ -107,7 +112,12 @@ class BrowseModel @Inject constructor(
|
|||
is BrowseEvent.OnSearchVisibility -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (!event.show) {
|
||||
getFilesFromDownloads("")
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
loading = false,
|
||||
hideSearch = true
|
||||
)
|
||||
)
|
||||
} else {
|
||||
_state.update {
|
||||
it.copy(
|
||||
|
|
@ -156,7 +166,12 @@ class BrowseModel @Inject constructor(
|
|||
|
||||
is BrowseEvent.OnSearch -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
getFilesFromDownloads()
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
loading = false,
|
||||
hideSearch = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +307,7 @@ class BrowseModel @Inject constructor(
|
|||
}
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
showIndicator = true,
|
||||
loading = true,
|
||||
hideSearch = false
|
||||
)
|
||||
)
|
||||
|
|
@ -318,7 +333,12 @@ class BrowseModel @Inject constructor(
|
|||
|
||||
if (permissionGranted) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
getFilesFromDownloads()
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
loading = true,
|
||||
hideSearch = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -412,7 +432,10 @@ class BrowseModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(showIndicator = false, hideSearch = false)
|
||||
BrowseEvent.OnRefreshList(
|
||||
loading = false,
|
||||
hideSearch = false
|
||||
)
|
||||
)
|
||||
onEvent(BrowseEvent.OnClearSelectedFiles)
|
||||
|
||||
|
|
@ -440,7 +463,12 @@ class BrowseModel @Inject constructor(
|
|||
dialog = null
|
||||
)
|
||||
}
|
||||
onEvent(BrowseEvent.OnRefreshList(showIndicator = false, hideSearch = false))
|
||||
onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
loading = false,
|
||||
hideSearch = false
|
||||
)
|
||||
)
|
||||
onEvent(BrowseEvent.OnClearSelectedFiles)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ object BrowseScreen : Screen, Parcelable {
|
|||
onRefresh = {
|
||||
screenModel.onEvent(
|
||||
BrowseEvent.OnRefreshList(
|
||||
showIndicator = true,
|
||||
loading = false,
|
||||
hideSearch = true
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue