mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +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
|
val context = LocalContext.current
|
||||||
var firstLoad by rememberSaveable { mutableStateOf(true) }
|
var firstLoad by rememberSaveable { mutableStateOf(true) }
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.init(firstLoad, preferences).join()
|
viewModel.init(preferences).join()
|
||||||
firstLoad = false
|
firstLoad = false
|
||||||
}
|
}
|
||||||
val loading by viewModel.loadingState.observeAsState(LoadingState.Loading)
|
val loading by viewModel.loadingState.observeAsState(LoadingState.Loading)
|
||||||
|
val refreshing by viewModel.refreshState.observeAsState(LoadingState.Loading)
|
||||||
val watchingRows by viewModel.watchingRows.observeAsState(listOf())
|
val watchingRows by viewModel.watchingRows.observeAsState(listOf())
|
||||||
val latestRows by viewModel.latestRows.observeAsState(listOf())
|
val latestRows by viewModel.latestRows.observeAsState(listOf())
|
||||||
LaunchedEffect(loading) {
|
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)
|
is LoadingState.Error -> ErrorMessage(state)
|
||||||
|
|
||||||
LoadingState.Loading,
|
LoadingState.Loading,
|
||||||
|
|
@ -155,7 +156,7 @@ fun HomePage(
|
||||||
items = dialogItems,
|
items = dialogItems,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
loadingState = loading,
|
loadingState = refreshing,
|
||||||
showClock = preferences.appPreferences.interfacePreferences.showClock,
|
showClock = preferences.appPreferences.interfacePreferences.showClock,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -52,18 +52,18 @@ class HomeViewModel
|
||||||
val navDrawerItemRepository: NavDrawerItemRepository,
|
val navDrawerItemRepository: NavDrawerItemRepository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
val loadingState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
val loadingState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
||||||
|
val refreshState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
||||||
val watchingRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
val watchingRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
||||||
val latestRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
val latestRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
||||||
|
|
||||||
private lateinit var preferences: UserPreferences
|
private lateinit var preferences: UserPreferences
|
||||||
|
|
||||||
fun init(
|
fun init(preferences: UserPreferences): Job {
|
||||||
firstLoad: Boolean,
|
val reload = loadingState.value != LoadingState.Success
|
||||||
preferences: UserPreferences,
|
if (reload) {
|
||||||
): Job {
|
|
||||||
if (firstLoad) {
|
|
||||||
loadingState.value = LoadingState.Loading
|
loadingState.value = LoadingState.Loading
|
||||||
}
|
}
|
||||||
|
refreshState.value = LoadingState.Loading
|
||||||
this.preferences = preferences
|
this.preferences = preferences
|
||||||
val prefs = preferences.appPreferences.homePagePreferences
|
val prefs = preferences.appPreferences.homePagePreferences
|
||||||
val limit = prefs.maxItemsPerRow
|
val limit = prefs.maxItemsPerRow
|
||||||
|
|
@ -116,12 +116,13 @@ class HomeViewModel
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
this@HomeViewModel.watchingRows.value = watching
|
this@HomeViewModel.watchingRows.value = watching
|
||||||
if (firstLoad) {
|
if (reload) {
|
||||||
this@HomeViewModel.latestRows.value = pendingLatest
|
this@HomeViewModel.latestRows.value = pendingLatest
|
||||||
}
|
}
|
||||||
loadingState.value = LoadingState.Success
|
loadingState.value = LoadingState.Success
|
||||||
}
|
}
|
||||||
loadLatest(latest)
|
loadLatest(latest)
|
||||||
|
refreshState.setValueOnMain(LoadingState.Success)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -263,7 +264,7 @@ class HomeViewModel
|
||||||
api.playStateApi.markUnplayedItem(itemId)
|
api.playStateApi.markUnplayedItem(itemId)
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
init(false, preferences)
|
init(preferences)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,7 +278,7 @@ class HomeViewModel
|
||||||
api.userLibraryApi.unmarkFavoriteItem(itemId)
|
api.userLibraryApi.unmarkFavoriteItem(itemId)
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
init(false, preferences)
|
init(preferences)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue