Add error handling to device name updating
This fixes a crash
This commit is contained in:
parent
e3d049156c
commit
6bb784b2fe
3 changed files with 20 additions and 8 deletions
|
@ -76,4 +76,6 @@ interface JellyfinRepository {
|
|||
suspend fun getIntros(itemId: UUID): List<BaseItemDto>
|
||||
|
||||
fun getBaseUrl(): String
|
||||
|
||||
suspend fun updateDeviceName(name: String)
|
||||
}
|
|
@ -288,4 +288,12 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
}
|
||||
|
||||
override fun getBaseUrl() = jellyfinApi.api.baseUrl.orEmpty()
|
||||
|
||||
override suspend fun updateDeviceName(name: String) {
|
||||
jellyfinApi.jellyfin.deviceInfo?.id?.let { id ->
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.devicesApi.updateDeviceOptions(id, DeviceOptionsDto(0, customName = name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,21 +3,23 @@ package dev.jdtech.jellyfin.viewmodels
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dev.jdtech.jellyfin.api.JellyfinApi
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jellyfin.sdk.model.api.DeviceOptionsDto
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
internal class SettingsDeviceViewModel @Inject internal constructor(
|
||||
private val api: JellyfinApi
|
||||
internal class SettingsDeviceViewModel
|
||||
@Inject internal constructor(
|
||||
private val jellyfinRepository: JellyfinRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
fun updateDeviceName(name: String) {
|
||||
api.jellyfin.deviceInfo?.id?.let { id ->
|
||||
viewModelScope.launch(IO) {
|
||||
api.devicesApi.updateDeviceOptions(id, DeviceOptionsDto(0, customName = name))
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
jellyfinRepository.updateDeviceName(name)
|
||||
} catch (e: Exception) {
|
||||
Timber.e("Could not update device name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue