浏览代码

use 10cols on landscape, 6 on portrait

tobiasKaminsky 8 年之前
父节点
当前提交
ba14880f3d

+ 1 - 1
src/main/AndroidManifest.xml

@@ -19,7 +19,6 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          xmlns:tools="http://schemas.android.com/tools"
           package="com.owncloud.android"
           android:versionCode="10040299"
           android:versionName="1.4.2">
@@ -72,6 +71,7 @@
         <activity
             android:name=".ui.activity.FileDisplayActivity"
             android:label="@string/app_name"
+            android:configChanges="orientation|screenSize"
             android:theme="@style/Theme.ownCloud.Toolbar.Drawer">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

+ 24 - 1
src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -23,6 +23,7 @@ package com.owncloud.android.ui.fragment;
 
 import android.animation.LayoutTransition;
 import android.app.Activity;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
@@ -96,7 +97,10 @@ public class ExtendedListFragment extends Fragment
     private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
     private static final String KEY_IS_GRID_VISIBLE = "IS_GRID_VISIBLE";
     public static final float minColumnSize = 2.0f;
-    public static final float maxColumnSize = 10.0f;
+
+    private int maxColumnSize = 6;
+    private int maxColumnSizePortrait = 6;
+    private int maxColumnSizeLandscape = 10;
 
     private ScaleGestureDetector mScaleGestureDetector = null;
     protected SwipeRefreshLayout mRefreshListLayout;
@@ -475,6 +479,8 @@ public class ExtendedListFragment extends Fragment
 
             PreferenceManager.setGridColumns(getContext(), mScale);
 
+            mAdapter.notifyDataSetChanged();
+
             return true;
         }
     }
@@ -875,4 +881,21 @@ public class ExtendedListFragment extends Fragment
         }
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+
+        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+            maxColumnSize = maxColumnSizeLandscape;
+        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+            maxColumnSize = maxColumnSizePortrait;
+        } else {
+            maxColumnSize = maxColumnSizePortrait;
+        }
+
+        if (mGridView.getNumColumns() > maxColumnSize) {
+            mGridView.setNumColumns(maxColumnSize);
+            mGridView.invalidateViews();
+        }
+    }
 }