Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark theme #208

Merged
merged 14 commits into from
Jun 20, 2022
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.makore;


import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
Expand All @@ -9,10 +11,12 @@
import android.view.MenuItem;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import androidx.preference.PreferenceManager;
import androidx.room.Room;

import com.example.makore.auth.SignInActivity;
Expand Down Expand Up @@ -51,6 +55,11 @@ protected void onCreate(Bundle savedInstanceState) {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean isNightMode = sharedPreferences.getBoolean("dark_mode", false);
if (isNightMode) {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.example.makore.auth;

import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import com.example.makore.MainActivity;
import com.example.makore.api.UserAPI;
Expand All @@ -24,6 +28,11 @@ public class SignInActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedPreferences1 = PreferenceManager.getDefaultSharedPreferences(this);
boolean isNightMode = sharedPreferences1.getBoolean("dark_mode", false);
if (isNightMode) {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
}
super.onCreate(savedInstanceState);
binding = ActivitySignInBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.example.makore.auth;

import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import com.example.makore.MainActivity;
import com.example.makore.api.UserAPI;
Expand All @@ -24,6 +28,11 @@ public class SignUpActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedPreferences1 = PreferenceManager.getDefaultSharedPreferences(this);
boolean isNightMode = sharedPreferences1.getBoolean("dark_mode", false);
if (isNightMode) {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
}
super.onCreate(savedInstanceState);
binding = ActivitySignUpBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
Expand All @@ -32,7 +41,6 @@ protected void onCreate(Bundle savedInstanceState) {
Intent intent = new Intent(SignUpActivity.this, SignInActivity.class);
startActivity(intent);
});

sharedpreferences = getSharedPreferences("user", MODE_PRIVATE);

binding.signUpButton.setOnClickListener(view -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package com.example.makore.chat;

import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;

import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;

import com.example.makore.R;

public class SettingsActivity extends AppCompatActivity {

private void changeTheme(boolean isNightMode) {
if (isNightMode) {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -24,6 +38,13 @@ protected void onCreate(Bundle savedInstanceState) {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences1, key) -> {
if (key.equals("dark_mode")) {
changeTheme(sharedPreferences1.getBoolean(key, false));
}
};
sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}

public static class SettingsFragment extends PreferenceFragmentCompat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor"
tools:context=".chat.AddContactActivity">

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions android-client/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor"
tools:context=".MainActivity">

<com.google.android.material.appbar.AppBarLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/backgroundColor"
tools:context=".auth.SignInActivity">


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor"
tools:context=".auth.SignUpActivity">

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions android-client/app/src/main/res/layout/contact_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:layout_margin="16dp"
android:scaleType="centerCrop"
android:contentDescription="@string/cV_description_profile_picture"
app:tint="?attr/customProfilePicTint"
android:src="@drawable/ic_default_contact_pic_light" />

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor"
tools:context=".ContactsFragment">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="?attr/backgroundColor"
android:layout_height="match_parent">

<FrameLayout
Expand Down
18 changes: 12 additions & 6 deletions android-client/app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
<!-- Base application theme. -->
<style name="Theme.MaKore" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="colorPrimary">@color/darker_blue_2</item>
<item name="colorPrimaryVariant">@color/darker_blue_2</item>
<item name="colorOnPrimary">@color/white_333_d</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorSecondary">@color/darker_blue_0</item>
<item name="colorSecondaryVariant">@color/darker_blue_0</item>
<item name="colorOnSecondary">@color/white_444_d</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<!-- Button color -->
<item name="colorButtonNormal">@color/night_bright</item>
<item name="backgroundColor">@color/darker_blue_4</item>
<item name="customProfilePicTint">@color/white_444_d</item>
</style>

<style name="Theme.MaKore.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />
</resources>
4 changes: 4 additions & 0 deletions android-client/app/src/main/res/values/attrs.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="customProfilePicTint" format="reference" />
</resources>
16 changes: 16 additions & 0 deletions android-client/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="day_bright">#36D1DC</color>
<color name="day_dark">#5B86E5</color>
<color name="night_bright">#36D1DC</color>
<color name="night_dark">#5B86E5</color>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
Expand Down Expand Up @@ -29,5 +33,17 @@
<color name="rich_black_0">#091014</color>
<!-- input-section-border, contacts-section-border -->
<color name="rich_black_1">#1c282e</color>
<!-- message-bubble-left-background dark -->
<color name="darker_blue_0">#2b5278</color>
<!-- message-bubble-right-background dark -->
<color name="darker_blue_1">#1f2c33</color>
<!-- chat-section-header-border -->
<color name="darker_blue_2">#1c282e</color>
<!-- primary-text-color dark mode -->
<color name="white_333_d">#d1d7db</color>
<!-- message-bubble-text dark mode -->
<color name="white_444_d">#e9edef</color>
<color name="darker_blue_3">#283942</color>
<color name="darker_blue_4">#253137</color>

</resources>
14 changes: 8 additions & 6 deletions android-client/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<!-- Base application theme. -->
<style name="Theme.MaKore" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/blue_0</item>
<item name="colorPrimaryVariant">@color/blue_0</item>
<item name="colorPrimary">@color/day_dark</item>
<item name="colorPrimaryVariant">@color/day_dark</item>
<item name="colorOnPrimary">@color/white_1</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/turquoise_0</item>
<item name="colorSecondaryVariant">@color/turquoise_0</item>
<item name="colorOnSecondary">@color/white_1</item>
<item name="colorSecondary">@color/day_bright</item>
<item name="colorSecondaryVariant">@color/day_bright</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<!-- Button color -->
<item name="colorButtonNormal">@color/turquoise_0</item>
<item name="colorButtonNormal">@color/day_bright</item>
<item name="backgroundColor">@color/white</item>
<item name="customProfilePicTint">@color/rich_black_1</item>
</style>

<style name="Theme.MaKore.NoActionBar">
Expand Down