mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-06-20 17:03:57 +03:00
Merge pull request #616 from ultrasonic/rm-globalscope
Remove global scope use
This commit is contained in:
commit
a34fc809d9
@ -2,8 +2,8 @@ package org.moire.ultrasonic.data
|
|||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -24,7 +24,7 @@ import timber.log.Timber
|
|||||||
*/
|
*/
|
||||||
class ActiveServerProvider(
|
class ActiveServerProvider(
|
||||||
private val repository: ServerSettingDao
|
private val repository: ServerSettingDao
|
||||||
) {
|
) : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
||||||
private var cachedServer: ServerSetting? = null
|
private var cachedServer: ServerSetting? = null
|
||||||
private var cachedDatabase: MetaDatabase? = null
|
private var cachedDatabase: MetaDatabase? = null
|
||||||
private var cachedServerId: Int? = null
|
private var cachedServerId: Int? = null
|
||||||
@ -83,7 +83,7 @@ class ActiveServerProvider(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
launch {
|
||||||
val serverId = repository.findByIndex(index)?.id ?: 0
|
val serverId = repository.findByIndex(index)?.id ?: 0
|
||||||
setActiveServerId(serverId)
|
setActiveServerId(serverId)
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ class ActiveServerProvider(
|
|||||||
* Sets the minimum Subsonic API version of the current server.
|
* Sets the minimum Subsonic API version of the current server.
|
||||||
*/
|
*/
|
||||||
fun setMinimumApiVersion(apiVersion: String) {
|
fun setMinimumApiVersion(apiVersion: String) {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
launch {
|
||||||
if (cachedServer != null) {
|
if (cachedServer != null) {
|
||||||
cachedServer!!.minimumApiVersion = apiVersion
|
cachedServer!!.minimumApiVersion = apiVersion
|
||||||
repository.update(cachedServer!!)
|
repository.update(cachedServer!!)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user