11package org .openimis .imisclaims ;
22
33import android .app .AlertDialog ;
4+ import android .content .Context ;
45import android .content .SharedPreferences ;
56import android .os .Bundle ;
67import android .util .Base64 ;
8+ import android .view .View ;
79import android .widget .Button ;
10+ import android .widget .CompoundButton ;
811import android .widget .EditText ;
12+ import android .widget .Switch ;
13+
14+ import androidx .appcompat .app .AppCompatDelegate ;
915
1016import java .security .MessageDigest ;
1117import java .security .SecureRandom ;
@@ -21,6 +27,11 @@ public class SettingsActivity extends ImisActivity {
2127 private String salt , password ;
2228 public static String generatedSalt ;
2329 Global global ;
30+ private Switch mode_switch ;
31+ SharedPreferences sharedPreferences ;
32+ SharedPreferences .Editor editor ;
33+ private static final String SHPREF_NAME = "SHPref" ;
34+ boolean dark_mode ;
2435
2536 @ Override
2637 protected void onCreate (Bundle savedInstanceState ) {
@@ -32,6 +43,15 @@ protected void onCreate(Bundle savedInstanceState) {
3243 btnSaveRarPwd = (Button )findViewById (R .id .btnSaveRarPwd );
3344 etRarPassword = (EditText )findViewById (R .id .rarPassword );
3445 btnDefaultRarPassword = (Button ) findViewById (R .id .btnDefaultRarPassword );
46+ mode_switch = findViewById (R .id .mode_switch );
47+ global = (Global ) getApplicationContext ();
48+
49+ sharedPreferences = getSharedPreferences (SHPREF_NAME , Context .MODE_PRIVATE );
50+ dark_mode = sharedPreferences .getBoolean ("night" , false );
51+
52+ if (dark_mode ){
53+ mode_switch .setChecked (true );
54+ }
3555
3656 btnSaveRarPwd .setOnClickListener (view -> {
3757 if (etRarPassword .getText ().length () == 0 ){
@@ -52,6 +72,19 @@ protected void onCreate(Bundle savedInstanceState) {
5272 ShowDialog ("Password has been changed to the default rar password" );
5373 });
5474
75+ mode_switch .setOnClickListener (new View .OnClickListener () {
76+ @ Override
77+ public void onClick (View view ) {
78+ if (dark_mode ){
79+ global .setDarkMode (false );
80+ AppCompatDelegate .setDefaultNightMode (AppCompatDelegate .MODE_NIGHT_NO );
81+ } else {
82+ global .setDarkMode (true );
83+ AppCompatDelegate .setDefaultNightMode (AppCompatDelegate .MODE_NIGHT_YES );
84+ }
85+ }
86+ });
87+
5588 }
5689
5790 public static String getGeneratedSalt () {
0 commit comments