mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-12-22 21:17:47 +00:00
Update PrefService
This commit is contained in:
parent
720d88320d
commit
c6b1d0a4af
1 changed files with 27 additions and 3 deletions
|
@ -6,14 +6,38 @@ import android.content.SharedPreferences;
|
|||
import net.mynero.wallet.MoneroApplication;
|
||||
|
||||
public class PrefService extends ServiceBase {
|
||||
public static SharedPreferences instance = null;
|
||||
public static SharedPreferences preferences = null;
|
||||
public static PrefService instance = null;
|
||||
|
||||
public PrefService(MoneroApplication application) {
|
||||
super(null);
|
||||
instance = application.getSharedPreferences(application.getApplicationInfo().packageName, Context.MODE_PRIVATE);
|
||||
preferences = application.getSharedPreferences(application.getApplicationInfo().packageName, Context.MODE_PRIVATE);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static SharedPreferences getInstance() {
|
||||
public SharedPreferences.Editor edit() {
|
||||
return preferences.edit();
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
String value = preferences.getString(key, "");
|
||||
if(value.isEmpty() && !defaultValue.isEmpty()) {
|
||||
edit().putString(key, defaultValue).apply();
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
boolean value = preferences.getBoolean(key, false);
|
||||
if(!value && defaultValue) {
|
||||
edit().putBoolean(key, true).apply();
|
||||
return true;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static PrefService getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue