diff --git a/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreference.kt b/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreference.kt index 7ac87673..ffc14ce2 100644 --- a/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreference.kt +++ b/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreference.kt @@ -164,6 +164,18 @@ sealed interface AppPreference { summarizer = { value -> value?.toString() }, ) + val CombineContinueNext = + AppSwitchPreference( + title = R.string.combine_continue_next, + defaultValue = false, + getter = { it.homePagePreferences.combineContinueNext }, + setter = { prefs, value -> + prefs.updateHomePagePreferences { combineContinueNext = value } + }, + summaryOn = R.string.enabled, + summaryOff = R.string.disabled, + ) + val RewatchNextUp = AppSwitchPreference( title = R.string.rewatch_next_up, @@ -457,6 +469,7 @@ val basicPreferences = listOf( AppPreference.HomePageItems, AppPreference.RewatchNextUp, + AppPreference.CombineContinueNext, AppPreference.PlayThemeMusic, AppPreference.RememberSelectedTab, AppPreference.ThemeColors, diff --git a/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreferencesSerializer.kt b/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreferencesSerializer.kt index f48df5ac..9043e288 100644 --- a/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreferencesSerializer.kt +++ b/app/src/main/java/com/github/damontecres/dolphin/preferences/AppPreferencesSerializer.kt @@ -49,6 +49,7 @@ class AppPreferencesSerializer .apply { maxItemsPerRow = AppPreference.HomePageItems.defaultValue.toInt() enableRewatchingNextUp = AppPreference.RewatchNextUp.defaultValue + combineContinueNext = AppPreference.CombineContinueNext.defaultValue }.build() interfacePreferences = InterfacePreferences diff --git a/app/src/main/java/com/github/damontecres/dolphin/ui/main/HomeViewModel.kt b/app/src/main/java/com/github/damontecres/dolphin/ui/main/HomeViewModel.kt index 552ff0e6..21ac3325 100644 --- a/app/src/main/java/com/github/damontecres/dolphin/ui/main/HomeViewModel.kt +++ b/app/src/main/java/com/github/damontecres/dolphin/ui/main/HomeViewModel.kt @@ -40,7 +40,8 @@ class HomeViewModel val homeRows = MutableLiveData>() fun init(preferences: UserPreferences) { - val limit = preferences.appPreferences.homePagePreferences.maxItemsPerRow + val prefs = preferences.appPreferences.homePagePreferences + val limit = prefs.maxItemsPerRow viewModelScope.launch( Dispatchers.IO + LoadingExceptionHandler( @@ -78,53 +79,32 @@ class HomeViewModel // } // TODO data is fetched all together which may be slow for large servers + val resume = getResume(user.id, limit) + val nextUp = getNextUp(user.id, limit, prefs.enableRewatchingNextUp) + val latest = getLatest(user, limit) + val homeRows = - homeSections - .mapNotNull { section -> - Timber.Forest.v("Loading section: %s", section.name) - when (section) { - HomeSection.LATEST_MEDIA -> { - getLatest(user, limit) - } - - HomeSection.RESUME -> { - val items = getResume(user.id, limit) - listOf( - HomeRow( - section = section, - items = items, - ), - ) - } - - HomeSection.NEXT_UP -> { - val nextUp = - getNextUp( - user.id, - limit, - preferences.appPreferences.homePagePreferences.enableRewatchingNextUp, - ) - listOf( - HomeRow( - section = section, - items = nextUp, - ), - ) - } - - // TODO - HomeSection.LIVE_TV -> null - HomeSection.ACTIVE_RECORDINGS -> null - - // TODO Not supported? - HomeSection.LIBRARY_TILES_SMALL -> null - HomeSection.LIBRARY_BUTTONS -> null - HomeSection.RESUME_AUDIO -> null - HomeSection.RESUME_BOOK -> null - HomeSection.NONE -> null - } - }.flatten() - .filter { it.items.isNotEmpty() } + if (prefs.combineContinueNext) { + listOf( + HomeRow( + section = HomeSection.NEXT_UP, + items = resume + nextUp, + ), + *latest.toTypedArray(), + ) + } else { + listOf( + HomeRow( + section = HomeSection.RESUME, + items = resume, + ), + HomeRow( + section = HomeSection.NEXT_UP, + items = nextUp, + ), + *latest.toTypedArray(), + ) + } withContext(Dispatchers.Main) { this@HomeViewModel.homeRows.value = homeRows loadingState.value = LoadingState.Success diff --git a/app/src/main/proto/DolphinDataStore.proto b/app/src/main/proto/DolphinDataStore.proto index 3b22208f..51f1a465 100644 --- a/app/src/main/proto/DolphinDataStore.proto +++ b/app/src/main/proto/DolphinDataStore.proto @@ -30,6 +30,7 @@ message PlaybackPreferences { message HomePagePreferences{ int32 max_items_per_row = 1; bool enable_rewatching_next_up = 2; + bool combine_continue_next = 3; } enum ThemeSongVolume { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c7b96a3c..1d88c220 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,5 +76,6 @@ No update available Clear image cache Shuffle +