Browse Source

add an option to force phone layout on tablet devices

Andrew Dolgov 3 months ago
parent
commit
5c2759c358

+ 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="515"
-    android:versionName="1.281">
+    android:versionCode="516"
+    android:versionName="1.282">
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

@@ -345,7 +345,8 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
 		}
 
 		String[] filter = new String[] { "enable_cats", "headline_mode", "widget_update_interval",
-				"headlines_swipe_to_dismiss", "headlines_mark_read_scroll", "headlines_request_size" };
+				"headlines_swipe_to_dismiss", "headlines_mark_read_scroll", "headlines_request_size",
+				"force_phone_layout" };
 
 		m_needRestart = Arrays.asList(filter).indexOf(key) != -1;
 	}

+ 5 - 1
org.fox.ttrss/src/main/java/org/fox/ttrss/DetailActivity.java

@@ -38,7 +38,11 @@ public class DetailActivity extends OnlineActivity implements HeadlinesEventList
 
         super.onCreate(savedInstanceState);
 
-		setContentView(R.layout.activity_detail);
+		if (m_prefs.getBoolean("force_phone_layout", false)) {
+			setContentView(R.layout.activity_detail_phone);
+		} else {
+			setContentView(R.layout.activity_detail);
+		}
 
 		Toolbar toolbar = findViewById(R.id.toolbar);
 		setSupportActionBar(toolbar);

+ 13 - 12
org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java

@@ -50,17 +50,6 @@ import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
-import androidx.appcompat.app.ActionBar;
-import androidx.core.app.ActivityCompat;
-import androidx.core.app.ActivityOptionsCompat;
-import androidx.core.view.ViewCompat;
-import androidx.recyclerview.widget.DefaultItemAnimator;
-import androidx.recyclerview.widget.DividerItemDecoration;
-import androidx.recyclerview.widget.ItemTouchHelper;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
-
 import com.amulyakhare.textdrawable.TextDrawable;
 import com.amulyakhare.textdrawable.util.ColorGenerator;
 import com.bumptech.glide.Glide;
@@ -92,6 +81,16 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.TimeZone;
 
+import androidx.appcompat.app.ActionBar;
+import androidx.core.app.ActivityCompat;
+import androidx.core.app.ActivityOptionsCompat;
+import androidx.core.view.ViewCompat;
+import androidx.recyclerview.widget.DefaultItemAnimator;
+import androidx.recyclerview.widget.DividerItemDecoration;
+import androidx.recyclerview.widget.ItemTouchHelper;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 import icepick.State;
 import jp.wasabeef.glide.transformations.CropCircleTransformation;
 
@@ -442,6 +441,8 @@ public class HeadlinesFragment extends StateSavedFragment {
         }
 
 		m_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
+			boolean m_forcePhoneLayout = m_prefs.getBoolean("force_phone_layout", false);
+
 			@Override
 			public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
 				super.onScrollStateChanged(recyclerView, newState);
@@ -498,7 +499,7 @@ public class HeadlinesFragment extends StateSavedFragment {
 					}
 				}
 
-				if (!m_activity.isTablet() && m_articles.size() > 0) {
+				if ((m_forcePhoneLayout || !m_activity.isTablet()) && m_articles.size() > 0) {
 					m_amountScrolled += dy;
 					ActionBar bar = m_activity.getSupportActionBar();
 

+ 5 - 1
org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java

@@ -58,7 +58,11 @@ public class MasterActivity extends OnlineActivity implements HeadlinesEventList
 
 		super.onCreate(savedInstanceState);
 
-		setContentView(R.layout.activity_master);
+		if (m_prefs.getBoolean("force_phone_layout", false)) {
+			setContentView(R.layout.activity_master_phone);
+		} else {
+			setContentView(R.layout.activity_master);
+		}
 
 		setSmallScreen(findViewById(R.id.sw600dp_anchor) == null);
 

+ 4 - 3
org.fox.ttrss/src/main/java/org/fox/ttrss/PreferencesFragment.java

@@ -1,6 +1,5 @@
 package org.fox.ttrss;
 
-import android.app.Activity;
 import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
@@ -42,13 +41,15 @@ public class PreferencesFragment extends PreferenceFragment {
             }
         });
 
