Basic home page & images
This commit is contained in:
parent
76d78246db
commit
51ad92f539
16 changed files with 421 additions and 42 deletions
|
|
@ -8,6 +8,7 @@ import kotlinx.coroutines.withContext
|
|||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.api.client.exception.InvalidStatusException
|
||||
import org.jellyfin.sdk.api.client.extensions.userApi
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class ServerRepository
|
||||
|
|
@ -51,6 +52,7 @@ class ServerRepository
|
|||
server: JellyfinServer,
|
||||
user: JellyfinUser,
|
||||
) {
|
||||
Timber.v("Changing user to ${user.name} on ${server.url}")
|
||||
apiClient.update(baseUrl = server.url, accessToken = user.accessToken)
|
||||
try {
|
||||
apiClient.userApi
|
||||
|
|
@ -60,6 +62,7 @@ class ServerRepository
|
|||
_currentUser = user
|
||||
} catch (e: InvalidStatusException) {
|
||||
// TODO
|
||||
Timber.e(e)
|
||||
if (e.status == 401) {
|
||||
// Unauthorized
|
||||
_currentServer = null
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.github.damontecres.dolphin.data.model
|
||||
|
||||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||
import java.util.UUID
|
||||
|
||||
sealed interface DolphinModel {
|
||||
val id: UUID
|
||||
val name: String?
|
||||
val imageUrl: String?
|
||||
}
|
||||
|
||||
fun convertModel(
|
||||
dto: BaseItemDto,
|
||||
api: ApiClient,
|
||||
): DolphinModel =
|
||||
when (dto.type) {
|
||||
BaseItemKind.VIDEO -> Video.fromDto(dto, api)
|
||||
else -> throw IllegalArgumentException("Unsupported item type: ${dto.type}")
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.github.damontecres.dolphin.data.model
|
||||
|
||||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.api.client.extensions.imageApi
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import org.jellyfin.sdk.model.api.ImageType
|
||||
import java.util.UUID
|
||||
|
||||
data class Video(
|
||||
override val id: UUID,
|
||||
override val name: String?,
|
||||
override val imageUrl: String?,
|
||||
) : DolphinModel {
|
||||
companion object {
|
||||
fun fromDto(
|
||||
dto: BaseItemDto,
|
||||
api: ApiClient,
|
||||
): Video =
|
||||
Video(
|
||||
id = dto.id,
|
||||
name = dto.name,
|
||||
imageUrl = api.imageApi.getItemImageUrl(dto.id, ImageType.PRIMARY),
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue