From 04b77aa2f4c35fefe2436630611c7950ec441b56 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 19 Jan 2015 22:10:29 +0100 Subject: [PATCH] rebased footer view disabled due to GridView does not support it --- .../ui/adapter/FileListListAdapter.java | 30 +++-------------- .../ui/fragment/OCFileListFragment.java | 33 ++++--------------- .../owncloud/android/utils/DisplayUtils.java | 30 +++++++++++++++++ 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 62a772ef76..3feb370c27 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -65,7 +65,7 @@ import com.owncloud.android.utils.FileStorageUtils; */ public class FileListListAdapter extends BaseAdapter implements ListAdapter { private final static String PERMISSION_SHARED_WITH_ME = "S"; - + private Context mContext; private OCFile mFile = null; private Vector mFiles = null; @@ -142,29 +142,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { - // decide image vs. file view - double countImages = 0; - double countFiles = 0; - - for (OCFile file : mFiles){ - if (!file.isFolder()){ - countFiles++; - - if (file.isImage()){ - countImages++; - } - } - } - - // TODO threshold as constant in Preferences - // > 50% Images --> image view - boolean fileView = true; - if ((countImages / countFiles) >= 0.5){ - fileView = false; - } else { - fileView = true; - } - + + boolean fileView = DisplayUtils.decideViewLayout(mFiles); + View view = convertView; OCFile file = null; LayoutInflater inflator = (LayoutInflater) mContext @@ -176,7 +156,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { // Find out which layout should be displayed ViewType viewType; - if (fileView){ + if (!fileView){ viewType = ViewType.LIST_ITEM; } else if (file.isImage()){ viewType = ViewType.GRID_IMAGE; diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 114b048d00..4e65cac460 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -48,6 +48,7 @@ import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; +import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; /** @@ -392,35 +393,15 @@ public class OCFileListFragment extends ExtendedListFragment { imageView.setSelection(0); } mFile = directory; - - // Update Footer - TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText); - Log_OC.d("footer", String.valueOf(System.currentTimeMillis())); - footerText.setText(generateFooterText(directory)); - Log_OC.d("footer", String.valueOf(System.currentTimeMillis())); - - // decide image vs. file view - double countImages = 0; - double countFiles = 0; - + Vector files = storageManager.getFolderContent(directory); - for (OCFile file : files){ - if (!file.isFolder()){ - countFiles++; - - if (file.isImage()){ - countImages++; - } - } - } - - // > 50% Images --> image view - // TODO threshold as constant in Preferences - if ((countImages / countFiles) >= 0.5){ - Log_OC.i(TAG, "Image View"); + if (DisplayUtils.decideViewLayout(files)){ switchImageView(); } else { - Log_OC.i(TAG, "Folder View"); + // Update Footer + TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText); + footerText.setText(generateFooterText(directory)); + switchFileView(); } } diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index c93e792225..e22b6de8a6 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -26,6 +26,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.Vector; import android.annotation.TargetApi; import android.content.Context; @@ -51,6 +52,8 @@ public class DisplayUtils { private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; + private final static Double THUMBNAIL_THRESHOLD = 0.5; + private static HashMap mimeType2HUmanReadable; static { mimeType2HUmanReadable = new HashMap(); @@ -340,4 +343,31 @@ public class DisplayUtils { } return path; } + + /** + * + * @param mFiles + * @return true: imageView, false: listView + */ + public static boolean decideViewLayout(Vector mFiles){ + // decide image vs. file view + double countImages = 0; + double countFiles = 0; + + for (OCFile file : mFiles){ + if (!file.isFolder()){ + countFiles++; + + if (file.isImage()){ + countImages++; + } + } + } + + if ((countImages / countFiles) >= THUMBNAIL_THRESHOLD){ + return true; + } else { + return false; + } + } }