+        CommonActivity activity = (CommonActivity) getActivity();
+
+        findPreference("force_phone_layout").setEnabled(activity.isTablet());
+
         try {
             String version;
             int versionCode;
             String buildTimestamp;
 
-            Activity activity = getActivity();
-
             PackageInfo packageInfo = activity.getPackageManager().
                     getPackageInfo(activity.getPackageName(), 0);
 

+ 5 - 1
org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDetailActivity.java

@@ -39,7 +39,11 @@ public class OfflineDetailActivity extends OfflineActivity implements OfflineHea
 		
 		super.onCreate(savedInstanceState);
 
-		setContentView(R.layout.activity_detail);
+		if (m_prefs.getBoolean("force_phone_layout", false)) {
+			setContentView(R.layout.activity_detail_phone);
+		} else {
+			setContentView(R.layout.activity_detail);
+		}
 
 		Toolbar toolbar = findViewById(R.id.toolbar);
 		setSupportActionBar(toolbar);

+ 7 - 3
org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java

@@ -107,6 +107,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
     private ListView m_list;
     private int m_listPreviousVisibleItem;
 
+	boolean m_forcePhoneLayout;
+
 	public void initialize(int feedId, boolean isCat, boolean compactMode) {
 		m_feedId = feedId;
 		m_feedIsCat = isCat;
@@ -356,6 +358,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
 		
 		m_list = view.findViewById(R.id.headlines_list);
 
+		m_forcePhoneLayout = m_prefs.getBoolean("force_phone_layout", false);
+
 		FloatingActionButton fab = view.findViewById(R.id.headlines_fab);
 		fab.setVisibility(View.GONE);
 
@@ -648,7 +652,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
 
 					holder.textImage.setImageDrawable(textDrawable);
 
-					Glide.with(OfflineHeadlinesFragment.this)
+					Glide.with(getContext())
 							.load(afi.flavorImageUri)
 							.placeholder(textDrawable)
 							.bitmapTransform(new CropCircleTransformation(getActivity()))
@@ -1000,7 +1004,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
 
 						try {
 
-							Glide.with(OfflineHeadlinesFragment.this)
+							Glide.with(getContext())
 									.load(afi.flavorImageUri)
 									//.dontTransform()
 									.diskCacheStrategy(DiskCacheStrategy.NONE)
@@ -1320,7 +1324,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
             }
         }
 
-        if (!m_activity.isTablet()) {
+        if (m_forcePhoneLayout || !m_activity.isTablet()) {
             if (m_adapter.getCount() > 0) {
                 if (firstVisibleItem > m_listPreviousVisibleItem) {
                     m_activity.getSupportActionBar().hide();

+ 6 - 2
org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineMasterActivity.java

@@ -47,8 +47,12 @@ public class OfflineMasterActivity extends OfflineActivity implements OfflineHea
 		setAppTheme(m_prefs);
 		
 		super.onCreate(savedInstanceState);
-		
-		setContentView(R.layout.activity_master);
+
+		if (m_prefs.getBoolean("force_phone_layout", false)) {
+			setContentView(R.layout.activity_master_phone);
+		} else {
+			setContentView(R.layout.activity_master);
+		}
 
 		Toolbar toolbar = findViewById(R.id.toolbar);
 		setSupportActionBar(toolbar);

+ 6 - 21
org.fox.ttrss/src/main/res/layout/activity_detail.xml

@@ -1,24 +1,9 @@
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/headlines"
-    android:fitsSystemWindows="true"
-    android:animateLayoutChanges="true"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent">
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
 
-    <FrameLayout
-        android:id="@+id/article_fragment"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="?articleBackground">
-    </FrameLayout>
+    <include layout="@layout/activity_detail_phone" />
 
-    <FrameLayout
-        android:id="@+id/headlines_fragment"
-        android:visibility="gone"
-        android:layout_height="0dp"
-        android:layout_width="0dp"
-        android:background="?headlinesBackground">
-    </FrameLayout>
-
-    <include layout="@layout/toolbar" android:id="@+id/toolbar" />
 </FrameLayout>

+ 24 - 0
org.fox.ttrss/src/main/res/layout/activity_detail_phone.xml

@@ -0,0 +1,24 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/headlines"
+    android:fitsSystemWindows="true"
+    android:animateLayoutChanges="true"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent">
+
+    <FrameLayout
+        android:id="@+id/article_fragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="?articleBackground">
+    </FrameLayout>
+
+    <FrameLayout
+        android:id="@+id/headlines_fragment"
+        android:visibility="gone"
+        android:layout_height="0dp"
+        android:layout_width="0dp"
+        android:background="?headlinesBackground">
+    </FrameLayout>
+
+    <include layout="@layout/toolbar" android:id="@+id/toolbar" />
+</FrameLayout>

+ 8 - 44
org.fox.ttrss/src/main/res/layout/activity_master.xml

@@ -1,44 +1,8 @@
-    <androidx.drawerlayout.widget.DrawerLayout
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:fitsSystemWindows="true"
-        android:id="@+id/headlines_drawer"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent">
-
-        <FrameLayout
-            android:fitsSystemWindows="true"
-            android:animateLayoutChanges="true"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent">
-
-            <FrameLayout
-                android:id="@+id/headlines_fragment"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:background="?headlinesBackground"></FrameLayout>
-
-            <include layout="@layout/toolbar" android:id="@+id/toolbar" />
-
-        </FrameLayout>
-
-        <org.fox.ttrss.util.ScrimInsetsFrameLayout
-            xmlns:app="http://schemas.android.com/apk/res-auto"
-            android:id="@+id/scrimInsetsFrameLayout"
-            android:layout_width="300dp"
-            android:layout_height="match_parent"
-            android:layout_gravity="start"
-            android:background="@android:color/white"
-            android:elevation="10dp"
-            android:fitsSystemWindows="true"
-            app:insetForeground="#4000">
-
-        <FrameLayout
-            android:id="@+id/feeds_fragment"
-            android:layout_width="match_parent"
-            android:background="?feedlistBackground"
-            android:layout_height="match_parent" >
-        </FrameLayout>
-
-        </org.fox.ttrss.util.ScrimInsetsFrameLayout>
-
-    </androidx.drawerlayout.widget.DrawerLayout>
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <include layout="@layout/activity_master_phone" />
+</FrameLayout>

+ 44 - 0
org.fox.ttrss/src/main/res/layout/activity_master_phone.xml

@@ -0,0 +1,44 @@
+    <androidx.drawerlayout.widget.DrawerLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:fitsSystemWindows="true"
+        android:id="@+id/headlines_drawer"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+        <FrameLayout
+            android:fitsSystemWindows="true"
+            android:animateLayoutChanges="true"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <FrameLayout
+                android:id="@+id/headlines_fragment"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="?headlinesBackground" />
+
+            <include layout="@layout/toolbar" android:id="@+id/toolbar" />
+
+        </FrameLayout>
+
+        <org.fox.ttrss.util.ScrimInsetsFrameLayout
+            xmlns:app="http://schemas.android.com/apk/res-auto"
+            android:id="@+id/scrimInsetsFrameLayout"
+            android:layout_width="300dp"
+            android:layout_height="match_parent"
+            android:layout_gravity="start"
+            android:background="@android:color/white"
+            android:elevation="10dp"
+            android:fitsSystemWindows="true"
+            app:insetForeground="#4000">
+
+        <FrameLayout
+            android:id="@+id/feeds_fragment"
+            android:layout_width="match_parent"
+            android:background="?feedlistBackground"
+            android:layout_height="match_parent" >
+        </FrameLayout>
+
+        </org.fox.ttrss.util.ScrimInsetsFrameLayout>
+
+    </androidx.drawerlayout.widget.DrawerLayout>

+ 2 - 0
org.fox.ttrss/src/main/res/values/strings.xml

@@ -282,4 +282,6 @@
     <string name="prefs_always_downsample_images">Always resize images</string>
     <string name="prefs_always_downsample_images_long">Even on Wi-Fi</string>
     <string name="prefs_inline_video_player_title">Inline video player</string>
+    <string name="force_phone_layout_summary">On tablet devices</string>
+    <string name="force_phone_layout">Force phone layout</string>
 </resources>

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

@@ -62,6 +62,12 @@
             android:defaultValue="true"
             android:key="open_fresh_on_startup"
             android:title="@string/prefs_open_fresh_on_startup" />
+
+        <org.fox.ttrss.util.LessBrokenSwitchPreference
+            android:defaultValue="false"
+            android:key="force_phone_layout"
+            android:summary="@string/force_phone_layout_summary"
+            android:title="@string/force_phone_layout" />
     </PreferenceCategory>
 
     <PreferenceCategory

+ 1 - 1
tt-rss-android.iml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id="tt-rss-android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
+<module external.linked.project.id="tt-rss-android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
     <facet type="java-gradle" name="Java-Gradle">
       <configuration>