Browse Source

remove deprecated MODE_NIGHT_AUTO_TIME
check for night mode using resources instead of theme name

Andrew Dolgov 9 months ago
parent
commit
21ff9102e2

+ 2 - 2
org.fox.ttrss/src/main/AndroidManifest.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="org.fox.ttrss"
-    android:versionCode="509"
-    android:versionName="1.275">
+    android:versionCode="510"
+    android:versionName="1.276">
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

+ 1 - 2
org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java

@@ -469,8 +469,7 @@ public class ArticleFragment extends StateSavedFragment  {
             ws.setMediaPlaybackRequiresUserGesture(false);
         }
 
-        String theme = m_prefs.getString("theme", CommonActivity.THEME_DEFAULT);
-        if (CommonActivity.THEME_DARK.equals(theme) || CommonActivity.THEME_AMBER.equals(theme)) {
+        if (m_activity.isUiNightMode()) {
             m_web.setBackgroundColor(Color.BLACK);
         }
 

+ 21 - 17
org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java

@@ -15,6 +15,7 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.content.res.Configuration;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.BitmapFactory;
 import android.net.ConnectivityManager;
@@ -31,15 +32,6 @@ import android.view.Display;
 import android.view.View;
 import android.widget.CheckBox;
 
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.browser.customtabs.CustomTabsCallback;
-import androidx.browser.customtabs.CustomTabsClient;
-import androidx.browser.customtabs.CustomTabsIntent;
-import androidx.browser.customtabs.CustomTabsServiceConnection;
-import androidx.browser.customtabs.CustomTabsSession;
-import androidx.core.app.JobIntentService;
-
 import com.bumptech.glide.Glide;
 import com.google.android.material.snackbar.Snackbar;
 import com.livefront.bridge.Bridge;
@@ -55,6 +47,14 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.app.AppCompatDelegate;
+import androidx.browser.customtabs.CustomTabsCallback;
+import androidx.browser.customtabs.CustomTabsClient;
+import androidx.browser.customtabs.CustomTabsIntent;
+import androidx.browser.customtabs.CustomTabsServiceConnection;
+import androidx.browser.customtabs.CustomTabsSession;
+import androidx.core.app.JobIntentService;
 import icepick.State;
 
 public class CommonActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -66,11 +66,7 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 	public final static String FRAG_CATS = "cats";
 	public final static String FRAG_DIALOG = "dialog";
 
-	public final static String THEME_DARK = "THEME_DARK";
-	public final static String THEME_LIGHT = "THEME_LIGHT";
-	//public final static String THEME_SEPIA = "THEME_SEPIA";
-    public final static String THEME_AMBER = "THEME_AMBER";
-	public final static String THEME_DEFAULT = CommonActivity.THEME_LIGHT;
+	public final static String THEME_DEFAULT = "THEME_FOLLOW_DEVICE";
 
 	public final static String NOTIFICATION_CHANNEL_NORMAL = "channel_normal";
 	public final static String NOTIFICATION_CHANNEL_PRIORITY = "channel_priority";
@@ -314,6 +310,16 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 				.show();
 	}
 
+	public boolean isUiNightMode() {
+		try {
+			int nightModeFlags = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+
+			return Configuration.UI_MODE_NIGHT_YES == nightModeFlags;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
 	protected void setAppTheme(SharedPreferences prefs) {
 		String theme = prefs.getString("theme", CommonActivity.THEME_DEFAULT);
 
@@ -323,10 +329,8 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 			AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
 		} else if ("THEME_LIGHT".equals(theme)) {
 			AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
-		} else if ("THEME_FOLLOW_DEVICE".equals(theme)) {
-			AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
 		} else {
-			AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_TIME);
+			AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
 		}
 
 		setTheme(R.style.AppTheme);

+ 1 - 3
org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java

@@ -31,7 +31,6 @@ import android.widget.TextView;
 
 import com.shamanland.fab.ShowHideOnScroll;
 
-import org.fox.ttrss.CommonActivity;
 import org.fox.ttrss.R;
 import org.fox.ttrss.util.ImageCacheService;
 import org.fox.ttrss.util.NotifyingScrollView;
@@ -322,8 +321,7 @@ public class OfflineArticleFragment extends Fragment {
 			
 			if (m_web != null) {
 
-				String theme = m_prefs.getString("theme", CommonActivity.THEME_DEFAULT);
-				if (CommonActivity.THEME_DARK.equals(theme) || CommonActivity.THEME_AMBER.equals(theme)) {
+				if (m_activity.isUiNightMode()) {
 					m_web.setBackgroundColor(Color.BLACK);
 				}
 

+ 0 - 3
org.fox.ttrss/src/main/res/values/arrays.xml

@@ -1,12 +1,10 @@
 <resources>
     <string-array name="pref_theme_names">
-        <item>@string/theme_auto</item>
         <item>@string/theme_follow_device</item>
         <item>@string/theme_light</item>
         <item>@string/theme_dark</item>
     </string-array>
     <string-array name="pref_theme_values" translatable="false">
-        <item>THEME_AUTO</item>
         <item>THEME_FOLLOW_DEVICE</item>
         <item>THEME_LIGHT</item>
         <item>THEME_DARK</item>
@@ -54,6 +52,5 @@
         <item>30</item>
         <item>45</item>
     </string-array>
-    <string name="theme_auto">Auto (by time)</string>
     <string name="theme_follow_device">Same as device</string>
 </resources>

+ 1 - 1
org.fox.ttrss/src/main/res/xml/preferences.xml

@@ -32,7 +32,7 @@
         android:key="category_look_and_feel"
         android:title="@string/look_and_feel" >
         <ListPreference
-            android:defaultValue="THEME_AUTO"
+            android:defaultValue="THEME_FOLLOW_DEVICE"
             android:entries="@array/pref_theme_names"
             android:entryValues="@array/pref_theme_values"
             android:key="theme"