Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ data class HomeRowViewOptions(
val episodeContentScale: PrefContentScale = PrefContentScale.FILL,
val episodeAspectRatio: AspectRatio = AspectRatio.TALL,
val episodeImageType: ViewOptionImageType = ViewOptionImageType.PRIMARY,
val showcase: Boolean = false,
val showcaseShowLogo: Boolean = true,
val showcaseShowRating: Boolean = true,
val showcaseShowOverview: Boolean = true,
val showcaseShowDetails: Boolean = true,
val showcaseInfiniteScroll: Boolean = true,
val showcaseRotateArtwork: Boolean = false,
) {
companion object {
val genreDefault =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -51,6 +52,17 @@ class BackdropService
private val _backdropFlow = MutableStateFlow<BackdropResult>(BackdropResult.NONE)
val backdropFlow = _backdropFlow

private val _showcaseFlow = MutableStateFlow<ShowcaseArtwork?>(null)

/**
* The artwork for a focused showcase row, drawn full screen behind the nav drawer
*/
val showcaseFlow: StateFlow<ShowcaseArtwork?> = _showcaseFlow

fun setShowcase(showcase: ShowcaseArtwork?) {
_showcaseFlow.value = showcase
}

/**
* Update the backdrop to use the specified item
*/
Expand Down Expand Up @@ -241,6 +253,14 @@ class BackdropService
}
}

/**
* The item whose artwork is shown full screen for a focused showcase row
*/
data class ShowcaseArtwork(
val item: BaseItem,
val rotate: Boolean,
)

