Created
September 6, 2017 13:45
-
-
Save Sloy/5f950b62f302d17378856f7884d887ee to your computer and use it in GitHub Desktop.
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
public class NetworkEndpointPreference extends StringPreference { | |
@Inject | |
public NetworkEndpointPreference(SharedPreferences preferences) { | |
super(preferences, "debug_network_endpoint_url", DebugApiEndpoints.PROD.getUrl()); | |
} | |
} |
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
public class StringPreference { | |
private final SharedPreferences preferences; | |
private final String key; | |
private final String defaultValue; | |
public StringPreference(SharedPreferences preferences, String key) { | |
this(preferences, key, null); | |
} | |
public StringPreference(SharedPreferences preferences, String key, String defaultValue) { | |
this.preferences = preferences; | |
this.key = key; | |
this.defaultValue = defaultValue; | |
} | |
public String get() { | |
return preferences.getString(key, defaultValue); | |
} | |
public boolean isSet() { | |
return preferences.contains(key); | |
} | |
public void set(String value) { | |
preferences.edit().putString(key, value).apply(); | |
} | |
public void delete() { | |
preferences.edit().remove(key).apply(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment