Created
November 14, 2022 03:06
-
-
Save cse-ariful/99d544de8e527c8a15ab6013dfdaed63 to your computer and use it in GitHub Desktop.
A Complete helper class for firebase remote config. And very easy to use and type safe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | |
import kotlin.math.max | |
object RcConfig { | |
private val remoteConfig: FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance() | |
init { | |
remoteConfig.setDefaultsAsync(getRemoteDefaults()) | |
remoteConfig.fetchAndActivate().addOnCompleteListener { | |
Log.d("RemoteConfig", "RemoteConfig Fetch complete ") | |
} | |
} | |
private fun getRemoteDefaults(): Map<String, Any> { | |
return mapOf( | |
"min_app_version" to 1, | |
"offer_active" to false | |
) | |
} | |
fun initialize() { | |
} | |
val minAppVersion: Int | |
get() = remoteConfig.getLong("min_app_version").toInt() | |
val isAppUpdateRequired: Boolean | |
get() = minAppVersion > BuildConfig.VERSION_CODE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment