/
PreventChurnActivity.kt
47 lines (37 loc) · 1.44 KB
/
PreventChurnActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.google.firebase.example.predictions.kotlin
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import java.util.HashMap
class PreventChurnActivity : AppCompatActivity() {
private fun preventChurn() {
// [START pred_prevent_churn]
val config = FirebaseRemoteConfig.getInstance()
val remoteConfigDefaults = HashMap<String, Any>()
remoteConfigDefaults["grant_retention_gift"] = false
config.setDefaults(remoteConfigDefaults)
// ...
config.fetch(CACHE_EXPIRATION)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
config.activateFetched()
}
// Act on the retrieved parameters. For example, grant the
// retention gift to players who haven't yet received one.
val shouldGrantGift = config.getBoolean("grant_retention_gift")
if (shouldGrantGift && !playerAlreadyReceivedGift()) {
grantGiftToPlayer()
}
}
// [END pred_prevent_churn]
}
private fun playerAlreadyReceivedGift(): Boolean {
// Dummy method
return false
}
private fun grantGiftToPlayer() {
// Dummy method
}
companion object {
private val CACHE_EXPIRATION = (60 * 1000).toLong()
}
}