diff --git a/app/build.gradle b/app/build.gradle index 47f9366a4..69808750f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -155,7 +155,7 @@ dependencies { implementation 'com.google.firebase:firebase-messaging:19.0.1' } implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'com.google.android:flexbox:1.1.0' implementation 'com.github.bumptech.glide:glide:4.9.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 70ca1c5b3..8182f5952 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -64,7 +64,7 @@ android:largeHeap="true" android:roundIcon="@mipmap/ic_launcher_round" android:resizeableActivity="true" - android:theme="@style/LinphoneStyleLight"> + android:theme="@style/LinphoneStyle"> diff --git a/app/src/main/java/org/linphone/activities/ThemeableActivity.java b/app/src/main/java/org/linphone/activities/ThemeableActivity.java index 31dde8c8f..f95f5d74c 100644 --- a/app/src/main/java/org/linphone/activities/ThemeableActivity.java +++ b/app/src/main/java/org/linphone/activities/ThemeableActivity.java @@ -20,56 +20,39 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import org.linphone.R; -import org.linphone.core.tools.Log; import org.linphone.settings.LinphonePreferences; public abstract class ThemeableActivity extends AppCompatActivity { - private int mTheme; @Override protected void onCreate(Bundle savedInstanceState) { - mTheme = R.style.LinphoneStyleLight; - if (LinphonePreferences.instance().isDarkModeEnabled()) { - mTheme = R.style.LinphoneStyleDark; - setTheme(R.style.LinphoneStyleDark); - } - if (getResources().getBoolean(R.bool.orientation_portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } super.onCreate(savedInstanceState); - } - @Override - protected void onSaveInstanceState(Bundle outState) { - outState.putInt("Theme", mTheme); - super.onSaveInstanceState(outState); - } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - mTheme = savedInstanceState.getInt("Theme"); - super.onRestoreInstanceState(savedInstanceState); + int nightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + switch (nightMode) { + case Configuration.UI_MODE_NIGHT_NO: + case Configuration.UI_MODE_NIGHT_UNDEFINED: + if (LinphonePreferences.instance().isDarkModeEnabled()) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + } + case Configuration.UI_MODE_NIGHT_YES: + if (!LinphonePreferences.instance().isDarkModeEnabled()) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + } + } } @Override protected void onResume() { super.onResume(); - - if (LinphonePreferences.instance().isDarkModeEnabled()) { - if (mTheme != R.style.LinphoneStyleDark) { - Log.w("[Themeable Activity] Recreate Activity cause theme doesn't match"); - recreate(); - } - } else { - if (mTheme != R.style.LinphoneStyleLight) { - Log.w("[Themeable Activity] Recreate Activity cause theme doesn't match"); - recreate(); - } - } } } diff --git a/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java b/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java index b698d7dc2..f2741aa22 100644 --- a/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java +++ b/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java @@ -30,6 +30,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatDelegate; import org.linphone.LinphoneService; import org.linphone.R; import org.linphone.compatibility.Compatibility; @@ -147,7 +148,10 @@ public class AdvancedSettingsFragment extends SettingsFragment { @Override public void onBoolValueChanged(boolean newValue) { mPrefs.enableDarkMode(newValue); - getActivity().recreate(); + AppCompatDelegate.setDefaultNightMode( + newValue + ? AppCompatDelegate.MODE_NIGHT_YES + : AppCompatDelegate.MODE_NIGHT_NO); } }); diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml new file mode 100644 index 000000000..7bd84f46a --- /dev/null +++ b/app/src/main/res/values-night/styles.xml @@ -0,0 +1,44 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a8e671de0..27a435916 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,6 +1,6 @@ - - -