Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions app/src/main/java/com/example/healthlog/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.healthlog;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -9,9 +10,13 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.Switch;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
Expand All @@ -24,6 +29,11 @@ public class MainActivity extends AppCompatActivity {

// COMPLETED(SHANK) add logout button in appBar

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);
Expand All @@ -43,7 +53,45 @@ protected void onCreate(Bundle savedInstanceState) {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);

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 void dialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomDialogTheme);
// Set the message show for the Alert time
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<Switch
android:id="@+id/theme_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="50dp"
android:text="Switch"></Switch>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
Expand All @@ -20,9 +28,10 @@
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="642dp"
android:layout_above="@id/nav_view"
android:layout_alignParentTop="true"
android:layout_marginTop="33dp"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />

Expand Down
61 changes: 61 additions & 0 deletions app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimaryNight</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkNight</item>
<item name="colorAccent">@color/colorAccentNight</item>
<item name="android:statusBarColor">@color/colorPrimary</item>

<item name="android:windowBackground">@color/colorPrimaryNight</item>
<item name="primaryTitleColor">@color/primaryTitleColorNight</item>
</style>

<style name="CustomDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<!--<item name="android:windowBackground">#191616</item>-->
<item name="android:background">#000</item>
<item name="android:colorPrimary">#000</item>
<item name="colorAccent">@color/ColorAccentSec</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textSize">16sp</item>
</style>

<!-- new patient layout editText theme. -->
<style name="NewPatientEditTextTheme" parent="Widget.AppCompat.EditText">
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingBottom">16dp</item>
<item name="android:layout_marginLeft">32dp</item>
<item name="android:layout_marginRight">32dp</item>
</style>

<!-- patient layout textView theme. -->
<style name="PatientLayoutTextViewTheme" parent="Widget.AppCompat.TextView">
<item name="android:layout_marginLeft">16dp</item>
<item name="android:layout_marginBottom">16dp</item>
</style>


<!--hospital fragment top box text styles-->
<style name="hospitalFragmentTextHeadingStyle" parent="Widget.AppCompat.TextView">
<item name="android:textSize">16sp</item>
<item name="android:layout_margin">8dp</item>
<item name="android:textStyle">bold</item>
<item name="android:minLines">1</item>
<item name="android:maxLines">1</item>
<item name="android:ellipsize">end</item>
</style>

<style name="hospitalFragmentTextValueStyle" parent="Widget.AppCompat.TextView">
<item name="android:textSize">16sp</item>
<item name="android:layout_marginLeft">8dp</item>
<item name="android:textStyle">bold</item>
</style>

<!--Splash Screen Theme-->
<style name="splashScreenTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:statusBarColor">@color/colorPrimary</item>
</style>

</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/attributes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="primaryTitleColor" format="color" />
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@
<color name="deceasedLightText">#A7ACB1</color>
<color name="deceasedDarkText">#6E777E</color>

<!-- dark theme colors -->
<color name="colorPrimaryNight">#16202c</color>
<color name="colorPrimaryDarkNight">#141d26</color>
<color name="colorAccentNight">#ffffff</color>

<color name="primaryTitleColor">#212121</color>
<color name="primaryTitleColorNight">#ffffff</color>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<item name="colorPrimaryDark">@color/colorPrimaryLight</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@color/colorPrimary</item>
<item name="primaryTitleColor">@color/primaryTitleColor</item>
</style>

<style name="CustomDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
Expand Down