Skip to content
Merged
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 @@ -35,6 +35,7 @@ import com.github.damontecres.wholphin.services.BackdropService
import com.github.damontecres.wholphin.services.DatePlayedInvalidationService
import com.github.damontecres.wholphin.services.DeviceProfileService
import com.github.damontecres.wholphin.services.ImageUrlService
import com.github.damontecres.wholphin.services.LatestNextUpSchedulerService
import com.github.damontecres.wholphin.services.NavigationManager
import com.github.damontecres.wholphin.services.PlaybackLifecycleObserver
import com.github.damontecres.wholphin.services.RefreshRateService
Expand Down Expand Up @@ -115,6 +116,9 @@ class MainActivity : AppCompatActivity() {
@Inject
lateinit var suggestionsSchedulerService: SuggestionsSchedulerService

@Inject
lateinit var latestNextUpSchedulerService: LatestNextUpSchedulerService

@Inject
lateinit var backdropService: BackdropService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ data class BaseItem(

val canDelete: Boolean get() = data.canDelete == true

@Transient
val aspectRatio: Float? = data.primaryImageAspectRatio?.toFloat()?.takeIf { it > 0 }
val aspectRatio: Float? get() = data.primaryImageAspectRatio?.toFloat()?.takeIf { it > 0 }

val indexNumber get() = data.indexNumber

Expand All @@ -92,8 +91,7 @@ data class BaseItem(

val favorite get() = data.userData?.isFavorite ?: false

@Transient
val timeRemainingOrRuntime: Duration? = data.timeRemaining ?: data.runTimeTicks?.ticks
val timeRemainingOrRuntime: Duration? get() = data.timeRemaining ?: data.runTimeTicks?.ticks

/**
* Contains pre computed UI elements that would be expensive to create on the main thread
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.damontecres.wholphin.services

import android.content.Context
import com.github.damontecres.wholphin.BuildConfig
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi
import org.jellyfin.sdk.model.UUID
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class DisplayPreferencesService
@Inject
constructor(
@param:ApplicationContext private val context: Context,
private val api: ApiClient,
) {
private val mutex = Mutex()

suspend fun getDisplayPreferences(
userId: UUID,
displayPreferencesId: String = DEFAULT_DISPLAY_PREF_ID,
client: String = DEFAULT_CLIENT,
) = api.displayPreferencesApi
.getDisplayPreferences(
userId = userId,
displayPreferencesId = displayPreferencesId,
client = client,
).content

suspend fun updateDisplayPreferences(
userId: UUID,
displayPreferencesId: String = DEFAULT_DISPLAY_PREF_ID,
client: String = DEFAULT_CLIENT,
block: MutableMap<String, String?>.() -> Unit,
) {
mutex.withLock {
val current = getDisplayPreferences(userId, DEFAULT_DISPLAY_PREF_ID)
val customPrefs =
current.customPrefs.toMutableMap().apply {
block.invoke(this)
}
api.displayPreferencesApi.updateDisplayPreferences(
displayPreferencesId = displayPreferencesId,
userId = userId,
client = client,
data = current.copy(customPrefs = customPrefs),
)
}
}

companion object {
const val DEFAULT_DISPLAY_PREF_ID = "default"
val DEFAULT_CLIENT = if (BuildConfig.DEBUG) "Wholphin (Debug)" else "Wholphin"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.damontecres.wholphin.services

import com.github.damontecres.wholphin.data.model.BaseItem
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.extensions.playStateApi
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
Expand Down Expand Up @@ -39,4 +40,7 @@ class FavoriteWatchManager
} else {
api.userLibraryApi.unmarkFavoriteItem(itemId).content
}

suspend fun removeContinueWatching(item: BaseItem) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi
import org.jellyfin.sdk.api.client.extensions.liveTvApi
import org.jellyfin.sdk.api.client.extensions.userApi
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
Expand Down Expand Up @@ -78,6 +77,7 @@ class HomeSettingsService
private val latestNextUpService: LatestNextUpService,
private val imageUrlService: ImageUrlService,
private val suggestionService: SuggestionService,
private val displayPreferencesService: DisplayPreferencesService,
) {
@OptIn(ExperimentalSerializationApi::class)
val jsonParser =
Expand All @@ -100,19 +100,11 @@ class HomeSettingsService
suspend fun saveToServer(
userId: UUID,
settings: HomePageSettings,
displayPreferencesId: String = DISPLAY_PREF_ID,
displayPreferencesId: String = DisplayPreferencesService.DEFAULT_DISPLAY_PREF_ID,
) {
val current = getDisplayPreferences(userId, DISPLAY_PREF_ID)
val customPrefs =
current.customPrefs.toMutableMap().apply {
put(CUSTOM_PREF_ID, jsonParser.encodeToString(settings))
}
api.displayPreferencesApi.updateDisplayPreferences(
displayPreferencesId = displayPreferencesId,
userId = userId,
client = context.getString(R.string.app_name),
data = current.copy(customPrefs = customPrefs),
)
displayPreferencesService.updateDisplayPreferences(userId, displayPreferencesId) {
put(CUSTOM_PREF_ID, jsonParser.encodeToString(settings))
}
}

/**
Expand All @@ -124,24 +116,15 @@ class HomeSettingsService
*/
suspend fun loadFromServer(
userId: UUID,
displayPreferencesId: String = DISPLAY_PREF_ID,
): HomePageSettings? {
val current = getDisplayPreferences(userId, displayPreferencesId)
return current.customPrefs[CUSTOM_PREF_ID]?.let {
val jsonElement = jsonParser.parseToJsonElement(it)
decode(jsonElement)
}
}

private suspend fun getDisplayPreferences(
userId: UUID,
displayPreferencesId: String,
) = api.displayPreferencesApi
.getDisplayPreferences(
userId = userId,
displayPreferencesId = displayPreferencesId,
client = context.getString(R.string.app_name),
).content
displayPreferencesId: String = DisplayPreferencesService.DEFAULT_DISPLAY_PREF_ID,
): HomePageSettings? =
displayPreferencesService
.getDisplayPreferences(userId, displayPreferencesId)
.customPrefs[CUSTOM_PREF_ID]
?.let {
val jsonElement = jsonParser.parseToJsonElement(it)
decode(jsonElement)
}

/**
* Computes the filename for locally saved [HomePageSettings]
Expand Down Expand Up @@ -331,12 +314,12 @@ class HomeSettingsService
*/
suspend fun parseFromWebConfig(userId: UUID): HomePageResolvedSettings? {
val customPrefs =
api.displayPreferencesApi
displayPreferencesService
.getDisplayPreferences(
displayPreferencesId = "usersettings",
userId = userId,
client = "emby",
).content.customPrefs
).customPrefs
val userDto by api.userApi.getUserById(userId)
val config = userDto.configuration ?: DefaultUserConfiguration
val libraries =
Expand Down Expand Up @@ -592,6 +575,7 @@ class HomeSettingsService
title = context.getString(R.string.continue_watching),
items = resume,
viewOptions = row.viewOptions,
rowType = row,
)
}

