Last active
March 29, 2020 10:02
-
-
Save liorkup/6fbc3573e1813cb534d8615e259b8ecd to your computer and use it in GitHub Desktop.
Remote Config solution for LadyM (License: https://gist.github.com/liorkup/019cec4f23edfe39a444571206ea2ae7)
This file contains hidden or 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
//Remote Config Solution | |
public class MainActivity extends AppCompatActivity { | |
// Remote Config Parameter Key | |
public static Map<String, String> RC_KEY_TO_EVENT_MAP; | |
static { | |
RC_KEY_TO_EVENT_MAP = new HashMap<>(); | |
RC_KEY_TO_EVENT_MAP.put("rc_retention", "p_retention"); | |
RC_KEY_TO_EVENT_MAP.put("rc_complete_level_3", "p_complete_level_3"); | |
RC_KEY_TO_EVENT_MAP.put("rc_complete_level_5", "p_complete_level_5"); | |
RC_KEY_TO_EVENT_MAP.put("rc_complete_level_10", "p_complete_level_10"); | |
} | |
private FirebaseAnalytics mFirebaseAnalytics; | |
private FirebaseRemoteConfig mFirebaseRemoteConfig; | |
private static final String TAG = MainActivity.class.getName(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
RecyclerView newArrivalView = findViewById(R.id.new_arrivals_view); | |
renderProducts(NEW_ARRIVAL, newArrivalView); | |
RecyclerView recommendView = findViewById(R.id.recommendation_view); | |
renderProducts(RECOMMENDATION, recommendView); | |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); | |
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); | |
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults); | |
// [START fetch_config_with_callback] | |
mFirebaseRemoteConfig.fetchAndActivate() | |
.addOnCompleteListener(this, task -> { | |
if (task.isSuccessful()) { | |
boolean updated = task.getResult(); | |
Log.d(TAG, "Config params updated: " + updated); | |
Toast.makeText(MainActivity.this, "Fetch and activate succeeded", | |
Toast.LENGTH_SHORT).show(); | |
} else { | |
Toast.makeText(MainActivity.this, "Fetch failed", | |
Toast.LENGTH_SHORT).show(); | |
} | |
for(Map.Entry<String, String> entry : RC_KEY_TO_EVENT_MAP.entrySet()) { | |
boolean rcValue = mFirebaseRemoteConfig.getBoolean(entry.getKey()); | |
Log.d(TAG, "Remote Config key: " + entry.getKey() + "; value: " + rcValue); | |
if(rcValue) { | |
mFirebaseAnalytics.logEvent(entry.getValue(), new Bundle()); | |
} | |
} | |
}); | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<defaultsMap> | |
<entry> | |
<key>rc_retention</key> | |
<value>false</value> | |
</entry> | |
<entry> | |
<key>rc_complete_level_3</key> | |
<value>false</value> | |
</entry> | |
<entry> | |
<key>rc_complete_level_5</key> | |
<value>false</value> | |
</entry> | |
<entry> | |
<key>rc_complete_level_10</key> | |
<value>false</value> | |
</entry> | |
</defaultsMap> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment