Fix unnecessary home page reloads (#2008)
## Description Fixes the home page reloading from scratch when the app is resumed This happened because the `userDto` is updated on app resume and since it has a last accessed timestamp, it would always different and trigger a reload. ### Related issues Bug introduced by #1981 ### Testing Emulator ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
365f8f8ada
commit
65954a99eb
9 changed files with 61 additions and 36 deletions
|
|
@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope
|
|||
import com.github.damontecres.wholphin.data.ServerRepository
|
||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowConfig
|
||||
import com.github.damontecres.wholphin.data.model.ServerUserConfig
|
||||
import com.github.damontecres.wholphin.preferences.AppPreferences
|
||||
import com.github.damontecres.wholphin.services.BackdropService
|
||||
import com.github.damontecres.wholphin.services.DatePlayedService
|
||||
|
|
@ -19,7 +20,6 @@ import com.github.damontecres.wholphin.services.NavigationManager
|
|||
import com.github.damontecres.wholphin.services.ServerReportService
|
||||
import com.github.damontecres.wholphin.services.UserPreferencesService
|
||||
import com.github.damontecres.wholphin.services.deleteItem
|
||||
import com.github.damontecres.wholphin.services.tvAccess
|
||||
import com.github.damontecres.wholphin.ui.collectLatestIn
|
||||
import com.github.damontecres.wholphin.ui.combinePair
|
||||
import com.github.damontecres.wholphin.ui.data.RowColumn
|
||||
|
|
@ -48,7 +48,6 @@ import kotlinx.coroutines.sync.withPermit
|
|||
import kotlinx.coroutines.withContext
|
||||
import org.jellyfin.sdk.api.client.exception.InvalidStatusException
|
||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||
import org.jellyfin.sdk.model.api.UserDto
|
||||
import timber.log.Timber
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
|
|
@ -85,20 +84,27 @@ class HomeViewModel
|
|||
userDto?.id,
|
||||
settings != HomePageResolvedSettings.EMPTY,
|
||||
)
|
||||
_state.update { HomeState.EMPTY }
|
||||
// Timber.v("userDto=%s", userDto)
|
||||
dataLoadingJob?.cancel()
|
||||
if (userDto == null) {
|
||||
Timber.d("UserDto is null")
|
||||
_state.update { HomeState.EMPTY }
|
||||
return@collectLatestIn
|
||||
}
|
||||
if (settings == HomePageResolvedSettings.EMPTY) {
|
||||
Timber.d("Home settings are empty")
|
||||
_state.update { HomeState.EMPTY }
|
||||
return@collectLatestIn
|
||||
}
|
||||
if (userDto.id != settings.userId) {
|
||||
Timber.d("User IDs don't match: %s vs %s", userDto?.id, settings.userId)
|
||||
_state.update { HomeState.EMPTY }
|
||||
return@collectLatestIn
|
||||
}
|
||||
if (state.value.settings.userId != settings.userId) {
|
||||
Timber.d("User changed")
|
||||
_state.update { HomeState.EMPTY }
|
||||
}
|
||||
dataLoadingJob =
|
||||
viewModelScope.launchIO {
|
||||
loadHomeRows(userDto, settings)
|
||||
|
|
@ -133,7 +139,7 @@ class HomeViewModel
|
|||
}
|
||||
|
||||
suspend fun loadHomeRows(
|
||||
userDto: UserDto,
|
||||
userDto: ServerUserConfig,
|
||||
settings: HomePageResolvedSettings,
|
||||
) {
|
||||
Timber.i("Starting loadHomeRows")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue