mirror of
https://github.com/bbara04/Purefin.git
synced 2026-03-31 17:10:08 +02:00
refactor image URL handling to use ViewModel method for consistency
This commit is contained in:
@@ -9,6 +9,7 @@ import hu.bbara.purefin.app.home.ui.HomeNavItem
|
||||
import hu.bbara.purefin.app.home.ui.LibraryItem
|
||||
import hu.bbara.purefin.app.home.ui.PosterItem
|
||||
import hu.bbara.purefin.client.JellyfinApiClient
|
||||
import hu.bbara.purefin.image.JellyfinImageHelper
|
||||
import hu.bbara.purefin.navigation.ItemDto
|
||||
import hu.bbara.purefin.navigation.LibraryDto
|
||||
import hu.bbara.purefin.navigation.NavigationManager
|
||||
@@ -21,6 +22,7 @@ import kotlinx.coroutines.launch
|
||||
import org.jellyfin.sdk.model.UUID
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||
import org.jellyfin.sdk.model.api.ImageType
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
@@ -32,6 +34,8 @@ class HomePageViewModel @Inject constructor(
|
||||
private val jellyfinApiClient: JellyfinApiClient
|
||||
) : ViewModel() {
|
||||
|
||||
private val _url = MutableStateFlow("")
|
||||
|
||||
private val _continueWatching = MutableStateFlow<List<ContinueWatchingItem>>(emptyList())
|
||||
val continueWatching = _continueWatching.asStateFlow()
|
||||
|
||||
@@ -45,6 +49,11 @@ class HomePageViewModel @Inject constructor(
|
||||
val latestLibraryContent = _latestLibraryContent.asStateFlow()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
userSessionRepository.serverUrl.collect {
|
||||
_url.value = it
|
||||
}
|
||||
}
|
||||
loadHomePageData()
|
||||
}
|
||||
|
||||
@@ -204,6 +213,14 @@ class HomePageViewModel @Inject constructor(
|
||||
loadAllShownLibraryItems()
|
||||
}
|
||||
|
||||
fun getImageUrl(itemId: UUID, type: ImageType): String {
|
||||
return JellyfinImageHelper.toImageUrl(
|
||||
url = _url.value,
|
||||
itemId = itemId,
|
||||
type = type
|
||||
)
|
||||
}
|
||||
|
||||
fun logout() {
|
||||
viewModelScope.launch {
|
||||
userSessionRepository.setLoggedIn(false)
|
||||
|
||||
@@ -39,7 +39,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import coil3.compose.AsyncImage
|
||||
import hu.bbara.purefin.app.home.HomePageViewModel
|
||||
import hu.bbara.purefin.common.ui.PosterCard
|
||||
import hu.bbara.purefin.image.JellyfinImageHelper
|
||||
import hu.bbara.purefin.player.PlayerActivity
|
||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||
import org.jellyfin.sdk.model.api.ImageType
|
||||
@@ -96,9 +95,7 @@ fun ContinueWatchingCard(
|
||||
.background(colors.card)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = JellyfinImageHelper.toImageUrl(
|
||||
url = "https://jellyfin.bbara.hu", itemId = item.id, type = ImageType.PRIMARY
|
||||
),
|
||||
model = viewModel.getImageUrl(itemId = item.id, type = ImageType.PRIMARY),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
|
||||
@@ -23,7 +23,6 @@ import hu.bbara.purefin.app.home.HomePageViewModel
|
||||
import hu.bbara.purefin.app.home.ui.HomeColors
|
||||
import hu.bbara.purefin.app.home.ui.PosterItem
|
||||
import hu.bbara.purefin.app.home.ui.rememberHomeColors
|
||||
import hu.bbara.purefin.image.JellyfinImageHelper
|
||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||
import org.jellyfin.sdk.model.api.ImageType
|
||||
|
||||
@@ -48,11 +47,7 @@ fun PosterCard(
|
||||
) {
|
||||
|
||||
AsyncImage(
|
||||
model = JellyfinImageHelper.toImageUrl(
|
||||
url = "https://jellyfin.bbara.hu",
|
||||
itemId = item.imageItemId,
|
||||
type = ImageType.PRIMARY
|
||||
),
|
||||
model = viewModel.getImageUrl(item.id, ImageType.PRIMARY),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.aspectRatio(2f / 3f)
|
||||
|
||||
Reference in New Issue
Block a user