diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 13d96785..6f1bc365 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -21,11 +21,11 @@ import org.jellyfin.sdk.model.serializer.UUIDSerializer import java.util.UUID @Serializable -sealed class HomeRowConfig { - abstract val id: Int - abstract val viewOptions: HomeRowViewOptions +sealed interface HomeRowConfig { + val id: Int + val viewOptions: HomeRowViewOptions - abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig + fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig /** * Continue watching media that the user has started but not finished @@ -35,8 +35,8 @@ sealed class HomeRowConfig { data class ContinueWatching( override val id: Int, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatching = this.copy(viewOptions = viewOptions) } /** @@ -47,8 +47,8 @@ sealed class HomeRowConfig { data class NextUp( override val id: Int, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): NextUp = this.copy(viewOptions = viewOptions) } /** @@ -59,8 +59,8 @@ sealed class HomeRowConfig { data class ContinueWatchingCombined( override val id: Int, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatchingCombined = this.copy(viewOptions = viewOptions) } /** @@ -72,8 +72,8 @@ sealed class HomeRowConfig { override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyAdded = this.copy(viewOptions = viewOptions) } /** @@ -85,8 +85,8 @@ sealed class HomeRowConfig { override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyReleased = this.copy(viewOptions = viewOptions) } /** @@ -102,8 +102,8 @@ sealed class HomeRowConfig { heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt().let { it - it % 4 }, aspectRatio = AspectRatio.WIDE, ), - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): Genres = this.copy(viewOptions = viewOptions) } /** @@ -117,8 +117,8 @@ sealed class HomeRowConfig { val recursive: Boolean, val sort: SortAndDirection? = null, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): ByParent = this.copy(viewOptions = viewOptions) } /** @@ -131,34 +131,26 @@ sealed class HomeRowConfig { val name: String, val getItems: GetItemsRequest, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): GetItems = this.copy(viewOptions = viewOptions) } } -data class HomeRowConfigDisplay( - val title: String, - val config: HomeRowConfig, -) - @Serializable @SerialName("HomePageSettings") data class HomePageSettings( val rows: List, - val version: Int = 1, + val version: Int = SUPPORTED_HOME_PAGE_SETTINGS_VERSION, ) { companion object { val EMPTY = HomePageSettings(listOf()) } } -data class HomePageResolvedSettings( - val rows: List, -) { - companion object { - val EMPTY = HomePageResolvedSettings(listOf()) - } -} +/** + * This is the max version supported by this version of the app + */ +const val SUPPORTED_HOME_PAGE_SETTINGS_VERSION = 1 @Serializable data class HomeRowViewOptions( diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index d9c184a3..995cae8c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -4,11 +4,10 @@ import android.content.Context import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.SlimItemFields @@ -86,7 +85,9 @@ class HomeSettingsService ): HomePageSettings? { val current = getDisplayPreferences(userId, displayPreferencesId) return current.customPrefs[DISPLAY_PREF_ID]?.let { - Json.decodeFromString(it) + Json + .decodeFromString(it) + .takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION } } } @@ -120,7 +121,9 @@ class HomeSettingsService val file = File(dir, filename(userId)) return if (file.exists()) { file.inputStream().use { - jsonParser.decodeFromStream(it) + jsonParser + .decodeFromStream(it) + .takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION } } } else { null @@ -534,3 +537,16 @@ class HomeSettingsService const val CUSTOM_PREF_ID = "home_settings" } } + +data class HomeRowConfigDisplay( + val title: String, + val config: HomeRowConfig, +) + +data class HomePageResolvedSettings( + val rows: List, +) { + companion object { + val EMPTY = HomePageResolvedSettings(listOf()) + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt index f6d25786..41b37520 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt @@ -11,7 +11,6 @@ import com.github.damontecres.wholphin.api.seerr.model.PublicSettings import com.github.damontecres.wholphin.api.seerr.model.User import com.github.damontecres.wholphin.data.SeerrServerDao import com.github.damontecres.wholphin.data.ServerRepository -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.SeerrAuthMethod import com.github.damontecres.wholphin.data.model.SeerrPermission import com.github.damontecres.wholphin.data.model.SeerrServer diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt index ebde16a8..f51db306 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt @@ -6,10 +6,10 @@ import androidx.lifecycle.viewModelScope import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.DatePlayedService import com.github.damontecres.wholphin.services.FavoriteWatchManager +import com.github.damontecres.wholphin.services.HomePageResolvedSettings import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.NavigationManager import com.github.damontecres.wholphin.services.UserPreferencesService diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index b1e72e92..7740065b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -34,7 +34,7 @@ import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import androidx.tv.material3.surfaceColorAtElevation import com.github.damontecres.wholphin.R -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay +import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.components.Button import com.github.damontecres.wholphin.ui.tryRequestFocus @@ -108,7 +108,7 @@ fun HomeSettingsRowList( config = row, moveUpAllowed = index > 0, moveDownAllowed = index != state.rows.lastIndex, - deleteAllowed = true, + deleteAllowed = state.rows.size > 1, onClickMove = { onClickMove.invoke(it, index) }, onClickDelete = { onClickDelete.invoke(index) }, onClick = { onClick.invoke(index, row) }, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 61c91875..8a3d3984 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -9,12 +9,12 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.services.BackdropService +import com.github.damontecres.wholphin.services.HomePageResolvedSettings +import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope @@ -316,8 +316,12 @@ class HomeSettingsViewModel val settings = HomePageSettings(rows = rows) try { Timber.d("saveToLocal") - homeSettingsService.saveToLocal(user.id, settings) - showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + val local = homeSettingsService.loadFromLocal(user.id) + // Only save if there are changes + if (local != settings) { + homeSettingsService.saveToLocal(user.id, settings) + showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + } } catch (ex: Exception) { Timber.e(ex) showToast(context, "Error saving: ${ex.localizedMessage}")