/**
* The result from determining the backdrop URL and extracted colors for the dynamic backdrop
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.damontecres.wholphin.services

import android.content.Context
import androidx.annotation.StringRes
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
import com.github.damontecres.wholphin.ui.toServerString
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton

/**
* Stores the display settings for each row on a library's recommended tab, per user and library.
*
* Rows without saved settings use the library's defaults.
*/
@Singleton
class LibraryRowSettingsService
@Inject
constructor(
@param:ApplicationContext private val context: Context,
private val keyValueService: KeyValueService,
) {
/**
* A stable key for a row, based on the resource name of its title (for example
* "recently_added"), which does not change between app versions
*/
fun rowKey(
@StringRes title: Int,
): String = context.resources.getResourceEntryName(title)

fun flow(
userId: UUID,
libraryId: UUID,
): Flow<Map<String, HomeRowViewOptions>> = keyValueService.get(userId, key(libraryId), emptyMap<String, HomeRowViewOptions>())

suspend fun get(
userId: UUID,
libraryId: UUID,
): Map<String, HomeRowViewOptions> = flow(userId, libraryId).first()

/**
* Save the settings for one row, or remove them (go back to the defaults) if null
*/
suspend fun save(
userId: UUID,
libraryId: UUID,
rowKey: String,
viewOptions: HomeRowViewOptions?,
) {
val current = get(userId, libraryId)
val updated =
if (viewOptions == null) {
current - rowKey
} else {
current + (rowKey to viewOptions)
}
keyValueService.save(userId, key(libraryId), updated)
}

private fun key(libraryId: UUID) = "library_row_settings_${libraryId.toServerString()}"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.damontecres.wholphin.ui.components

import android.content.Context
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand All @@ -21,6 +22,7 @@ import com.github.damontecres.wholphin.preferences.AppPreferences
import com.github.damontecres.wholphin.preferences.UserPreferences
import com.github.damontecres.wholphin.services.BackdropService
import com.github.damontecres.wholphin.services.FavoriteWatchManager
import com.github.damontecres.wholphin.services.LibraryRowSettingsService
import com.github.damontecres.wholphin.services.MediaManagementService
import com.github.damontecres.wholphin.services.MusicService
import com.github.damontecres.wholphin.services.NavigationManager
Expand Down Expand Up @@ -81,6 +83,7 @@ class RecommendedViewModel
private val mediaManagementService: MediaManagementService,
private val suggestionService: SuggestionService,
val serverReportService: ServerReportService,
private val libraryRowSettingsService: LibraryRowSettingsService,
@Assisted private val parentId: UUID,
@Assisted private val suggestionsType: BaseItemKind,
@Assisted private val recommendedRows: List<RecommendedRow<*>>,
Expand All @@ -99,12 +102,33 @@ class RecommendedViewModel
private val _state = MutableStateFlow(RecommendedState())
val state: StateFlow<RecommendedState> = _state

/**
* The user's saved settings for this library's rows, by row key
*/
private var rowSettings: Map<String, HomeRowViewOptions> = emptyMap()

/**
* The display settings for a row: the user's saved settings, or the library's default
*/
private fun viewOptionsFor(
@StringRes title: Int,
): HomeRowViewOptions = rowSettings[libraryRowSettingsService.rowKey(title)] ?: viewOptions

fun init() {
viewModelScope.launchDefault {
val limit =
userPreferencesService.flow
.first()
.appPreferences.homePagePreferences.maxItemsPerRow
rowSettings =
try {
serverRepository.currentUser
?.let { libraryRowSettingsService.get(it.id, parentId) }
.orEmpty()
} catch (ex: Exception) {
Timber.e(ex, "Error loading row settings for %s", parentId)
emptyMap()
}
_state.update {
it.copy(
loading = LoadingState.Loading,
Expand All @@ -123,7 +147,7 @@ class RecommendedViewModel
HomeRowLoadingState.Success(
title,
items,
viewOptions,
viewOptionsFor(row.title),
showViewMore = items.size >= limit,
)
} catch (ex: Exception) {
Expand Down Expand Up @@ -192,7 +216,7 @@ class RecommendedViewModel
HomeRowLoadingState.Success(
title,
resource.items,
viewOptions,
viewOptionsFor(R.string.suggestions),
showViewMore = resource.items.size >= limit,
)
}
Expand All @@ -201,7 +225,7 @@ class RecommendedViewModel
HomeRowLoadingState.Success(
title,
emptyList(),
viewOptions,
viewOptionsFor(R.string.suggestions),
showViewMore = false,
)
}
Expand Down Expand Up @@ -309,7 +333,7 @@ class RecommendedViewModel
initialPosition = row.items.size,
viewOptions =
ViewOptions(
aspectRatio = viewOptions.aspectRatio,
aspectRatio = row.viewOptions.aspectRatio,
),
),
)
Expand All @@ -326,7 +350,7 @@ class RecommendedViewModel
initialPosition = row.items.size,
viewOptions =
ViewOptions(
aspectRatio = viewOptions.aspectRatio,
aspectRatio = row.viewOptions.aspectRatio,
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.jellyfin.sdk.model.api.request.GetResumeItemsRequest
import java.time.LocalDateTime
import java.util.UUID

private fun getRecommendedRows(parentId: UUID) =
internal fun getRecommendedMovieRows(parentId: UUID) =
listOf(
RecommendedRow(
title = R.string.continue_watching,
Expand Down Expand Up @@ -104,7 +104,7 @@ fun RecommendedMovie(
it.create(
parentId = parentId,
suggestionsType = BaseItemKind.MOVIE,
recommendedRows = getRecommendedRows(parentId),
recommendedRows = getRecommendedMovieRows(parentId),
viewOptions = HomeRowViewOptions(),
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
import com.github.damontecres.wholphin.preferences.UserPreferences
import com.github.damontecres.wholphin.ui.AspectRatio
import com.github.damontecres.wholphin.ui.Cards
import com.github.damontecres.wholphin.ui.SlimItemFields
import com.github.damontecres.wholphin.ui.data.RowColumn
import com.github.damontecres.wholphin.util.GetItemsRequestHandler
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.api.CollectionType
import org.jellyfin.sdk.model.api.ItemSortBy
import org.jellyfin.sdk.model.api.SortOrder
import org.jellyfin.sdk.model.api.request.GetItemsRequest
import java.time.LocalDateTime
import java.util.UUID

private fun getRecommendedRows(parentId: UUID) =
internal fun getRecommendedMusicRows(parentId: UUID) =
listOf(
RecommendedRow(
title = R.string.recently_released,
Expand Down Expand Up @@ -88,13 +86,8 @@ fun RecommendedMusic(
it.create(
parentId = parentId,
suggestionsType = BaseItemKind.MUSIC_ALBUM,
recommendedRows = getRecommendedRows(parentId),
viewOptions =
HomeRowViewOptions(
aspectRatio = AspectRatio.SQUARE,
heightDp = Cards.HEIGHT_EPISODE,
showTitles = true,
),
recommendedRows = getRecommendedMusicRows(parentId),
viewOptions = recommendedRowDefaultViewOptions(CollectionType.MUSIC),
)
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.damontecres.wholphin.ui.components

import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
import com.github.damontecres.wholphin.ui.AspectRatio
import com.github.damontecres.wholphin.ui.Cards
import org.jellyfin.sdk.model.api.CollectionType
import java.util.UUID

/**
* The title of each row on the recommended tab for a type of library, in order. Empty if that
* type of library has no recommended tab.
*/
fun recommendedRowTitles(type: CollectionType): List<Int> {
// Only the titles are used, so the library ID does not matter
val anyId = UUID(0, 0)
val rows =
when (type) {
CollectionType.MOVIES -> getRecommendedMovieRows(anyId)
CollectionType.TVSHOWS -> getRecommendedTvShowRows(anyId, enableRewatching = false)
CollectionType.MUSIC -> getRecommendedMusicRows(anyId)
else -> return emptyList()
}
return rows.map { it.title } + R.string.suggestions
}

/**
* The default display settings for the rows on the recommended tab for a type of library
*/
fun recommendedRowDefaultViewOptions(type: CollectionType): HomeRowViewOptions =
when (type) {
CollectionType.MUSIC -> {
HomeRowViewOptions(
aspectRatio = AspectRatio.SQUARE,
heightDp = Cards.HEIGHT_EPISODE,
showTitles = true,
)
}

else -> {
HomeRowViewOptions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.jellyfin.sdk.model.api.request.GetResumeItemsRequest
import java.time.LocalDateTime
import java.util.UUID

private fun getRecommendedRows(
internal fun getRecommendedTvShowRows(
parentId: UUID,
enableRewatching: Boolean,
) = listOf(
Expand Down Expand Up @@ -125,7 +125,7 @@ fun RecommendedTvShow(
parentId = parentId,
suggestionsType = BaseItemKind.SERIES,
recommendedRows =
getRecommendedRows(
getRecommendedTvShowRows(
parentId,
preferences.appPreferences.homePagePreferences.enableRewatchingNextUp,
),
Expand Down
Loading