mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
Refactoring
This commit is contained in:
parent
d7236e7bbf
commit
668a3960f3
6 changed files with 56 additions and 45 deletions
|
|
@ -21,11 +21,11 @@ import org.jellyfin.sdk.model.serializer.UUIDSerializer
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
sealed class HomeRowConfig {
|
sealed interface HomeRowConfig {
|
||||||
abstract val id: Int
|
val id: Int
|
||||||
abstract val viewOptions: HomeRowViewOptions
|
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
|
* Continue watching media that the user has started but not finished
|
||||||
|
|
@ -35,8 +35,8 @@ sealed class HomeRowConfig {
|
||||||
data class ContinueWatching(
|
data class ContinueWatching(
|
||||||
override val id: Int,
|
override val id: Int,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatching = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,8 +47,8 @@ sealed class HomeRowConfig {
|
||||||
data class NextUp(
|
data class NextUp(
|
||||||
override val id: Int,
|
override val id: Int,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): NextUp = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -59,8 +59,8 @@ sealed class HomeRowConfig {
|
||||||
data class ContinueWatchingCombined(
|
data class ContinueWatchingCombined(
|
||||||
override val id: Int,
|
override val id: Int,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatchingCombined = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,8 +72,8 @@ sealed class HomeRowConfig {
|
||||||
override val id: Int,
|
override val id: Int,
|
||||||
val parentId: UUID,
|
val parentId: UUID,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyAdded = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -85,8 +85,8 @@ sealed class HomeRowConfig {
|
||||||
override val id: Int,
|
override val id: Int,
|
||||||
val parentId: UUID,
|
val parentId: UUID,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
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 },
|
heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt().let { it - it % 4 },
|
||||||
aspectRatio = AspectRatio.WIDE,
|
aspectRatio = AspectRatio.WIDE,
|
||||||
),
|
),
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): Genres = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -117,8 +117,8 @@ sealed class HomeRowConfig {
|
||||||
val recursive: Boolean,
|
val recursive: Boolean,
|
||||||
val sort: SortAndDirection? = null,
|
val sort: SortAndDirection? = null,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): ByParent = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,34 +131,26 @@ sealed class HomeRowConfig {
|
||||||
val name: String,
|
val name: String,
|
||||||
val getItems: GetItemsRequest,
|
val getItems: GetItemsRequest,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): GetItems = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class HomeRowConfigDisplay(
|
|
||||||
val title: String,
|
|
||||||
val config: HomeRowConfig,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("HomePageSettings")
|
@SerialName("HomePageSettings")
|
||||||
data class HomePageSettings(
|
data class HomePageSettings(
|
||||||
val rows: List<HomeRowConfig>,
|
val rows: List<HomeRowConfig>,
|
||||||
val version: Int = 1,
|
val version: Int = SUPPORTED_HOME_PAGE_SETTINGS_VERSION,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
val EMPTY = HomePageSettings(listOf())
|
val EMPTY = HomePageSettings(listOf())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class HomePageResolvedSettings(
|
/**
|
||||||
val rows: List<HomeRowConfigDisplay>,
|
* This is the max version supported by this version of the app
|
||||||
) {
|
*/
|
||||||
companion object {
|
const val SUPPORTED_HOME_PAGE_SETTINGS_VERSION = 1
|
||||||
val EMPTY = HomePageResolvedSettings(listOf())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class HomeRowViewOptions(
|
data class HomeRowViewOptions(
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,10 @@ import android.content.Context
|
||||||
import com.github.damontecres.wholphin.R
|
import com.github.damontecres.wholphin.R
|
||||||
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
||||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
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.HomePageSettings
|
||||||
import com.github.damontecres.wholphin.data.model.HomeRowConfig
|
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.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.preferences.HomePagePreferences
|
||||||
import com.github.damontecres.wholphin.ui.DefaultItemFields
|
import com.github.damontecres.wholphin.ui.DefaultItemFields
|
||||||
import com.github.damontecres.wholphin.ui.SlimItemFields
|
import com.github.damontecres.wholphin.ui.SlimItemFields
|
||||||
|
|
@ -86,7 +85,9 @@ class HomeSettingsService
|
||||||
): HomePageSettings? {
|
): HomePageSettings? {
|
||||||
val current = getDisplayPreferences(userId, displayPreferencesId)
|
val current = getDisplayPreferences(userId, displayPreferencesId)
|
||||||
return current.customPrefs[DISPLAY_PREF_ID]?.let {
|
return current.customPrefs[DISPLAY_PREF_ID]?.let {
|
||||||
Json.decodeFromString<HomePageSettings>(it)
|
Json
|
||||||
|
.decodeFromString<HomePageSettings>(it)
|
||||||
|
.takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +121,9 @@ class HomeSettingsService
|
||||||
val file = File(dir, filename(userId))
|
val file = File(dir, filename(userId))
|
||||||
return if (file.exists()) {
|
return if (file.exists()) {
|
||||||
file.inputStream().use {
|
file.inputStream().use {
|
||||||
jsonParser.decodeFromStream<HomePageSettings>(it)
|
jsonParser
|
||||||
|
.decodeFromStream<HomePageSettings>(it)
|
||||||
|
.takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|
@ -534,3 +537,16 @@ class HomeSettingsService
|
||||||
const val CUSTOM_PREF_ID = "home_settings"
|
const val CUSTOM_PREF_ID = "home_settings"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class HomeRowConfigDisplay(
|
||||||
|
val title: String,
|
||||||
|
val config: HomeRowConfig,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class HomePageResolvedSettings(
|
||||||
|
val rows: List<HomeRowConfigDisplay>,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
val EMPTY = HomePageResolvedSettings(listOf())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.api.seerr.model.User
|
||||||
import com.github.damontecres.wholphin.data.SeerrServerDao
|
import com.github.damontecres.wholphin.data.SeerrServerDao
|
||||||
import com.github.damontecres.wholphin.data.ServerRepository
|
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.SeerrAuthMethod
|
||||||
import com.github.damontecres.wholphin.data.model.SeerrPermission
|
import com.github.damontecres.wholphin.data.model.SeerrPermission
|
||||||
import com.github.damontecres.wholphin.data.model.SeerrServer
|
import com.github.damontecres.wholphin.data.model.SeerrServer
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ import androidx.lifecycle.viewModelScope
|
||||||
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
||||||
import com.github.damontecres.wholphin.data.ServerRepository
|
import com.github.damontecres.wholphin.data.ServerRepository
|
||||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
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.BackdropService
|
||||||
import com.github.damontecres.wholphin.services.DatePlayedService
|
import com.github.damontecres.wholphin.services.DatePlayedService
|
||||||
import com.github.damontecres.wholphin.services.FavoriteWatchManager
|
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.HomeSettingsService
|
||||||
import com.github.damontecres.wholphin.services.NavigationManager
|
import com.github.damontecres.wholphin.services.NavigationManager
|
||||||
import com.github.damontecres.wholphin.services.UserPreferencesService
|
import com.github.damontecres.wholphin.services.UserPreferencesService
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import androidx.tv.material3.MaterialTheme
|
||||||
import androidx.tv.material3.Text
|
import androidx.tv.material3.Text
|
||||||
import androidx.tv.material3.surfaceColorAtElevation
|
import androidx.tv.material3.surfaceColorAtElevation
|
||||||
import com.github.damontecres.wholphin.R
|
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.FontAwesome
|
||||||
import com.github.damontecres.wholphin.ui.components.Button
|
import com.github.damontecres.wholphin.ui.components.Button
|
||||||
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
||||||
|
|
@ -108,7 +108,7 @@ fun HomeSettingsRowList(
|
||||||
config = row,
|
config = row,
|
||||||
moveUpAllowed = index > 0,
|
moveUpAllowed = index > 0,
|
||||||
moveDownAllowed = index != state.rows.lastIndex,
|
moveDownAllowed = index != state.rows.lastIndex,
|
||||||
deleteAllowed = true,
|
deleteAllowed = state.rows.size > 1,
|
||||||
onClickMove = { onClickMove.invoke(it, index) },
|
onClickMove = { onClickMove.invoke(it, index) },
|
||||||
onClickDelete = { onClickDelete.invoke(index) },
|
onClickDelete = { onClickDelete.invoke(index) },
|
||||||
onClick = { onClick.invoke(index, row) },
|
onClick = { onClick.invoke(index, row) },
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ import com.github.damontecres.wholphin.R
|
||||||
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
||||||
import com.github.damontecres.wholphin.data.ServerRepository
|
import com.github.damontecres.wholphin.data.ServerRepository
|
||||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
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.HomePageSettings
|
||||||
import com.github.damontecres.wholphin.data.model.HomeRowConfig
|
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.HomeRowViewOptions
|
||||||
import com.github.damontecres.wholphin.services.BackdropService
|
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.HomeSettingsService
|
||||||
import com.github.damontecres.wholphin.services.UserPreferencesService
|
import com.github.damontecres.wholphin.services.UserPreferencesService
|
||||||
import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope
|
import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope
|
||||||
|
|
@ -316,8 +316,12 @@ class HomeSettingsViewModel
|
||||||
val settings = HomePageSettings(rows = rows)
|
val settings = HomePageSettings(rows = rows)
|
||||||
try {
|
try {
|
||||||
Timber.d("saveToLocal")
|
Timber.d("saveToLocal")
|
||||||
homeSettingsService.saveToLocal(user.id, settings)
|
val local = homeSettingsService.loadFromLocal(user.id)
|
||||||
showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT)
|
// 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) {
|
} catch (ex: Exception) {
|
||||||
Timber.e(ex)
|
Timber.e(ex)
|
||||||
showToast(context, "Error saving: ${ex.localizedMessage}")
|
showToast(context, "Error saving: ${ex.localizedMessage}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue