Basic navigation
This commit is contained in:
parent
51ad92f539
commit
80070f4174
18 changed files with 496 additions and 22 deletions
|
|
@ -3,7 +3,11 @@ package com.github.damontecres.dolphin.data
|
|||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [JellyfinServer::class, JellyfinUser::class], version = 1, exportSchema = false)
|
||||
@Database(
|
||||
entities = [JellyfinServer::class, JellyfinUser::class],
|
||||
version = 2,
|
||||
exportSchema = false,
|
||||
)
|
||||
abstract class DolphinDatabase : RoomDatabase() {
|
||||
abstract fun serverDao(): JellyfinServerDao
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import androidx.room.Transaction
|
|||
@Entity(tableName = "servers")
|
||||
data class JellyfinServer(
|
||||
@PrimaryKey val id: String,
|
||||
val name: String,
|
||||
val name: String?,
|
||||
val url: String,
|
||||
)
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ data class JellyfinUser(
|
|||
val name: String?,
|
||||
@ColumnInfo(index = true)
|
||||
val serverId: String,
|
||||
val accessToken: String,
|
||||
val accessToken: String?,
|
||||
)
|
||||
|
||||
data class JellyfinServerUsers(
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import org.jellyfin.sdk.api.client.exception.InvalidStatusException
|
|||
import org.jellyfin.sdk.api.client.extensions.userApi
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ServerRepository
|
||||
@Inject
|
||||
constructor(
|
||||
|
|
@ -55,11 +57,22 @@ class ServerRepository
|
|||
Timber.v("Changing user to ${user.name} on ${server.url}")
|
||||
apiClient.update(baseUrl = server.url, accessToken = user.accessToken)
|
||||
try {
|
||||
apiClient.userApi
|
||||
.getCurrentUser()
|
||||
.content.name
|
||||
_currentServer = server
|
||||
_currentUser = user
|
||||
val userDto =
|
||||
apiClient.userApi
|
||||
.getCurrentUser()
|
||||
.content
|
||||
val updatedServer = server.copy(name = userDto.serverName)
|
||||
val updatedUser =
|
||||
user.copy(
|
||||
id = userDto.id.toString(),
|
||||
name = userDto.name,
|
||||
)
|
||||
withContext(Dispatchers.IO) {
|
||||
serverDao.addServer(updatedServer)
|
||||
serverDao.addUser(updatedUser)
|
||||
}
|
||||
_currentServer = updatedServer
|
||||
_currentUser = updatedUser
|
||||
} catch (e: InvalidStatusException) {
|
||||
// TODO
|
||||
Timber.e(e)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@ fun convertModel(
|
|||
api: ApiClient,
|
||||
): DolphinModel =
|
||||
when (dto.type) {
|
||||
BaseItemKind.COLLECTION_FOLDER -> Library.fromDto(dto, api)
|
||||
|
||||
// TODO
|
||||
BaseItemKind.VIDEO -> Video.fromDto(dto, api)
|
||||
BaseItemKind.SERIES -> Video.fromDto(dto, api)
|
||||
BaseItemKind.MOVIE -> Video.fromDto(dto, api)
|
||||
BaseItemKind.SEASON -> Video.fromDto(dto, api)
|
||||
BaseItemKind.EPISODE -> Video.fromDto(dto, api)
|
||||
else -> throw IllegalArgumentException("Unsupported item type: ${dto.type}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
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.CollectionType
|
||||
import org.jellyfin.sdk.model.api.ImageType
|
||||
import java.util.UUID
|
||||
|
||||
data class Library(
|
||||
override val id: UUID,
|
||||
override val name: String?,
|
||||
override val imageUrl: String?,
|
||||
val type: CollectionType,
|
||||
) : DolphinModel {
|
||||
companion object {
|
||||
fun fromDto(
|
||||
dto: BaseItemDto,
|
||||
api: ApiClient,
|
||||
): Library =
|
||||
Library(
|
||||
id = dto.id,
|
||||
name = dto.name,
|
||||
imageUrl = api.imageApi.getItemImageUrl(dto.id, ImageType.PRIMARY),
|
||||
type = dto.collectionType ?: CollectionType.UNKNOWN,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue