feat: add pull-to-refresh gesture to HomeScreen

Wrap HomeContent with PullToRefreshBox to allow refreshing library,
continue watching, and next up sections by pulling down. Also fix
refreshHomeData to suspend until loading completes so the refresh
indicator dismisses properly.
This commit is contained in:
2026-03-03 21:18:50 +01:00
parent cc972e0e89
commit 5ca127434d
4 changed files with 38 additions and 2 deletions

View File

@@ -13,7 +13,10 @@ import hu.bbara.purefin.core.data.navigation.Route
import hu.bbara.purefin.core.data.navigation.SeriesDto
import hu.bbara.purefin.core.data.session.UserSessionRepository
import hu.bbara.purefin.core.model.Media
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -31,6 +34,9 @@ class HomePageViewModel @Inject constructor(
private val refreshHomeDataUseCase: RefreshHomeDataUseCase
) : ViewModel() {
private val _isRefreshing = MutableStateFlow(false)
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
private val _url = userSessionRepository.serverUrl.stateIn(
scope = viewModelScope,
started = SharingStarted.Eagerly,
@@ -195,6 +201,19 @@ class HomePageViewModel @Inject constructor(
}
}
fun onRefresh() {
viewModelScope.launch {
_isRefreshing.value = true
try {
refreshHomeDataUseCase()
} catch (e: Exception) {
// Refresh is best-effort; don't crash on failure
} finally {
_isRefreshing.value = false
}
}
}
fun logout() {
viewModelScope.launch {
userSessionRepository.setLoggedIn(false)