Expand All @@ -610,6 +594,7 @@ class HomeSettingsService
title = context.getString(R.string.next_up),
items = nextUp,
viewOptions = row.viewOptions,
rowType = row,
)
}

Expand Down Expand Up @@ -639,6 +624,7 @@ class HomeSettingsService
nextUp,
),
viewOptions = row.viewOptions,
rowType = row,
)
}

Expand Down Expand Up @@ -698,6 +684,7 @@ class HomeSettingsService
title,
genres,
viewOptions = row.viewOptions,
rowType = row,
)
}

Expand Down Expand Up @@ -725,6 +712,7 @@ class HomeSettingsService
title,
it,
row.viewOptions,
rowType = row,
)
}
latest
Expand Down Expand Up @@ -757,6 +745,7 @@ class HomeSettingsService
title,
it,
row.viewOptions,
rowType = row,
)
}
}
Expand Down Expand Up @@ -785,6 +774,7 @@ class HomeSettingsService
name ?: context.getString(R.string.collection),
it,
row.viewOptions,
rowType = row,
)
}
}
Expand Down Expand Up @@ -812,6 +802,7 @@ class HomeSettingsService
row.name,
it,
row.viewOptions,
rowType = row,
)
}
}
Expand Down Expand Up @@ -862,6 +853,7 @@ class HomeSettingsService
title,
it,
row.viewOptions,
rowType = row,
)
}
}
Expand All @@ -886,6 +878,7 @@ class HomeSettingsService
context.getString(R.string.active_recordings),
it,
row.viewOptions,
rowType = row,
)
}
}
Expand All @@ -910,6 +903,7 @@ class HomeSettingsService
context.getString(R.string.live_tv),
it,
row.viewOptions,
rowType = row,
)
}
}
Expand All @@ -927,6 +921,7 @@ class HomeSettingsService
context.getString(R.string.channels),
it,
row.viewOptions,
rowType = row,
)
}
}
Expand All @@ -949,12 +944,14 @@ class HomeSettingsService
title,
suggestions.items,
row.viewOptions,
rowType = row,
)
} else if (suggestions is SuggestionsResource.Empty) {
Success(
title,
listOf(),
row.viewOptions,
rowType = row,
)
} else {
Error(
Expand All @@ -966,7 +963,6 @@ class HomeSettingsService
}

companion object {
const val DISPLAY_PREF_ID = "default"
const val CUSTOM_PREF_ID = "home_settings"
}
}
Expand Down
Loading
Loading