From ca59c75371ac7611bca32dc544c204d981b3810f Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 15 Sep 2014 19:12:12 +0200 Subject: [PATCH] - GridLayout --- res/layout/{image_item.xml => grid_image.xml} | 15 ++- res/layout/grid_item.xml | 118 ++++++++++++++++++ res/layout/list_fragment.xml | 22 ++-- .../owncloud/android/ui/ExtendedListView.java | 6 +- .../ui/adapter/FileListListAdapter.java | 21 +++- .../ui/fragment/ExtendedListFragment.java | 54 ++++---- .../ui/fragment/LocalFileListFragment.java | 12 +- .../ui/fragment/OCFileListFragment.java | 6 +- 8 files changed, 193 insertions(+), 61 deletions(-) rename res/layout/{image_item.xml => grid_image.xml} (90%) create mode 100644 res/layout/grid_item.xml diff --git a/res/layout/image_item.xml b/res/layout/grid_image.xml similarity index 90% rename from res/layout/image_item.xml rename to res/layout/grid_image.xml index bd9f8d7153..a9fe863f36 100644 --- a/res/layout/image_item.xml +++ b/res/layout/grid_image.xml @@ -34,6 +34,13 @@ android:layout_marginTop="5dp" android:src="@drawable/ic_menu_archive" /> + + - - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/list_fragment.xml b/res/layout/list_fragment.xml index 24dbb49a15..1f51f41e23 100644 --- a/res/layout/list_fragment.xml +++ b/res/layout/list_fragment.xml @@ -19,7 +19,7 @@ --> @@ -31,7 +31,14 @@ + android:layout_height="match_parent" + android:columnWidth="160dp" + android:gravity="center" + android:horizontalSpacing="10dp" + android:numColumns="auto_fit" + android:stretchMode="columnWidth" + android:verticalSpacing="10dp" + android:visibility="visible" /> - - \ No newline at end of file diff --git a/src/com/owncloud/android/ui/ExtendedListView.java b/src/com/owncloud/android/ui/ExtendedListView.java index 9fe885bfc3..9b347bec6e 100644 --- a/src/com/owncloud/android/ui/ExtendedListView.java +++ b/src/com/owncloud/android/ui/ExtendedListView.java @@ -21,6 +21,7 @@ package com.owncloud.android.ui; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; +import android.widget.GridView; import android.widget.ListView; /** @@ -30,7 +31,7 @@ import android.widget.ListView; * * @author David A. Velasco */ -public class ExtendedListView extends ListView { +public class ExtendedListView extends GridView { private int mPositionToSetAndCenter; @@ -55,7 +56,8 @@ public class ExtendedListView extends ListView { protected void onDraw (Canvas canvas) { super.onDraw(canvas); if (mPositionToSetAndCenter > 0) { - this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2); + this.setSelection(mPositionToSetAndCenter); + //this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2); mPositionToSetAndCenter = 0; } } diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index c6fc19e45c..202854f6b8 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -130,22 +130,31 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { } View view = convertView; + OCFile file = null; LayoutInflater inflator = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + if (mFiles != null && mFiles.size() > position) { + file = mFiles.get(position); + } + if (fileView){ view = inflator.inflate(R.layout.list_item, null); } else { - view = inflator.inflate(R.layout.image_item, null); + if (file.isImage()){ + view = inflator.inflate(R.layout.grid_image, null); + } else { + view = inflator.inflate(R.layout.grid_item, null); + } + View frame = view.findViewById(R.id.imageItemFrame); frame.setVisibility(View.GONE); } -// } view.invalidate(); - if (mFiles != null && mFiles.size() > position) { - OCFile file = mFiles.get(position); + if (file != null){ TextView fileName = (TextView) view.findViewById(R.id.Filename); - if (!fileView){fileName.setVisibility(View.GONE);} + // if (!fileView){fileName.setVisibility(View.GONE);} String name = file.getFileName(); fileName.setText(name); @@ -189,7 +198,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { } GridView parentList = (GridView)parent; - if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { + if (parentList.getChoiceMode() == GridView.CHOICE_MODE_NONE) { checkBoxV.setVisibility(View.GONE); } else { if (parentList.isItemChecked(position)) { diff --git a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index bbf33e5750..547a3c0718 100644 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -52,7 +52,7 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL"; private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE"; - protected ExtendedListView mList; + // protected ExtendedListView mList; private SwipeRefreshLayout mRefreshLayout; private SwipeRefreshLayout mRefreshEmptyLayout; @@ -66,29 +66,24 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null; - private GridView imageView; - private View fileView; - - + protected GridView imageView; + public void setListAdapter(ListAdapter listAdapter) { imageView.setAdapter(listAdapter); imageView.invalidate(); } - public ListView getListView() { - return mList; + public GridView getGridView() { + return imageView; } protected void switchImageView(){ - // TODO berechnen, wieviele Spalten - imageView.setNumColumns(3); - mList.invalidate(); + imageView.setNumColumns(GridView.AUTO_FIT); imageView.invalidate(); } protected void switchFileView(){ - imageView.setNumColumns(1); - mList.invalidate(); + imageView.setNumColumns(1); imageView.invalidate(); } @@ -99,15 +94,16 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { View v = inflater.inflate(R.layout.list_fragment, null); - imageView = (GridView) v.findViewById(R.id.grid_list_view); - imageView.setOnItemClickListener(this); +// imageView = (GridView) v.findViewById(R.id.grid_list_view); +// imageView.setOnItemClickListener(this); // mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view); - mList = (ExtendedListView)(v.findViewById(R.id.list_root)); - // mList.setOnItemClickListener(this); + imageView = (ExtendedListView)(v.findViewById(R.id.list_root)); + imageView.setOnItemClickListener(this); - mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator)); - mList.setDividerHeight(1); + //mList.set + //mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator)); + //mList.setDividerHeight(1); if (savedInstanceState != null) { int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION); @@ -121,7 +117,7 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { onCreateSwipeToRefresh(mRefreshLayout); onCreateSwipeToRefresh(mRefreshEmptyLayout); - mList.setEmptyView(mRefreshEmptyLayout); +// mList.setEmptyView(mRefreshEmptyLayout); return v; } @@ -172,8 +168,8 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { * @return The position in the list of the visible item in the center of the screen. */ protected int getReferencePosition() { - if (mList != null) { - return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2; + if (imageView != null) { + return (imageView.getFirstVisiblePosition() + imageView.getLastVisiblePosition()) / 2; } else { return 0; } @@ -186,8 +182,8 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()} */ protected void setReferencePosition(int position) { - if (mList != null) { - mList.setAndCenterSelection(position); + if (imageView != null) { + imageView.setSelection(position); } } @@ -205,20 +201,20 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { int top = mTops.remove(mTops.size() - 1); - mList.setSelectionFromTop(firstPosition, top); + imageView.setSelection(firstPosition); // Move the scroll if the selection is not visible int indexPosition = mHeightCell*index; - int height = mList.getHeight(); + int height = imageView.getHeight(); if (indexPosition > height) { if (android.os.Build.VERSION.SDK_INT >= 11) { - mList.smoothScrollToPosition(index); + imageView.smoothScrollToPosition(index); } else if (android.os.Build.VERSION.SDK_INT >= 8) { - mList.setSelectionFromTop(index, 0); + imageView.setSelection(index); } } @@ -232,10 +228,10 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { mIndexes.add(index); - int firstPosition = mList.getFirstVisiblePosition(); + int firstPosition = imageView.getFirstVisiblePosition(); mFirstPositions.add(firstPosition); - View view = mList.getChildAt(0); + View view = imageView.getChildAt(0); int top = (view == null) ? 0 : view.getTop() ; mTops.add(top); diff --git a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java index c6d562c939..c695733d89 100644 --- a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@ -75,7 +75,7 @@ public class LocalFileListFragment extends ExtendedListFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.i(TAG, "onCreateView() start"); View v = super.onCreateView(inflater, container, savedInstanceState); - getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + getGridView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); disableSwipe(); // Disable pull refresh setMessageForEmptyList(getString(R.string.local_file_list_empty)); Log_OC.i(TAG, "onCreateView() end"); @@ -117,7 +117,7 @@ public class LocalFileListFragment extends ExtendedListFragment { } else { /// Click on a file ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox); if (checkBoxV != null) { - if (getListView().isItemChecked(position)) { + if (getGridView().isItemChecked(position)) { checkBoxV.setImageResource(android.R.drawable.checkbox_on_background); } else { checkBoxV.setImageResource(android.R.drawable.checkbox_off_background); @@ -194,10 +194,10 @@ public class LocalFileListFragment extends ExtendedListFragment { directory = directory.getParentFile(); } - mList.clearChoices(); // by now, only files in the same directory will be kept as selected + imageView.clearChoices(); // by now, only files in the same directory will be kept as selected mAdapter.swapDirectory(directory); if (mDirectory == null || !mDirectory.equals(directory)) { - mList.setSelectionFromTop(0, 0); + imageView.setSelection(0); } mDirectory = directory; } @@ -210,12 +210,12 @@ public class LocalFileListFragment extends ExtendedListFragment { */ public String[] getCheckedFilePaths() { String [] result = null; - SparseBooleanArray positions = mList.getCheckedItemPositions(); + SparseBooleanArray positions = imageView.getCheckedItemPositions(); if (positions.size() > 0) { Log_OC.d(TAG, "Returning " + positions.size() + " selected files"); result = new String[positions.size()]; for (int i=0; i