Last active
November 23, 2016 17:26
-
-
Save riggaroo/48d61770fa4361f1a6392b6650a410c0 to your computer and use it in GitHub Desktop.
Firebase Staged Rollout Features - Sample Gist showing how to use Firebase Remote Config for stage rollout of features.
This file contains 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
public class FriendsActivity extends AppCompatActivity { | |
private static final String TAG = "MainActivity"; | |
public static final String FEATURE_FLAG_ADD_FRIENDS = "feature_add_friends"; | |
private FirebaseRemoteConfig remoteConfig; | |
private Button buttonAddFriend; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
buttonAddFriend = (Button) findViewById(R.id.buttonCheckout); | |
initialiseRemoteConfig(); | |
} | |
private void initialiseRemoteConfig() { | |
remoteConfig = FirebaseRemoteConfig.getInstance(); | |
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() | |
.setDeveloperModeEnabled(BuildConfig.DEBUG).build(); | |
remoteConfig.setConfigSettings(configSettings); | |
remoteConfig.setDefaults(R.xml.firebase_config_defaults); | |
remoteConfig.fetch().addOnCompleteListener(new OnCompleteListener<Void>() { | |
@Override | |
public void onComplete(@NonNull Task<Void> task) { | |
if (task.isSuccessful()) { | |
Log.d(TAG, "Fetch Succeeded"); | |
remoteConfig.activateFetched(); | |
} else { | |
Log.d(TAG, "Fetch Failed"); | |
} | |
} | |
}); | |
enableFeatureFriends(); | |
} | |
private void enableFeatureFriends() { | |
boolean featureAddFriendsEnabled = remoteConfig.getBoolean(FEATURE_FLAG_ADD_FRIENDS); | |
if (featureAddFriendsEnabled) { | |
buttonAddFriend.setVisibility(View.VISIBLE); | |
} else { | |
buttonAddFriend.setVisibility(View.GONE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment