diff --git a/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java b/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java index 7e1c850..c7e7482 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java @@ -21,6 +21,7 @@ import com.m2049r.xmrwallet.service.MoneroHandlerThread; import com.m2049r.xmrwallet.service.PrefService; import com.m2049r.xmrwallet.service.TxService; import com.m2049r.xmrwallet.util.Constants; +import com.m2049r.xmrwallet.util.NightmodeHelper; import java.io.File; @@ -37,6 +38,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + NightmodeHelper.getAndSetPreferredNightmode(this); File walletFile = new File(getApplicationInfo().dataDir, Constants.WALLET_NAME); new PrefService(this); diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/settings/SettingsFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/settings/SettingsFragment.java index 568bda5..c109e61 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/settings/SettingsFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/settings/SettingsFragment.java @@ -4,10 +4,12 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.CompoundButton; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; @@ -15,6 +17,8 @@ import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.model.Wallet; import com.m2049r.xmrwallet.model.WalletManager; import com.m2049r.xmrwallet.service.BlockchainService; +import com.m2049r.xmrwallet.util.DayNightMode; +import com.m2049r.xmrwallet.util.NightmodeHelper; public class SettingsFragment extends Fragment { @@ -31,7 +35,10 @@ public class SettingsFragment extends Fragment { super.onViewCreated(view, savedInstanceState); mViewModel = new ViewModelProvider(this).get(SettingsViewModel.class); Wallet wallet = WalletManager.getInstance().getWallet(); + TextView walletInfoTextView = view.findViewById(R.id.wallet_info_textview); + SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch); + StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Seed: " + wallet.getSeed("")+"\n\n"); stringBuilder.append("Private view-key: " + wallet.getSecretViewKey()+"\n\n"); @@ -39,5 +46,14 @@ public class SettingsFragment extends Fragment { stringBuilder.append("Wallet height: " + wallet.getBlockChainHeight() + "\n\n"); stringBuilder.append("Daemon height: " + BlockchainService.getInstance().getDaemonHeight() + "\n\n"); walletInfoTextView.setText(stringBuilder.toString()); + + nightModeSwitch.setChecked(NightmodeHelper.getPreferredNightmode(getContext()) == DayNightMode.NIGHT); + nightModeSwitch.setOnCheckedChangeListener((compoundButton, b) -> { + if(b) { + NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.NIGHT); + } else { + NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.DAY); + } + }); } } \ No newline at end of file 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 3cd622d..d3094b8 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/NightmodeHelper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/NightmodeHelper.java @@ -26,17 +26,22 @@ import com.m2049r.xmrwallet.R; public class NightmodeHelper { public static DayNightMode getPreferredNightmode(Context context) { - return DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(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 void setPreferredNightmode(Context context) { - final DayNightMode mode = DayNightMode.valueOf(PreferenceManager.getDefaultSharedPreferences(context) + 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) - setAndSavePreferredNightmode(context, DayNightMode.AUTO); - else - setNightMode(mode); + if(mode == DayNightMode.UNKNOWN) { + mode = DayNightMode.NIGHT; + } + + setNightMode(mode); } public static void setAndSavePreferredNightmode(Context context, DayNightMode mode) { diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index fb89ace..7763bcf 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -24,4 +24,13 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> + + \ No newline at end of file diff --git a/app/src/main/res/values-night-v23/styles.xml b/app/src/main/res/values-night-v23/styles.xml new file mode 100644 index 0000000..331c450 --- /dev/null +++ b/app/src/main/res/values-night-v23/styles.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v23/styles.xml b/app/src/main/res/values-v23/styles.xml new file mode 100644 index 0000000..2706f11 --- /dev/null +++ b/app/src/main/res/values-v23/styles.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file