diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 250d604..86fe305 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,6 +29,7 @@ { if(b) { - NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.NIGHT); + NightmodeHelper.setAndSavePreferredNightmode(DayNightMode.NIGHT); } else { - NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.DAY); + NightmodeHelper.setAndSavePreferredNightmode(DayNightMode.DAY); } }); diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/AddressService.java b/app/src/main/java/com/m2049r/xmrwallet/service/AddressService.java index c28a608..70f2f99 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/AddressService.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/AddressService.java @@ -13,8 +13,8 @@ public class AddressService extends ServiceBase { return instance; } - public AddressService(MainActivity mainActivity, MoneroHandlerThread thread) { - super(mainActivity, thread); + public AddressService(MoneroHandlerThread thread) { + super(thread); instance = this; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/BalanceService.java b/app/src/main/java/com/m2049r/xmrwallet/service/BalanceService.java index 1ac45da..ff68ea4 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/BalanceService.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/BalanceService.java @@ -18,8 +18,8 @@ public class BalanceService extends ServiceBase { private final MutableLiveData _lockedBalance = new MutableLiveData<>(0L); public LiveData lockedBalance = _lockedBalance; - public BalanceService(MainActivity mainActivity, MoneroHandlerThread thread) { - super(mainActivity, thread); + public BalanceService(MoneroHandlerThread thread) { + super(thread); instance = this; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/BlockchainService.java b/app/src/main/java/com/m2049r/xmrwallet/service/BlockchainService.java index 3892038..a2fb312 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/BlockchainService.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/BlockchainService.java @@ -18,8 +18,8 @@ public class BlockchainService extends ServiceBase { private final MutableLiveData _currentHeight = new MutableLiveData<>(0L); public LiveData height = _currentHeight; - public BlockchainService(MainActivity mainActivity, MoneroHandlerThread thread) { - super(mainActivity, thread); + public BlockchainService(MoneroHandlerThread thread) { + super(thread); instance = this; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/HistoryService.java b/app/src/main/java/com/m2049r/xmrwallet/service/HistoryService.java index 7efb8cb..aee07eb 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/HistoryService.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/HistoryService.java @@ -20,8 +20,8 @@ public class HistoryService extends ServiceBase { private final MutableLiveData> _history = new MutableLiveData<>(); public LiveData> history = _history; - public HistoryService(MainActivity mainActivity, MoneroHandlerThread thread) { - super(mainActivity, thread); + public HistoryService(MoneroHandlerThread thread) { + super(thread); instance = this; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/PrefService.java b/app/src/main/java/com/m2049r/xmrwallet/service/PrefService.java index e54d9fd..10495c6 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/PrefService.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/PrefService.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import com.m2049r.xmrwallet.MainActivity; +import com.m2049r.xmrwallet.MoneroApplication; public class PrefService extends ServiceBase { public static SharedPreferences instance = null; @@ -12,8 +13,8 @@ public class PrefService extends ServiceBase { return instance; } - public PrefService(MainActivity mainActivity) { - super(mainActivity, null); - instance = mainActivity.getSharedPreferences(mainActivity.getApplicationInfo().packageName, Context.MODE_PRIVATE); + public PrefService(MoneroApplication application) { + super(null); + instance = application.getSharedPreferences(application.getApplicationInfo().packageName, Context.MODE_PRIVATE); } } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/ServiceBase.java b/app/src/main/java/com/m2049r/xmrwallet/service/ServiceBase.java index 28b2a95..14adbfb 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/ServiceBase.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/ServiceBase.java @@ -1,20 +1,12 @@ package com.m2049r.xmrwallet.service; -import com.m2049r.xmrwallet.MainActivity; - public class ServiceBase { - private final MainActivity mainActivity; private final MoneroHandlerThread thread; - public ServiceBase(MainActivity mainActivity, MoneroHandlerThread thread) { - this.mainActivity = mainActivity; + public ServiceBase(MoneroHandlerThread thread) { this.thread = thread; } - public MainActivity getMainActivity() { - return mainActivity; - } - public MoneroHandlerThread getThread() { return thread; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/TxService.java b/app/src/main/java/com/m2049r/xmrwallet/service/TxService.java index 8a2dd95..76c70ba 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/TxService.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/TxService.java @@ -10,8 +10,8 @@ public class TxService extends ServiceBase { return instance; } - public TxService(MainActivity mainActivity, MoneroHandlerThread thread) { - super(mainActivity, thread); + public TxService(MoneroHandlerThread thread) { + super(thread); instance = this; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java b/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java index c819cb5..496356a 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java @@ -5,4 +5,5 @@ public class Constants { public static final String MNEMONIC_LANGUAGE = "English"; public static final String PREF_USES_PASSWORD = "pref_uses_password"; public static final String PREF_USES_TOR = "pref_uses_tor"; + public static final String PREF_NIGHT_MODE = "pref_night_mode"; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/NightmodeHelper.java b/app/src/main/java/com/m2049r/xmrwallet/util/NightmodeHelper.java index d3094b8..120c389 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/NightmodeHelper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/NightmodeHelper.java @@ -23,30 +23,19 @@ import android.preference.PreferenceManager; import androidx.appcompat.app.AppCompatDelegate; import com.m2049r.xmrwallet.R; +import com.m2049r.xmrwallet.service.PrefService; public class NightmodeHelper { - public static DayNightMode getPreferredNightmode(Context context) { - DayNightMode mode = DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context) - .getString(context.getString(R.string.preferred_nightmode), "UNKNOWN")); - if(mode == DayNightMode.UNKNOWN) { - mode = DayNightMode.NIGHT; - } - return mode; + public static DayNightMode getPreferredNightmode() { + return DayNightMode.valueOf(PrefService.getInstance().getString(Constants.PREF_NIGHT_MODE, DayNightMode.NIGHT.name())); } - public static void getAndSetPreferredNightmode(Context context) { - DayNightMode mode = DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context) - .getString(context.getString(R.string.preferred_nightmode), "UNKNOWN")); - if(mode == DayNightMode.UNKNOWN) { - mode = DayNightMode.NIGHT; - } - - setNightMode(mode); + public static void getAndSetPreferredNightmode() { + setNightMode(getPreferredNightmode()); } - public static void setAndSavePreferredNightmode(Context context, DayNightMode mode) { - PreferenceManager.getDefaultSharedPreferences(context).edit() - .putString(context.getString(R.string.preferred_nightmode), mode.name()).apply(); + public static void setAndSavePreferredNightmode(DayNightMode mode) { + PrefService.getInstance().edit().putString(Constants.PREF_NIGHT_MODE, mode.name()).apply(); setNightMode(mode); }