Skip to content

Commit 7e68c25

Browse files
authored
fixed remote config init error and add min interval setting (#245)
1 parent 9483563 commit 7e68c25

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

app/src/main/java/ro/code4/monitorizarevot/ui/splashscreen/SplashScreenViewModel.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,33 @@ class SplashScreenViewModel : BaseViewModel() {
1515
private val sharedPreferences: SharedPreferences by inject()
1616
private val repository: Repository by inject()
1717
private val loginLiveData = SingleLiveEvent<LoginStatus>()
18+
private val remoteConfig = runCatching { FirebaseRemoteConfig.getInstance() }.getOrNull()
1819

1920
fun loginLiveData(): LiveData<LoginStatus> = loginLiveData
2021

2122
init {
2223
remoteConfiguration()
24+
checkLogin()
2325
}
2426

2527
private fun remoteConfiguration() {
28+
remoteConfig?.let {
29+
it.apply {
30+
val minInterval = if (BuildConfig.DEBUG) 0 else 3600L
31+
val configSettings = FirebaseRemoteConfigSettings.Builder()
32+
.setMinimumFetchIntervalInSeconds(minInterval)
33+
.build()
2634

27-
FirebaseRemoteConfig.getInstance().apply {
28-
val configSettings = FirebaseRemoteConfigSettings.Builder()
29-
.build()
30-
setConfigSettingsAsync(configSettings)
31-
setDefaultsAsync(R.xml.remote_config_defaults)
32-
fetchAndActivate()
33-
.addOnCompleteListener {
34-
checkResetDB()
35-
}
35+
setConfigSettingsAsync(configSettings)
36+
setDefaultsAsync(R.xml.remote_config_defaults)
37+
fetchAndActivate()
38+
.addOnCompleteListener {
39+
checkResetDB()
40+
}
41+
}
3642
}
37-
checkLogin()
43+
44+
3845
}
3946

4047
private fun checkLogin() {

0 commit comments

Comments
 (0)