Simple combine resume & next up

This commit is contained in:
Damontecres 2025-10-13 22:13:21 -04:00
parent b40db0074f
commit fc56a2c631
No known key found for this signature in database
5 changed files with 43 additions and 47 deletions

View file

@ -164,6 +164,18 @@ sealed interface AppPreference<T> {
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,

View file

@ -49,6 +49,7 @@ class AppPreferencesSerializer
.apply {
maxItemsPerRow = AppPreference.HomePageItems.defaultValue.toInt()
enableRewatchingNextUp = AppPreference.RewatchNextUp.defaultValue
combineContinueNext = AppPreference.CombineContinueNext.defaultValue
}.build()
interfacePreferences =
InterfacePreferences

View file

@ -40,7 +40,8 @@ class HomeViewModel
val homeRows = MutableLiveData<List<HomeRow>>()
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)
if (prefs.combineContinueNext) {
listOf(
HomeRow(
section = section,
items = items,
section = HomeSection.NEXT_UP,
items = resume + nextUp,
),
*latest.toTypedArray(),
)
}
HomeSection.NEXT_UP -> {
val nextUp =
getNextUp(
user.id,
limit,
preferences.appPreferences.homePagePreferences.enableRewatchingNextUp,
)
} else {
listOf(
HomeRow(
section = section,
section = HomeSection.RESUME,
items = resume,
),
HomeRow(
section = HomeSection.NEXT_UP,
items = nextUp,
),
*latest.toTypedArray(),
)
}
// 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() }
withContext(Dispatchers.Main) {
this@HomeViewModel.homeRows.value = homeRows
loadingState.value = LoadingState.Success

View file

@ -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 {

View file

@ -76,5 +76,6 @@
<string name="no_update_available">No update available</string>
<string name="clear_image_cache">Clear image cache</string>
<string name="shuffle">Shuffle</string>
<string name="combine_continue_next"><![CDATA[Combine Continue Watching & Next Up]]></string>
</resources>