File tree Expand file tree Collapse file tree 5 files changed +40
-28
lines changed
app/src/main/java/ai/bom/firebase
src/main/java/ai/bom/firebase/lib/config Expand file tree Collapse file tree 5 files changed +40
-28
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ var remoteAdSettings = RemoteModel()
40
40
```
41
41
Make your Custom model the way you want to receive model, call getRemoteConfig() to get data:
42
42
``` kotlin
43
- remoteConfig.getRemoteConfig {
43
+ remoteConfig.getRemoteConfig(context) {
44
44
it?.let {
45
45
val remoteJson = Gson ().toJson(it)
46
46
if (! remoteJson.isNullOrEmpty())
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ class MainActivity : AppCompatActivity() {
27
27
// Send FireBase Analytic Event
28
28
sendFbEvent(" MainActivity" , " Index Screen Open" )
29
29
30
- remoteConfig.getRemoteConfig {
30
+ remoteConfig.getRemoteConfig( this ) {
31
31
it?.let {
32
32
val remoteJson = Gson ().toJson(it)
33
33
if (! remoteJson.isNullOrEmpty())
Original file line number Diff line number Diff line change @@ -13,25 +13,6 @@ android {
13
13
testInstrumentationRunner " androidx.test.runner.AndroidJUnitRunner"
14
14
consumerProguardFiles " consumer-rules.pro"
15
15
}
16
-
17
- buildTypes {
18
- debug {
19
- minifyEnabled true
20
- proguardFiles getDefaultProguardFile(' proguard-android-optimize.txt' ), ' proguard-rules.pro'
21
- }
22
-
23
- release {
24
- minifyEnabled true
25
- proguardFiles getDefaultProguardFile(' proguard-android-optimize.txt' ), ' proguard-rules.pro'
26
- }
27
- }
28
- compileOptions {
29
- sourceCompatibility JavaVersion . VERSION_1_8
30
- targetCompatibility JavaVersion . VERSION_1_8
31
- }
32
- kotlinOptions {
33
- jvmTarget = ' 1.8'
34
- }
35
16
}
36
17
37
18
dependencies {
Original file line number Diff line number Diff line change 1
1
package ai.bom.firebase.lib.config
2
2
3
3
import ai.bom.firebase.lib.BuildConfig
4
+ import android.content.Context
4
5
import androidx.annotation.Keep
5
6
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
6
7
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
@@ -26,19 +27,24 @@ class RemoteConfigDate(private val remoteTopic: String) {
26
27
return remoteConfig
27
28
}
28
29
29
- private fun getRemoteConfig (): Any? {
30
- return Gson ().fromJson(
31
- getInstance()?.getString(remoteTopic),
32
- Any ::class .java
33
- )
30
+ private fun getRemoteConfig (context : Context ): Any? {
31
+ val pref = SharedPref (context)
32
+ var json = getInstance()?.getString(remoteTopic)
33
+
34
+ if (json.isNullOrEmpty() || json == " {}" ) {
35
+ json = pref.getRemoteString()
36
+ }
37
+ pref.putRemoteString(json)
38
+
39
+ return Gson ().fromJson(json, Any ::class .java)
34
40
}
35
41
36
- fun getRemoteConfig (listener : ((Any? ) -> Unit )) {
42
+ fun getRemoteConfig (context : Context , listener : ((Any? ) -> Unit )) {
37
43
getInstance()?.reset()
38
44
getInstance()?.fetchAndActivate()
39
45
?.addOnCompleteListener { task ->
40
46
if (task.isSuccessful) {
41
- val value = getRemoteConfig()
47
+ val value = getRemoteConfig(context )
42
48
listener.invoke(value)
43
49
} else {
44
50
listener.invoke(null )
Original file line number Diff line number Diff line change
1
+ package ai.bom.firebase.lib.config
2
+
3
+
4
+ import android.content.Context
5
+ import android.content.SharedPreferences
6
+
7
+ class SharedPref (private val context : Context ) {
8
+
9
+ private val strRemote = " remote"
10
+ private val strPref = " pref"
11
+
12
+ fun putRemoteString (value : String ) {
13
+ val sharedPref: SharedPreferences =
14
+ context.getSharedPreferences(strPref, Context .MODE_PRIVATE )
15
+ val editor = sharedPref.edit()
16
+ editor.putString(strRemote, value)
17
+ editor.apply ()
18
+ }
19
+
20
+ fun getRemoteString (): String {
21
+ val sharedPref: SharedPreferences =
22
+ context.getSharedPreferences(strPref, Context .MODE_PRIVATE )
23
+ return sharedPref.getString(strRemote, " {}" ) ? : " {}"
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments