Fix showing home page refreshes (#194)

Fixes the UI not showing that a refresh is in progress
This commit is contained in:
damontecres 2025-11-11 13:32:01 -05:00 committed by GitHub
parent d6c9b236ef
commit f8a2bb1545
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 11 deletions

View file

@ -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,
)

View file

@ -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)
}
}
}