Add error handling to played and favorite buttons
This commit is contained in:
parent
e9aca103d8
commit
8e3c4a3a37
2 changed files with 79 additions and 40 deletions
|
@ -12,6 +12,7 @@ import dev.jdtech.jellyfin.utils.*
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.jellyfin.sdk.api.client.exception.ApiClientException
|
||||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
|
@ -108,28 +109,44 @@ constructor(
|
||||||
|
|
||||||
fun markAsPlayed(itemId: UUID) {
|
fun markAsPlayed(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.markAsPlayed(itemId)
|
jellyfinRepository.markAsPlayed(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
played = true
|
played = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun markAsUnplayed(itemId: UUID) {
|
fun markAsUnplayed(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.markAsUnplayed(itemId)
|
jellyfinRepository.markAsUnplayed(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
played = false
|
played = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun markAsFavorite(itemId: UUID) {
|
fun markAsFavorite(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.markAsFavorite(itemId)
|
jellyfinRepository.markAsFavorite(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
favorite = true
|
favorite = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unmarkAsFavorite(itemId: UUID) {
|
fun unmarkAsFavorite(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.unmarkAsFavorite(itemId)
|
jellyfinRepository.unmarkAsFavorite(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
favorite = false
|
favorite = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.jellyfin.sdk.api.client.exception.ApiClientException
|
||||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||||
import org.jellyfin.sdk.model.api.BaseItemPerson
|
import org.jellyfin.sdk.model.api.BaseItemPerson
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -51,6 +52,7 @@ constructor(
|
||||||
val favorite: Boolean,
|
val favorite: Boolean,
|
||||||
val downloaded: Boolean,
|
val downloaded: Boolean,
|
||||||
) : UiState()
|
) : UiState()
|
||||||
|
|
||||||
object Loading : UiState()
|
object Loading : UiState()
|
||||||
data class Error(val message: String?) : UiState()
|
data class Error(val message: String?) : UiState()
|
||||||
}
|
}
|
||||||
|
@ -98,7 +100,8 @@ constructor(
|
||||||
nextUp = getNextUp(itemId)
|
nextUp = getNextUp(itemId)
|
||||||
seasons = jellyfinRepository.getSeasons(itemId)
|
seasons = jellyfinRepository.getSeasons(itemId)
|
||||||
}
|
}
|
||||||
uiState.emit(UiState.Normal(
|
uiState.emit(
|
||||||
|
UiState.Normal(
|
||||||
tempItem,
|
tempItem,
|
||||||
actors,
|
actors,
|
||||||
director,
|
director,
|
||||||
|
@ -112,7 +115,8 @@ constructor(
|
||||||
played,
|
played,
|
||||||
favorite,
|
favorite,
|
||||||
downloaded
|
downloaded
|
||||||
))
|
)
|
||||||
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.d(e)
|
Timber.d(e)
|
||||||
Timber.d(itemId.toString())
|
Timber.d(itemId.toString())
|
||||||
|
@ -135,7 +139,8 @@ constructor(
|
||||||
dateString = ""
|
dateString = ""
|
||||||
played = tempItem.userData?.played ?: false
|
played = tempItem.userData?.played ?: false
|
||||||
favorite = tempItem.userData?.isFavorite ?: false
|
favorite = tempItem.userData?.isFavorite ?: false
|
||||||
uiState.emit(UiState.Normal(
|
uiState.emit(
|
||||||
|
UiState.Normal(
|
||||||
tempItem,
|
tempItem,
|
||||||
actors,
|
actors,
|
||||||
director,
|
director,
|
||||||
|
@ -149,7 +154,8 @@ constructor(
|
||||||
played,
|
played,
|
||||||
favorite,
|
favorite,
|
||||||
downloaded
|
downloaded
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,28 +194,44 @@ constructor(
|
||||||
|
|
||||||
fun markAsPlayed(itemId: UUID) {
|
fun markAsPlayed(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.markAsPlayed(itemId)
|
jellyfinRepository.markAsPlayed(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
played = true
|
played = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun markAsUnplayed(itemId: UUID) {
|
fun markAsUnplayed(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.markAsUnplayed(itemId)
|
jellyfinRepository.markAsUnplayed(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
played = false
|
played = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun markAsFavorite(itemId: UUID) {
|
fun markAsFavorite(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.markAsFavorite(itemId)
|
jellyfinRepository.markAsFavorite(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
favorite = true
|
favorite = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unmarkAsFavorite(itemId: UUID) {
|
fun unmarkAsFavorite(itemId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
jellyfinRepository.unmarkAsFavorite(itemId)
|
jellyfinRepository.unmarkAsFavorite(itemId)
|
||||||
|
} catch (e: ApiClientException) {
|
||||||
|
Timber.d(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
favorite = false
|
favorite = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue