Commit 7895e1e5 authored by Mygod's avatar Mygod

Simplify RemoteConfig

parent 8b29b1bc
...@@ -49,9 +49,10 @@ androidExtensions { ...@@ -49,9 +49,10 @@ androidExtensions {
experimental = true experimental = true
} }
def coroutinesVersion = '1.3.0-RC'
def lifecycleVersion = '2.1.0-rc01' def lifecycleVersion = '2.1.0-rc01'
def roomVersion = '2.1.0' def roomVersion = '2.1.0'
def workVersion = '2.2.0-beta01' def workVersion = '2.2.0-beta02'
dependencies { dependencies {
api project(':plugin') api project(':plugin')
api "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" api "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
...@@ -66,7 +67,8 @@ dependencies { ...@@ -66,7 +67,8 @@ dependencies {
api 'com.google.firebase:firebase-config:18.0.0' api 'com.google.firebase:firebase-config:18.0.0'
api 'com.google.firebase:firebase-core:17.0.1' api 'com.google.firebase:firebase-core:17.0.1'
api 'dnsjava:dnsjava:2.1.9' 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' api 'org.connectbot.jsocks:jsocks:1.0.0'
kapt "androidx.room:room-compiler:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion"
testImplementation "junit:junit:$junitVersion" testImplementation "junit:junit:$junitVersion"
......
...@@ -25,8 +25,7 @@ import androidx.core.os.bundleOf ...@@ -25,8 +25,7 @@ import androidx.core.os.bundleOf
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.core.R import com.github.shadowsocks.core.R
import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.tasks.await
import kotlin.coroutines.resume
object RemoteConfig { object RemoteConfig {
private val config by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) } } private val config by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) } }
...@@ -40,15 +39,11 @@ object RemoteConfig { ...@@ -40,15 +39,11 @@ object RemoteConfig {
if (it.isSuccessful) config.activate() else it.exception?.log() if (it.isSuccessful) config.activate() else it.exception?.log()
} }
suspend fun fetch() = suspendCancellableCoroutine<Pair<FirebaseRemoteConfig, Boolean>> { cont -> suspend fun fetch() = try {
config.fetch().addOnCompleteListener { config.fetch().await()
if (it.isSuccessful) { config to true
config.activate() } catch (e: Exception) {
cont.resume(config to true) e.log()
} else { config to false
it.exception?.log()
cont.resume(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