Update PrefService

This commit is contained in:
pokkst 2022-10-15 00:31:56 -05:00
parent 720d88320d
commit c6b1d0a4af
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF

View File

@ -6,14 +6,38 @@ import android.content.SharedPreferences;
import net.mynero.wallet.MoneroApplication; import net.mynero.wallet.MoneroApplication;
public class PrefService extends ServiceBase { public class PrefService extends ServiceBase {
public static SharedPreferences instance = null; public static SharedPreferences preferences = null;
public static PrefService instance = null;
public PrefService(MoneroApplication application) { public PrefService(MoneroApplication application) {
super(null); 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; return instance;
} }
} }