|
@@ -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;
|
|
@@ -35,10 +36,13 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
import android.support.v7.widget.SearchView;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.DisplayMetrics;
|
|
|
+import android.view.GestureDetector;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuInflater;
|
|
|
import android.view.MenuItem;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.ScaleGestureDetector;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.ViewTreeObserver;
|
|
@@ -58,6 +62,7 @@ import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
|
|
import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.authentication.AccountUtils;
|
|
|
+import com.owncloud.android.db.PreferenceManager;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
import com.owncloud.android.lib.resources.files.SearchOperation;
|
|
|
import com.owncloud.android.ui.ExtendedListView;
|
|
@@ -77,8 +82,6 @@ import java.util.ArrayList;
|
|
|
|
|
|
import third_parties.in.srain.cube.GridViewWithHeaderAndFooter;
|
|
|
|
|
|
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
|
|
|
-
|
|
|
public class ExtendedListFragment extends Fragment
|
|
|
implements OnItemClickListener, OnEnforceableRefreshListener, SearchView.OnQueryTextListener {
|
|
|
|
|
@@ -92,7 +95,13 @@ public class ExtendedListFragment extends Fragment
|
|
|
private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
|
|
|
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;
|
|
|
+
|
|
|
+ private int maxColumnSize = 5;
|
|
|
+ private int maxColumnSizePortrait = 5;
|
|
|
+ private int maxColumnSizeLandscape = 10;
|
|
|
|
|
|
+ private ScaleGestureDetector mScaleGestureDetector = null;
|
|
|
protected SwipeRefreshLayout mRefreshListLayout;
|
|
|
protected SwipeRefreshLayout mRefreshGridLayout;
|
|
|
protected SwipeRefreshLayout mRefreshEmptyLayout;
|
|
@@ -126,6 +135,8 @@ public class ExtendedListFragment extends Fragment
|
|
|
protected SearchView searchView;
|
|
|
private Handler handler = new Handler();
|
|
|
|
|
|
+ private float mScale = -1f;
|
|
|
+
|
|
|
@Parcel
|
|
|
public enum SearchType {
|
|
|
NO_SEARCH,
|
|
@@ -208,7 +219,7 @@ public class ExtendedListFragment extends Fragment
|
|
|
if ((activity = getActivity()) != null) {
|
|
|
activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
|
|
int width = displaymetrics.widthPixels;
|
|
|
- if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
|
|
|
+ if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
searchView.setMaxWidth((int) (width * 0.4));
|
|
|
} else {
|
|
|
if (activity instanceof FolderPickerActivity) {
|
|
@@ -369,11 +380,40 @@ public class ExtendedListFragment extends Fragment
|
|
|
mListFooterView = inflater.inflate(R.layout.list_footer, null, false);
|
|
|
|
|
|
mGridView = (GridViewWithHeaderAndFooter) (v.findViewById(R.id.grid_root));
|
|
|
- mGridView.setNumColumns(GridView.AUTO_FIT);
|
|
|
+
|
|
|
+ mScale = PreferenceManager.getGridColumns(getContext());
|
|
|
+ setGridViewColumns(1f);
|
|
|
+
|
|
|
mGridView.setOnItemClickListener(this);
|
|
|
|
|
|
mGridFooterView = inflater.inflate(R.layout.list_footer, null, false);
|
|
|
|
|
|
+ mScaleGestureDetector = new ScaleGestureDetector(MainApp.getAppContext(),new ScaleListener());
|
|
|
+
|
|
|
+ mGridView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
+ mScaleGestureDetector.onTouchEvent(motionEvent);
|
|
|
+
|
|
|
+ if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
|
|
+ view.performClick();
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (savedInstanceState != null) {
|
|
|
+ int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
|
|
|
+ if (mCurrentListView!= null && mCurrentListView.equals(mListView)) {
|
|
|
+ Log_OC.v(TAG, "Setting and centering around list position " + referencePosition);
|
|
|
+ mListView.setAndCenterSelection(referencePosition);
|
|
|
+ } else {
|
|
|
+ Log_OC.v(TAG, "Setting grid position " + referencePosition);
|
|
|
+ mGridView.setSelection(referencePosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Pull-down to refresh layout
|
|
|
mRefreshListLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_containing_list);
|
|
|
mRefreshGridLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_containing_grid);
|
|
@@ -430,6 +470,38 @@ public class ExtendedListFragment extends Fragment
|
|
|
mEmptyListContainer.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
+ private class SingleTapConfirm extends GestureDetector.SimpleOnGestureListener {
|
|
|
+ @Override
|
|
|
+ public boolean onSingleTapUp(MotionEvent e) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
|
|
|
+ @Override
|
|
|
+ public boolean onScale(ScaleGestureDetector detector) {
|
|
|
+ setGridViewColumns(detector.getScaleFactor());
|
|
|
+
|
|
|
+ PreferenceManager.setGridColumns(getContext(), mScale);
|
|
|
+
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setGridViewColumns(float scaleFactor) {
|
|
|
+ if (mScale == -1f) {
|
|
|
+ mGridView.setNumColumns(GridView.AUTO_FIT);
|
|
|
+ mScale = mGridView.getNumColumns();
|
|
|
+ }
|
|
|
+ mScale *= 1.f - (scaleFactor - 1.f);
|
|
|
+ mScale = Math.max(minColumnSize, Math.min(mScale, maxColumnSize));
|
|
|
+ Integer scaleInt = Math.round(mScale);
|
|
|
+ mGridView.setNumColumns(scaleInt);
|
|
|
+ mGridView.invalidateViews();
|
|
|
+ }
|
|
|
+
|
|
|
protected void setupEmptyList(View view) {
|
|
|
mEmptyListContainer = (LinearLayout) view.findViewById(R.id.empty_list_view);
|
|
|
mEmptyListMessage = (TextView) view.findViewById(R.id.empty_list_view_text);
|
|
@@ -457,6 +529,8 @@ public class ExtendedListFragment extends Fragment
|
|
|
mTops = new ArrayList<>();
|
|
|
mHeightCell = 0;
|
|
|
}
|
|
|
+
|
|
|
+ mScale = PreferenceManager.getGridColumns(getContext());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -471,6 +545,8 @@ public class ExtendedListFragment extends Fragment
|
|
|
savedInstanceState.putIntegerArrayList(KEY_TOPS, mTops);
|
|
|
savedInstanceState.putInt(KEY_HEIGHT_CELL, mHeightCell);
|
|
|
savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());
|
|
|
+
|
|
|
+ PreferenceManager.setGridColumns(getContext(), mScale);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -493,6 +569,10 @@ public class ExtendedListFragment extends Fragment
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public int getColumnSize() {
|
|
|
+ return Math.round(mScale);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/*
|
|
|
* Restore index and position
|
|
@@ -824,4 +904,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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|