mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
A few more home page fixes (#967)
## Description A few more home page fixes * Focus issue between settings & preset buttons * Fix default genre card size for "Wholphin Default" preset * Cache genre image urls for 2 hours so that they don't change on every refresh ### Related issues Related to #399 ### Testing Emulator ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
c4cd1fbfd3
commit
a14fdac852
6 changed files with 35 additions and 3 deletions
|
|
@ -569,6 +569,7 @@ class HomeSettingsService
|
|||
userDto: UserDto,
|
||||
libraries: List<Library>,
|
||||
limit: Int = prefs.maxItemsPerRow,
|
||||
isRefresh: Boolean,
|
||||
): HomeRowLoadingState =
|
||||
when (row) {
|
||||
is HomeRowConfig.ContinueWatching -> {
|
||||
|
|
@ -649,12 +650,14 @@ class HomeSettingsService
|
|||
val genreImages =
|
||||
getGenreImageMap(
|
||||
api = api,
|
||||
userId = serverRepository.currentUser.value?.id,
|
||||
scope = scope,
|
||||
imageUrlService = imageUrlService,
|
||||
genres = genreIds,
|
||||
parentId = row.parentId,
|
||||
includeItemTypes = null,
|
||||
cardWidthPx = null,
|
||||
useCache = isRefresh,
|
||||
)
|
||||
val library =
|
||||
libraries
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import com.github.damontecres.wholphin.util.GetGenresRequestHandler
|
|||
import com.github.damontecres.wholphin.util.GetItemsRequestHandler
|
||||
import com.github.damontecres.wholphin.util.LoadingExceptionHandler
|
||||
import com.github.damontecres.wholphin.util.LoadingState
|
||||
import com.mayakapps.kache.InMemoryKache
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
|
|
@ -55,8 +56,10 @@ import org.jellyfin.sdk.model.api.ItemFields
|
|||
import org.jellyfin.sdk.model.api.ItemSortBy
|
||||
import org.jellyfin.sdk.model.api.request.GetGenresRequest
|
||||
import org.jellyfin.sdk.model.api.request.GetItemsRequest
|
||||
import timber.log.Timber
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
|
||||
@HiltViewModel(assistedFactory = GenreViewModel.Factory::class)
|
||||
class GenreViewModel
|
||||
|
|
@ -110,6 +113,7 @@ class GenreViewModel
|
|||
val genreToUrl =
|
||||
getGenreImageMap(
|
||||
api = api,
|
||||
userId = serverRepository.currentUser.value?.id,
|
||||
scope = viewModelScope,
|
||||
imageUrlService = imageUrlService,
|
||||
genres = genres.map { it.id },
|
||||
|
|
@ -141,15 +145,35 @@ class GenreViewModel
|
|||
}
|
||||
}
|
||||
|
||||
data class GenreCacheKey(
|
||||
val userId: UUID?,
|
||||
val parentId: UUID,
|
||||
)
|
||||
|
||||
private val genreCache by lazy {
|
||||
InMemoryKache<GenreCacheKey, Map<UUID, String?>>(8) {
|
||||
expireAfterWriteDuration = 2.hours
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getGenreImageMap(
|
||||
api: ApiClient,
|
||||
userId: UUID?,
|
||||
scope: CoroutineScope,
|
||||
imageUrlService: ImageUrlService,
|
||||
genres: List<UUID>,
|
||||
parentId: UUID,
|
||||
includeItemTypes: List<BaseItemKind>?,
|
||||
cardWidthPx: Int?,
|
||||
useCache: Boolean = true,
|
||||
): Map<UUID, String?> {
|
||||
val key = GenreCacheKey(userId, parentId)
|
||||
if (useCache) {
|
||||
genreCache.getIfAvailable(key)?.let {
|
||||
Timber.v("Got cached entry")
|
||||
return it
|
||||
}
|
||||
}
|
||||
val genreToUrl = ConcurrentHashMap<UUID, String?>()
|
||||
val semaphore = Semaphore(4)
|
||||
genres
|
||||
|
|
@ -161,6 +185,7 @@ suspend fun getGenreImageMap(
|
|||
.execute(
|
||||
api,
|
||||
GetItemsRequest(
|
||||
userId = userId,
|
||||
parentId = parentId,
|
||||
recursive = true,
|
||||
limit = 1,
|
||||
|
|
@ -189,6 +214,7 @@ suspend fun getGenreImageMap(
|
|||
}
|
||||
}
|
||||
}.awaitAll()
|
||||
genreCache.put(key, genreToUrl)
|
||||
return genreToUrl
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ class HomeViewModel
|
|||
// Refreshing if a load has already occurred and the rows haven't significantly changed
|
||||
val refresh =
|
||||
state.loadingState == LoadingState.Success && state.settings == settings
|
||||
Timber.v("refresh=$refresh, state.loadingState=${state.loadingState}")
|
||||
_state.update { it.copy(settings = settings) }
|
||||
|
||||
val semaphore = Semaphore(4)
|
||||
|
||||
|
|
@ -102,6 +104,7 @@ class HomeViewModel
|
|||
userDto = userDto,
|
||||
libraries = libraries,
|
||||
limit = prefs.maxItemsPerRow,
|
||||
isRefresh = refresh,
|
||||
)
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Error on row %s", row)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import com.github.damontecres.wholphin.R
|
|||
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
|
||||
import com.github.damontecres.wholphin.preferences.PrefContentScale
|
||||
import com.github.damontecres.wholphin.ui.AspectRatio
|
||||
import com.github.damontecres.wholphin.ui.Cards
|
||||
import com.github.damontecres.wholphin.ui.components.ViewOptionImageType
|
||||
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
||||
import org.jellyfin.sdk.model.api.CollectionType
|
||||
|
|
@ -81,7 +80,7 @@ data class HomeRowPresets(
|
|||
contentScale = PrefContentScale.FIT,
|
||||
),
|
||||
liveTv = HomeRowViewOptions.liveTvDefault,
|
||||
genreSize = Cards.HEIGHT_2X3_DP,
|
||||
genreSize = HomeRowViewOptions.genreDefault.heightDp,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ fun HomeSettingsRowList(
|
|||
position = 2
|
||||
onClickPresets.invoke()
|
||||
},
|
||||
modifier = Modifier.focusRequester(focusRequesters[1]),
|
||||
modifier = Modifier.focusRequester(focusRequesters[2]),
|
||||
)
|
||||
}
|
||||
item {
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ class HomeSettingsViewModel
|
|||
userDto = userDto,
|
||||
libraries = state.libraries,
|
||||
limit = limit,
|
||||
isRefresh = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue