Forráskód Böngészése

Merge pull request #316 from nextcloud/tuneUploadGrid

tune grid view of images
Andy Scherzinger 8 éve
szülő
commit
07c0cafadd

+ 0 - 2
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -71,8 +71,6 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
     private Account mAccount;
     private ComponentsGetter mTransferServiceGetter;
 
-    private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM}
-
     public FileListListAdapter(
             boolean justFolders,
             Context context,

+ 56 - 24
src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

@@ -105,20 +105,54 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
         View view = convertView;
-        boolean isGridView = parent instanceof GridView;
-        if (view == null) {
-            LayoutInflater inflator = (LayoutInflater) mContext
-                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-            view = isGridView ? inflator.inflate(R.layout.grid_item, null) :
-                    inflator.inflate(R.layout.list_item, null);
-        }
+        File file = null;
+        boolean isGridView = true;
+        LayoutInflater inflater = (LayoutInflater) mContext
+                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
         if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
-            File file = mFiles[position];
-            
-            TextView fileName = (TextView) view.findViewById(R.id.Filename);
-            String name = file.getName();
-            fileName.setText(name);
-            
+            file = mFiles[position];
+        }
+
+        if (file != null) {
+            // Find out which layout should be displayed
+            ViewType viewType;
+            if (parent instanceof GridView) {
+                String mimeType = MimetypeIconUtil.getBestMimeTypeByFilename(file.getName());
+                if (MimetypeIconUtil.isImage(mimeType) || MimetypeIconUtil.isVideo(mimeType)) {
+                    viewType = ViewType.GRID_IMAGE;
+                } else {
+                    viewType = ViewType.GRID_ITEM;
+                }
+            } else {
+                viewType = ViewType.LIST_ITEM;
+                isGridView = false;
+            }
+
+            // create view only if differs, otherwise reuse
+            if (convertView == null || convertView.getTag() != viewType) {
+                switch (viewType) {
+                    case GRID_IMAGE:
+                        view = inflater.inflate(R.layout.grid_image, parent, false);
+                        view.setTag(ViewType.GRID_IMAGE);
+                        break;
+                    case GRID_ITEM:
+                        view = inflater.inflate(R.layout.grid_item, parent, false);
+                        view.setTag(ViewType.GRID_ITEM);
+                        break;
+                    case LIST_ITEM:
+                        view = inflater.inflate(R.layout.list_item, parent, false);
+                        view.setTag(ViewType.LIST_ITEM);
+                        break;
+                }
+            }
+
+            if(!ViewType.GRID_IMAGE.equals(viewType)) {
+                TextView fileName = (TextView) view.findViewById(R.id.Filename);
+                String name = file.getName();
+                fileName.setText(name);
+            }
+
             ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
 
             /** Cancellation needs do be checked and done before changing the drawable in fileIcon, or
@@ -175,19 +209,17 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
                         if (allowedToCreateNewThumbnail) {
                             final ThumbnailsCacheManager.ThumbnailGenerationTask task =
                                     new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
-                            if (thumbnail == null) {
-                                if (BitmapUtils.isVideo(file)) {
-                                    thumbnail = ThumbnailsCacheManager.mDefaultVideo;
-                                } else {
-                                    thumbnail = ThumbnailsCacheManager.mDefaultImg;
-                                }
+                            if (BitmapUtils.isVideo(file)) {
+                                thumbnail = ThumbnailsCacheManager.mDefaultVideo;
+                            } else {
+                                thumbnail = ThumbnailsCacheManager.mDefaultImg;
                             }
                             final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
-                        		new ThumbnailsCacheManager.AsyncThumbnailDrawable(
-                                    mContext.getResources(), 
-                                    thumbnail, 
-                                    task
-                		        );
+                                    new ThumbnailsCacheManager.AsyncThumbnailDrawable(
+                                            mContext.getResources(),
+                                            thumbnail,
+                                            task
+                                    );
                             fileIcon.setImageDrawable(asyncDrawable);
                             task.execute(file);
                             Log_OC.v(TAG, "Executing task to generate a new thumbnail");

+ 31 - 0
src/com/owncloud/android/ui/adapter/ViewType.java

@@ -0,0 +1,31 @@
+/**
+ *   Nextcloud Android client application
+ *
+ *   @author Andy Scherzinger
+ *   Copyright (C) 2016 Andy Scherzinger
+ *   Copyright (C) 2016 Nextcloud
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ *   License as published by the Free Software Foundation; either
+ *   version 3 of the License, or any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ *   You should have received a copy of the GNU Affero General Public
+ *   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.ui.adapter;
+
+/**
+ * Enumeration of available/supported view types for file list/grid items
+ */
+public enum ViewType {
+    LIST_ITEM,
+    GRID_IMAGE,
+    GRID_ITEM
+}

+ 28 - 0
src/com/owncloud/android/utils/MimetypeIconUtil.java

@@ -117,6 +117,34 @@ public class MimetypeIconUtil {
         return candidates.get(0);
     }
 
+    /**
+     * @return 'True' if the mime type defines image
+     */
+    public static boolean isImage(String mimeType) {
+        return (mimeType.startsWith("image/") && !mimeType.contains("djvu"));
+    }
+
+    /**
+     * @return 'True' the mime type defines video
+     */
+    public static boolean isVideo(String mimeType) {
+        return (mimeType != null && mimeType.startsWith("video/"));
+    }
+
+    /**
+     * @return 'True' the mime type defines audio
+     */
+    public boolean isAudio(String mimeType) {
+        return (mimeType != null && mimeType.startsWith("audio/"));
+    }
+
+    /**
+     * @return 'True' if mime type defines text
+     */
+    public boolean isText(String mimeType) {
+        return (mimeType != null && mimeType.startsWith("text/"));
+    }
+
     /**
      * determines the icon based on the mime type.
      *