mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-16 01:10:36 +03:00
Fixed coroutine scope for server creation/update
This commit is contained in:
parent
6fcdfea1db
commit
8a047c5b78
@ -6,6 +6,9 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
@ -36,6 +39,8 @@ class ServerSettingsModel(
|
||||
private const val PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"
|
||||
}
|
||||
|
||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
/**
|
||||
* This function will try and convert settings from the Preferences to the Database
|
||||
* @return True, if the migration was executed, False otherwise
|
||||
@ -160,7 +165,7 @@ class ServerSettingsModel(
|
||||
fun updateItem(serverSetting: ServerSetting?) {
|
||||
if (serverSetting == null) return
|
||||
|
||||
viewModelScope.launch {
|
||||
appScope.launch {
|
||||
repository.update(serverSetting)
|
||||
activeServerProvider.invalidateCache()
|
||||
Timber.d("updateItem updated server setting: $serverSetting")
|
||||
@ -173,7 +178,7 @@ class ServerSettingsModel(
|
||||
fun saveNewItem(serverSetting: ServerSetting?) {
|
||||
if (serverSetting == null) return
|
||||
|
||||
viewModelScope.launch {
|
||||
appScope.launch {
|
||||
serverSetting.index = (repository.count() ?: 0) + 1
|
||||
serverSetting.id = (repository.getMaxId() ?: 0) + 1
|
||||
repository.insert(serverSetting)
|
||||
|
Loading…
x
Reference in New Issue
Block a user