mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fix showing home page refreshes (#194)
Fixes the UI not showing that a refresh is in progress
This commit is contained in:
parent
d6c9b236ef
commit
f8a2bb1545
2 changed files with 13 additions and 11 deletions
|
|
@ -87,10 +87,11 @@ fun HomePage(
|
|||
val context = LocalContext.current
|
||||
var firstLoad by rememberSaveable { mutableStateOf(true) }
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.init(firstLoad, preferences).join()
|
||||
viewModel.init(preferences).join()
|
||||
firstLoad = false
|
||||
}
|
||||
val loading by viewModel.loadingState.observeAsState(LoadingState.Loading)
|
||||
val refreshing by viewModel.refreshState.observeAsState(LoadingState.Loading)
|
||||
val watchingRows by viewModel.watchingRows.observeAsState(listOf())
|
||||
val latestRows by viewModel.latestRows.observeAsState(listOf())
|
||||
LaunchedEffect(loading) {
|
||||
|
|
@ -107,7 +108,7 @@ fun HomePage(
|
|||
}
|
||||
}
|
||||
|
||||
when (val state = if (firstLoad) loading else LoadingState.Success) {
|
||||
when (val state = loading) {
|
||||
is LoadingState.Error -> ErrorMessage(state)
|
||||
|
||||
LoadingState.Loading,
|
||||
|
|
@ -155,7 +156,7 @@ fun HomePage(
|
|||
items = dialogItems,
|
||||
)
|
||||
},
|
||||
loadingState = loading,
|
||||
loadingState = refreshing,
|
||||
showClock = preferences.appPreferences.interfacePreferences.showClock,
|
||||
modifier = modifier,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -52,18 +52,18 @@ class HomeViewModel
|
|||
val navDrawerItemRepository: NavDrawerItemRepository,
|
||||
) : ViewModel() {
|
||||
val loadingState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
||||
val refreshState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
||||
val watchingRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
||||
val latestRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
||||
|
||||
private lateinit var preferences: UserPreferences
|
||||
|
||||
fun init(
|
||||
firstLoad: Boolean,
|
||||
preferences: UserPreferences,
|
||||
): Job {
|
||||
if (firstLoad) {
|
||||
fun init(preferences: UserPreferences): Job {
|
||||
val reload = loadingState.value != LoadingState.Success
|
||||
if (reload) {
|
||||
loadingState.value = LoadingState.Loading
|
||||
}
|
||||
refreshState.value = LoadingState.Loading
|
||||
this.preferences = preferences
|
||||
val prefs = preferences.appPreferences.homePagePreferences
|
||||
val limit = prefs.maxItemsPerRow
|
||||
|
|
@ -116,12 +116,13 @@ class HomeViewModel
|
|||
|
||||
withContext(Dispatchers.Main) {
|
||||
this@HomeViewModel.watchingRows.value = watching
|
||||
if (firstLoad) {
|
||||
if (reload) {
|
||||
this@HomeViewModel.latestRows.value = pendingLatest
|
||||
}
|
||||
loadingState.value = LoadingState.Success
|
||||
}
|
||||
loadLatest(latest)
|
||||
refreshState.setValueOnMain(LoadingState.Success)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +264,7 @@ class HomeViewModel
|
|||
api.playStateApi.markUnplayedItem(itemId)
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
init(false, preferences)
|
||||
init(preferences)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -277,7 +278,7 @@ class HomeViewModel
|
|||
api.userLibraryApi.unmarkFavoriteItem(itemId)
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
init(false, preferences)
|
||||
init(preferences)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue