Skip to content

Commit

Permalink
Fix Remote Config Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Idrees committed Apr 4, 2023
1 parent 96066d0 commit b935036
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Send eventName & eventStatus init:
fbAnalytics.sendEventAnalytics(eventName, eventStatus)
```

### For FireBase Remote Config, create an object RemoteConfigDate, passing topicName init :
### For FireBase Remote Config, create an object RemoteConfigData, passing topicName init :
```kotlin
private val remoteConfig = RemoteConfigDate("topicName")
private val remoteConfig = RemoteConfigData("topicName")
var remoteAdSettings = RemoteModel()
```
Make your Custom model the way you want to receive model, call getRemoteConfig() to get data:
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ai/bom/firebase/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ai.bom.firebase

import ai.bom.firebase.lib.analytics.FirebaseAnalytics
import ai.bom.firebase.lib.config.RemoteConfigDate
import ai.bom.firebase.lib.config.RemoteConfigData
import ai.bom.firebase.lib.fcm.FirebaseFCM
import android.os.Bundle
import android.util.Log
Expand All @@ -11,7 +11,7 @@ import com.google.gson.Gson
class MainActivity : AppCompatActivity() {

private val fbAnalytics by lazy { FirebaseAnalytics(this) }
private val remoteConfig = RemoteConfigDate("demo")
private val remoteConfig = RemoteConfigData("demo")

private var remoteAdSettings = RemoteModel()

Expand Down
4 changes: 2 additions & 2 deletions firebaseLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ dependencies {
implementation 'androidx.core:core-ktx:1.8.0'

//Firebase BOM
api platform('com.google.firebase:firebase-bom:30.3.1')
api platform('com.google.firebase:firebase-bom:31.2.3')
api 'com.google.firebase:firebase-config-ktx'
api 'com.google.firebase:firebase-analytics-ktx'
api 'com.google.firebase:firebase-messaging-ktx'
api 'com.google.firebase:firebase-crashlytics-ktx'
//GSON
api 'com.google.code.gson:gson:2.9.0'
api 'com.google.code.gson:gson:2.9.1'
//Picasso For RemoteViews
api 'com.squareup.picasso:picasso:2.71828'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.bom.firebase.lib.config

import ai.bom.firebase.lib.BuildConfig
import android.content.Context
import android.os.SystemClock
import android.util.Log
import androidx.annotation.Keep
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
Expand All @@ -10,10 +11,11 @@ import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

@Keep
class RemoteConfigDate(private val remoteTopic: String) {
class RemoteConfigData(private val remoteTopic: String) {

private var remoteConfig: FirebaseRemoteConfig? = null
private val timeInMillis: Long = if (BuildConfig.DEBUG) 0L else 3600L
private var lastValueReceivedTime: Long = 0

private fun getInstance(): FirebaseRemoteConfig? {
remoteConfig = FirebaseRemoteConfig.getInstance()
Expand Down Expand Up @@ -44,7 +46,12 @@ class RemoteConfigDate(private val remoteTopic: String) {
getInstance()?.reset()
getInstance()?.fetchAndActivate()
?.addOnCompleteListener { task ->
Log.e("RemoteConfigNew*", "status : ${task.isSuccessful}")
val status = SystemClock.elapsedRealtime() - lastValueReceivedTime < 1000
Log.e("RemoteConfigNew*", "status $status: ${task.isSuccessful}")
if (status) {
return@addOnCompleteListener
}
lastValueReceivedTime = SystemClock.elapsedRealtime()
if (task.isSuccessful) {
val value = getRemoteConfig(context)
listener.invoke(value)
Expand Down

0 comments on commit b935036

Please sign in to comment.