Commit 7895e1e5 authored by Mygod's avatar Mygod

Simplify RemoteConfig

parent 8b29b1bc
......@@ -49,9 +49,10 @@ androidExtensions {
experimental = true
}
def coroutinesVersion = '1.3.0-RC'
def lifecycleVersion = '2.1.0-rc01'
def roomVersion = '2.1.0'
def workVersion = '2.2.0-beta01'
def workVersion = '2.2.0-beta02'
dependencies {
api project(':plugin')
api "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
......@@ -66,7 +67,8 @@ dependencies {
api 'com.google.firebase:firebase-config:18.0.0'
api 'com.google.firebase:firebase-core:17.0.1'
api 'dnsjava:dnsjava:2.1.9'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-M2'
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion"
api 'org.connectbot.jsocks:jsocks:1.0.0'
kapt "androidx.room:room-compiler:$roomVersion"
testImplementation "junit:junit:$junitVersion"
......
......@@ -25,8 +25,7 @@ import androidx.core.os.bundleOf
import com.github.shadowsocks.Core
import com.github.shadowsocks.core.R
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
import kotlinx.coroutines.tasks.await
object RemoteConfig {
private val config by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) } }
......@@ -40,15 +39,11 @@ object RemoteConfig {
if (it.isSuccessful) config.activate() else it.exception?.log()
}
suspend fun fetch() = suspendCancellableCoroutine<Pair<FirebaseRemoteConfig, Boolean>> { cont ->
config.fetch().addOnCompleteListener {
if (it.isSuccessful) {
config.activate()
cont.resume(config to true)
} else {
it.exception?.log()
cont.resume(config to false)
}
}
suspend fun fetch() = try {
config.fetch().await()
config to true
} catch (e: Exception) {
e.log()
config to false
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment