mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Backdrop changes
This commit is contained in:
parent
2b6c4eafb3
commit
99bddea295
2 changed files with 44 additions and 28 deletions
|
|
@ -33,7 +33,7 @@ import kotlin.time.Duration
|
||||||
@Stable
|
@Stable
|
||||||
data class BaseItem(
|
data class BaseItem(
|
||||||
val data: BaseItemDto,
|
val data: BaseItemDto,
|
||||||
val useSeriesForPrimary: Boolean,
|
val useSeriesForPrimary: Boolean = false,
|
||||||
val imageUrlOverride: String? = null,
|
val imageUrlOverride: String? = null,
|
||||||
val destinationOverride: Destination? = null,
|
val destinationOverride: Destination? = null,
|
||||||
) : CardGridItem {
|
) : CardGridItem {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import kotlinx.coroutines.CancellationException
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
|
@ -45,14 +44,16 @@ import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import org.jellyfin.sdk.api.client.ApiClient
|
import org.jellyfin.sdk.api.client.ApiClient
|
||||||
|
import org.jellyfin.sdk.api.client.extensions.itemsApi
|
||||||
import org.jellyfin.sdk.api.client.extensions.lyricsApi
|
import org.jellyfin.sdk.api.client.extensions.lyricsApi
|
||||||
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
||||||
|
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||||
import org.jellyfin.sdk.model.api.ImageType
|
import org.jellyfin.sdk.model.api.ImageType
|
||||||
|
import org.jellyfin.sdk.model.api.ItemSortBy
|
||||||
import org.jellyfin.sdk.model.api.LyricDto
|
import org.jellyfin.sdk.model.api.LyricDto
|
||||||
import org.jellyfin.sdk.model.extensions.ticks
|
import org.jellyfin.sdk.model.extensions.ticks
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import kotlin.random.Random
|
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
@ -99,7 +100,6 @@ class NowPlayingViewModel
|
||||||
|
|
||||||
init {
|
init {
|
||||||
player.addListener(this)
|
player.addListener(this)
|
||||||
|
|
||||||
addCloseable {
|
addCloseable {
|
||||||
player.removeListener(this)
|
player.removeListener(this)
|
||||||
visualizer?.release()
|
visualizer?.release()
|
||||||
|
|
@ -229,38 +229,54 @@ class NowPlayingViewModel
|
||||||
.getCurrent()
|
.getCurrent()
|
||||||
.appPreferences.musicPreferences.showBackdrop
|
.appPreferences.musicPreferences.showBackdrop
|
||||||
if (showBackdrop) {
|
if (showBackdrop) {
|
||||||
if (audio?.albumId != null) {
|
var backdropItem: BaseItem? = null
|
||||||
try {
|
try {
|
||||||
api.userLibraryApi.getItem(audio.albumId).content.let {
|
if (audio?.artistId != null) {
|
||||||
val backdropItem =
|
api.userLibraryApi.getItem(audio.artistId).content.let {
|
||||||
getBackdropItemForAlbum(api, BaseItem(it, false))
|
if (it.backdropImageTags?.isNotEmpty() == true) {
|
||||||
if (backdropItem != null) {
|
backdropItem = BaseItem(it, false)
|
||||||
doUpdateBackdrop(backdropItem)
|
|
||||||
} else {
|
|
||||||
clearBackdrop()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
|
||||||
Timber.e(ex, "Error fetching backdrop")
|
|
||||||
clearBackdrop()
|
|
||||||
}
|
}
|
||||||
} else {
|
if (backdropItem == null && audio?.albumId != null) {
|
||||||
clearBackdrop()
|
api.userLibraryApi.getItem(audio.albumId).content.let {
|
||||||
|
backdropItem =
|
||||||
|
getBackdropItemForAlbum(api, BaseItem(it, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (backdropItem != null) {
|
||||||
|
doUpdateBackdrop(backdropItem)
|
||||||
|
} else {
|
||||||
|
doUpdateBackdropRandom()
|
||||||
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Timber.e(ex, "Error fetching backdrop")
|
||||||
|
doUpdateBackdropRandom()
|
||||||
}
|
}
|
||||||
delay(60.seconds)
|
delay(60.seconds)
|
||||||
try {
|
doUpdateBackdropRandom()
|
||||||
val index = Random.nextInt(state.value.musicServiceState.queueSize)
|
|
||||||
val newAudio =
|
|
||||||
onMain { player.getMediaItemAt(index) }.localConfiguration?.tag as? AudioItem
|
|
||||||
updateBackdrop(newAudio)
|
|
||||||
} catch (_: CancellationException) {
|
|
||||||
} catch (ex: Exception) {
|
|
||||||
Timber.w(ex, "Error getting random audio")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun doUpdateBackdropRandom() {
|
||||||
|
val randomArtist =
|
||||||
|
api.itemsApi
|
||||||
|
.getItems(
|
||||||
|
recursive = true,
|
||||||
|
imageTypes = listOf(ImageType.BACKDROP),
|
||||||
|
includeItemTypes = listOf(BaseItemKind.MUSIC_ARTIST),
|
||||||
|
sortBy = listOf(ItemSortBy.RANDOM),
|
||||||
|
limit = 1,
|
||||||
|
).content.items
|
||||||
|
.firstOrNull()
|
||||||
|
if (randomArtist != null) {
|
||||||
|
doUpdateBackdrop(BaseItem(randomArtist))
|
||||||
|
} else {
|
||||||
|
clearBackdrop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun doUpdateBackdrop(item: BaseItem) {
|
private suspend fun doUpdateBackdrop(item: BaseItem) {
|
||||||
val imageUrl = imageUrlService.getItemImageUrl(item, ImageType.BACKDROP)
|
val imageUrl = imageUrlService.getItemImageUrl(item, ImageType.BACKDROP)
|
||||||
val (primaryColor, secondaryColor, tertiaryColor) =
|
val (primaryColor, secondaryColor, tertiaryColor) =
|
||||||
|
|
@ -337,7 +353,7 @@ class NowPlayingViewModel
|
||||||
if (prefs.musicPreferences.showBackdrop) {
|
if (prefs.musicPreferences.showBackdrop) {
|
||||||
updateBackdrop(getCurrent())
|
updateBackdrop(getCurrent())
|
||||||
} else {
|
} else {
|
||||||
backdropService.clearBackdrop()
|
clearBackdrop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue