Skip to content

Instantly share code, notes, and snippets.

@eddieberklee
Created September 10, 2020 06:08
Show Gist options
  • Save eddieberklee/c42c7e419e85570365c94eb0f7748f84 to your computer and use it in GitHub Desktop.
Save eddieberklee/c42c7e419e85570365c94eb0f7748f84 to your computer and use it in GitHub Desktop.
Wrapper around Remote Config to simplify fetching config values.
public class RemoteConfigUtil {
public static final String SHOULD_REQUIRE_LOGIN = "should_require_login";
public static void init() {
Map<String, Object> defaultsMap = getDefaultsMap();
FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(BuildConfig.DEBUG ? 15 : 3600)
.build();
firebaseRemoteConfig.setConfigSettingsAsync(configSettings);
firebaseRemoteConfig.setDefaultsAsync(defaultsMap);
firebaseRemoteConfig.fetchAndActivate()
.addOnCompleteListener(task -> {
if (CrashUtil.didHandleFirestoreException(task.getException())) {
return;
}
if (!task.isSuccessful()) {
Timber.e("Failed to fetch remote config from firebase");
return;
}
Timber.d("Remote config has been fetched from Firebase");
});
}
private static Map<String, Object> getDefaultsMap() {
Map<String, Object> defaultsMap = new HashMap<>();
defaultsMap.put(SHOULD_REQUIRE_LOGIN, true);
return defaultsMap;
}
/**
* If true, we go to the authentication activity per usual where users have to login.
* If false, we go to the landing activity. Users can use the app without logging in.
* Goal: increase short-term adoption and retention compared to forcing users to login.
*/
public static boolean shouldRequireLogin() {
boolean shouldRequireLogin = FirebaseRemoteConfig
.getInstance()
.getBoolean(SHOULD_REQUIRE_LOGIN);
Timber.d("remote config: " + SHOULD_REQUIRE_LOGIN + ": " + shouldRequireLogin);
return shouldRequireLogin;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment