mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-09 20:53:47 +01:00
Update PrefService
This commit is contained in:
parent
720d88320d
commit
c6b1d0a4af
@ -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 New Issue
Block a user