diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..0d15693 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,23 @@ + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index d5d35ec..39c65f6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/app/src/main/java/com/example/healthlog/MainActivity.java b/app/src/main/java/com/example/healthlog/MainActivity.java index 142e354..ef187a1 100644 --- a/app/src/main/java/com/example/healthlog/MainActivity.java +++ b/app/src/main/java/com/example/healthlog/MainActivity.java @@ -7,9 +7,7 @@ import android.content.res.Configuration; import android.os.Bundle; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -26,6 +24,7 @@ public class MainActivity extends AppCompatActivity { // COMPLETED(SHANK) add logout button in appBar + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -38,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) { // menu should be considered as top level destinations. AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( - R.id.navigation_dashboard, R.id.navigation_doctor, R.id.navigation_hospitals) + R.id.navigation_dashboard, R.id.navigation_doctor, R.id.navigation_hospitals) .build(); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); @@ -85,7 +84,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { case R.id.about: showAboutAppPage();break; case R.id.setting: - showSettingsAppPage(); + showSettingsAppPage(); break; default: super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/com/example/healthlog/SettingsActivity.java b/app/src/main/java/com/example/healthlog/SettingsActivity.java index b2984a0..cdc11aa 100644 --- a/app/src/main/java/com/example/healthlog/SettingsActivity.java +++ b/app/src/main/java/com/example/healthlog/SettingsActivity.java @@ -1,5 +1,6 @@ package com.example.healthlog; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -7,10 +8,13 @@ import android.os.Bundle; import android.util.DisplayMetrics; import android.util.Log; +import android.widget.CompoundButton; +import android.widget.Switch; import android.widget.Toast; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; @@ -19,6 +23,11 @@ public class SettingsActivity extends AppCompatActivity { + private Switch mSwitch; + private static final String MyPREFERENCES = "nightModePrefs"; + private static final String KEY_ISNIGHTMODE = "isNightMode"; + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -37,6 +46,42 @@ protected void onCreate(Bundle savedInstanceState) { actionBar.setTitle(R.string.setting); actionBar.setDisplayHomeAsUpEnabled(true); } + mSharedPreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); + mSwitch = findViewById(R.id.theme_toggle); + checkNightModeActivated(); + + mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if(isChecked){ + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + saveNightMode(true); + recreate(); + } else { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + saveNightMode(false); + recreate(); + } + } + }); + } + + //save night or dark mode + private void saveNightMode(boolean nightMode) { + SharedPreferences.Editor editor =mSharedPreferences.edit(); + editor.putBoolean(KEY_ISNIGHTMODE,nightMode); + editor.apply(); + } + + //checking the dark theme switch + public void checkNightModeActivated(){ + if(mSharedPreferences.getBoolean(KEY_ISNIGHTMODE,false)){ + mSwitch.setChecked(true); + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + } else { + mSwitch.setChecked(false); + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + } } public static class SettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener { diff --git a/app/src/main/res/drawable/ic_baseline_nights_stay_24.xml b/app/src/main/res/drawable/ic_baseline_nights_stay_24.xml new file mode 100644 index 0000000..dac2591 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_nights_stay_24.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_baseline_wb_sunny_24.xml b/app/src/main/res/drawable/ic_baseline_wb_sunny_24.xml new file mode 100644 index 0000000..fc8da89 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_wb_sunny_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml index ae8ae7d..98315bf 100644 --- a/app/src/main/res/layout/settings_activity.xml +++ b/app/src/main/res/layout/settings_activity.xml @@ -1,10 +1,43 @@ - + android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto"> - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/switch_item.xml b/app/src/main/res/layout/switch_item.xml new file mode 100644 index 0000000..96b022e --- /dev/null +++ b/app/src/main/res/layout/switch_item.xml @@ -0,0 +1,41 @@ + + + + + + + + + + diff --git a/app/src/main/res/menu/menu_logout.xml b/app/src/main/res/menu/menu_logout.xml index 4abfd91..6183610 100644 --- a/app/src/main/res/menu/menu_logout.xml +++ b/app/src/main/res/menu/menu_logout.xml @@ -2,13 +2,6 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000..18207a9 --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9a3b6c9..0a7c183 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -11,7 +11,7 @@ #FFBE00 - + #E2E2F4 #6B70C4 #383AAE @@ -31,5 +31,12 @@ #A7ACB1 #6E777E + + #16202c + #141d26 + #ffffff + + #212121 + #ffffff diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1b314c2..08f99cb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,6 +7,7 @@ @color/colorPrimaryLight @color/colorAccent @color/colorPrimary + @color/primaryTitleColor - - -