Browse Source

Merge pull request #6044 from nextcloud/feature/newDesign-round-thumbnails

New design (UI) - Round thumbnails
Andy Scherzinger 5 years ago
parent
commit
8e8d57ad27

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-373
+372

+ 1 - 1
src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java

@@ -57,7 +57,7 @@ public final class AppPreferencesImpl implements AppPreferences {
     public static final String AUTO_PREF__LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
     public static final String STORAGE_PATH = "storage_path";
     public static final String PREF__DARK_THEME = "dark_theme_mode";
-    public static final float DEFAULT_GRID_COLUMN = 4.0f;
+    public static final float DEFAULT_GRID_COLUMN = 3f;
 
     private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
     private static final String AUTO_PREF__UPLOAD_FROM_LOCAL_LAST_PATH = "upload_from_local_last_path";

+ 13 - 15
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -427,24 +427,14 @@ public final class ThumbnailsCacheManager {
         private String mImageKey;
         private FileDataStorageManager mStorageManager;
         private GetMethod getMethod;
-        private boolean roundedCorners = false;
         private Listener mListener;
+        private boolean gridViewEnabled = false;
 
         public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager, Account account)
                 throws IllegalArgumentException {
             this(imageView, storageManager, account, null);
         }
 
-        public ThumbnailGenerationTask(ImageView imageView,
-                                       FileDataStorageManager storageManager,
-                                       Account account,
-                                       List<ThumbnailGenerationTask> asyncTasks,
-                                       boolean roundedCorners)
-            throws IllegalArgumentException {
-            this(imageView, storageManager, account, asyncTasks);
-            this.roundedCorners = roundedCorners;
-        }
-
         public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager,
                                        Account account, List<ThumbnailGenerationTask> asyncTasks)
                 throws IllegalArgumentException {
@@ -458,6 +448,14 @@ public final class ThumbnailsCacheManager {
             mAsyncTasks = asyncTasks;
         }
 
+        public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager,
+                                       Account account, List<ThumbnailGenerationTask> asyncTasks,
+                                       boolean gridViewEnabled)
+            throws IllegalArgumentException {
+            this(imageView, storageManager, account, asyncTasks);
+            this.gridViewEnabled = gridViewEnabled;
+        }
+
         public GetMethod getGetMethod() {
             return getMethod;
         }
@@ -543,10 +541,10 @@ public final class ThumbnailsCacheManager {
                         tagId = String.valueOf(((TrashbinFile) mFile).getRemoteId());
                     }
                     if (String.valueOf(imageView.getTag()).equals(tagId)) {
-                        if (roundedCorners) {
-                            BitmapUtils.setRoundedBitmap(bitmap, imageView);
+                        if (gridViewEnabled){
+                            BitmapUtils.setRoundedBitmapForGridMode(bitmap, imageView);
                         } else {
-                            imageView.setImageBitmap(bitmap);
+                        BitmapUtils.setRoundedBitmap(bitmap, imageView);
                         }
                     }
                 }
@@ -673,7 +671,7 @@ public final class ThumbnailsCacheManager {
          *
          * @return int
          */
-        public int getThumbnailDimension() {
+        private int getThumbnailDimension() {
             // Converts dp to pixel
             Resources r = MainApp.getAppContext().getResources();
             Double d = Math.pow(2, Math.floor(Math.log(r.getDimension(R.dimen.file_icon_size_grid)) / Math.log(2)));

+ 46 - 20
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -31,6 +31,7 @@ import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.LinearGradient;
+import android.graphics.Point;
 import android.graphics.PorterDuff;
 import android.graphics.Shader;
 import android.graphics.drawable.Drawable;
@@ -40,6 +41,7 @@ import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.WindowManager;
 import android.widget.Filter;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
@@ -54,6 +56,7 @@ import com.elyeproj.loaderviewlibrary.LoaderImageView;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.preferences.AppPreferences;
+import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
@@ -368,7 +371,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                          asyncTasks,
                          gridView,
                          activity,
-                         gridViewHolder.shimmerThumbnail);
+                         gridViewHolder.shimmerThumbnail, preferences);
 
             if (highlightedItem != null && file.getFileId() == highlightedItem.getFileId()) {
                 gridViewHolder.itemLayout.setBackgroundColor(activity.getResources()
@@ -614,17 +617,18 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                                     List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks,
                                     boolean gridView,
                                     Context context) {
-        setThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, null);
+        setThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, null, null);
     }
 
     private static void setThumbnail(OCFile file,
-                                    ImageView thumbnailView,
-                                    User user,
-                                    FileDataStorageManager storageManager,
-                                    List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks,
-                                    boolean gridView,
-                                    Context context,
-                                    LoaderImageView shimmerThumbnail) {
+                                     ImageView thumbnailView,
+                                     User user,
+                                     FileDataStorageManager storageManager,
+                                     List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks,
+                                     boolean gridView,
+                                     Context context,
+                                     LoaderImageView shimmerThumbnail,
+                                     AppPreferences preferences) {
         if (file.isFolder()) {
             thumbnailView.setImageDrawable(MimeTypeUtil
                                                .getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
@@ -643,7 +647,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                         thumbnailView.setImageBitmap(withOverlay);
                     } else {
                         if (gridView) {
-                            thumbnailView.setImageBitmap(thumbnail);
+                            BitmapUtils.setRoundedBitmapForGridMode(thumbnail, thumbnailView);
                         } else {
                             BitmapUtils.setRoundedBitmap(thumbnail, thumbnailView);
                         }
@@ -657,7 +661,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                                                                                    storageManager,
                                                                                    user.toPlatformAccount(),
                                                                                    asyncTasks,
-                                                                                   !gridView);
+                                                                                   gridView);
                             if (thumbnail == null) {
                                 thumbnail = BitmapUtils.drawableToBitmap(
                                     MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
@@ -671,7 +675,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
                             if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
                                 if (gridView) {
-                                    configShimmerGridImageSize(shimmerThumbnail, task.getThumbnailDimension());
+                                    configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
                                 }
                                 startShimmer(shimmerThumbnail, thumbnailView);
                             }
@@ -721,6 +725,36 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         }
     }
 
+    private static Point getScreenSize(Context context) throws Exception {
+        final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+        if (windowManager != null) {
+            final Point displaySize = new Point();
+            windowManager.getDefaultDisplay().getSize(displaySize);
+            return displaySize;
+        } else {
+            throw new Exception("WindowManager not found");
+        }
+    }
+
+    private static void configShimmerGridImageSize(LoaderImageView thumbnailShimmer, float gridColumns) {
+        FrameLayout.LayoutParams targetLayoutParams = (FrameLayout.LayoutParams) thumbnailShimmer.getLayoutParams();
+
+        try {
+            final Point screenSize = getScreenSize(thumbnailShimmer.getContext());
+            final int marginLeftAndRight = Math.round(targetLayoutParams.leftMargin + targetLayoutParams.rightMargin);
+            final int size = Math.round(screenSize.x / gridColumns - marginLeftAndRight);
+
+            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(size, size);
+            params.setMargins(targetLayoutParams.leftMargin,
+                              targetLayoutParams.topMargin,
+                              targetLayoutParams.rightMargin,
+                              targetLayoutParams.bottomMargin);
+            thumbnailShimmer.setLayoutParams(params);
+        } catch (Exception exception) {
+            Log_OC.e("ConfigShimmer", exception.getMessage());
+        }
+    }
+
     private static void startShimmer(LoaderImageView thumbnailShimmer, ImageView thumbnailView) {
         thumbnailShimmer.setImageResource(R.drawable.background);
         thumbnailShimmer.resetLoader();
@@ -735,14 +769,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         }
     }
 
-    private static void configShimmerGridImageSize(LoaderImageView thumbnailShimmer, int size){
-        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,size);
-        FrameLayout.LayoutParams targetLayoutParams = (FrameLayout.LayoutParams) thumbnailShimmer.getLayoutParams();
-        params.setMargins(targetLayoutParams.leftMargin, targetLayoutParams.topMargin,
-                          targetLayoutParams.rightMargin, targetLayoutParams.bottomMargin);
-        thumbnailShimmer.setLayoutParams(params);
-    }
-
     private String getFooterText() {
         int filesCount = 0;
         int foldersCount = 0;

+ 2 - 2
src/main/java/com/owncloud/android/ui/trashbin/RemoteTrashbinRepository.java

@@ -81,7 +81,7 @@ public class RemoteTrashbinRepository implements TrashbinRepository {
                 return result.isSuccess();
             } catch (ClientFactory.CreationException e) {
                 Log_OC.e(this, "Cannot create client", e);
-                return false;
+                return Boolean.FALSE;
             }
         }
 
@@ -160,7 +160,7 @@ public class RemoteTrashbinRepository implements TrashbinRepository {
                 return result.isSuccess();
             } catch (ClientFactory.CreationException e) {
                 Log_OC.e(this, "Cannot create client", e);
-                return false;
+                return Boolean.FALSE;
             }
         }
 

+ 12 - 3
src/main/java/com/owncloud/android/utils/BitmapUtils.java

@@ -430,11 +430,20 @@ public final class BitmapUtils {
     }
 
     public static void setRoundedBitmap(Bitmap thumbnail, ImageView imageView) {
-        Resources resources = MainApp.getAppContext().getResources();
+        BitmapUtils.setRoundedBitmap(getResources(),
+                                     thumbnail,
+                                     getResources().getDimension(R.dimen.file_icon_rounded_corner_radius),
+                                     imageView);
+    }
 
-        BitmapUtils.setRoundedBitmap(resources,
+    public static void setRoundedBitmapForGridMode(Bitmap thumbnail, ImageView imageView){
+        BitmapUtils.setRoundedBitmap(getResources(),
                                      thumbnail,
-                                     resources.getDimension(R.dimen.file_icon_rounded_corner_radius),
+                                     getResources().getDimension(R.dimen.file_icon_rounded_corner_radius_for_grid_mode),
                                      imageView);
     }
+
+    private static Resources getResources(){
+        return MainApp.getAppContext().getResources();
+    }
 }

+ 16 - 23
src/main/res/layout/grid_image.xml

@@ -30,32 +30,25 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
 
-        <FrameLayout
-            android:id="@+id/shimmer_view_container"
+        <com.elyeproj.loaderviewlibrary.LoaderImageView
+            android:id="@+id/thumbnail_shimmer"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:clipChildren="true">
+            android:layout_margin="@dimen/grid_image_icon_margin"
+            android:contentDescription="@null"
+            android:visibility="gone"
+            app:corners="6"
+            app:height_weight="0.6"
+            app:width_weight="0.4" />
 
-            <com.elyeproj.loaderviewlibrary.LoaderImageView
-                android:id="@+id/thumbnail_shimmer"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:layout_margin="@dimen/standard_eigth_padding"
-                android:contentDescription="@null"
-                android:scaleType="centerCrop"
-                android:visibility="gone"
-                app:width_weight="0.4"
-                app:height_weight="0.6" />
-
-            <com.owncloud.android.ui.SquareImageView
-                android:id="@+id/thumbnail"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:contentDescription="@null"
-                android:padding="@dimen/standard_eigth_padding"
-                android:scaleType="centerCrop"
-                android:src="@drawable/folder" />
-        </FrameLayout>
+        <com.owncloud.android.ui.SquareImageView
+            android:id="@+id/thumbnail"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:contentDescription="@null"
+            android:padding="@dimen/grid_image_icon_padding"
+            android:scaleType="centerCrop"
+            android:src="@drawable/folder" />
 
         <ImageView
             android:id="@+id/favorite_action"

+ 15 - 19
src/main/res/layout/grid_item.xml

@@ -16,6 +16,7 @@
 
 -->
 <com.owncloud.android.ui.SquareLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/ListItemLayout"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
@@ -29,26 +30,21 @@
         android:layout_height="wrap_content"
         android:layout_gravity="center_horizontal">
 
-        <FrameLayout
-            android:id="@+id/shimmer_view_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center">
+        <com.elyeproj.loaderviewlibrary.LoaderImageView
+            android:id="@+id/thumbnail_shimmer"
+            android:layout_width="@dimen/standard_list_item_size"
+            android:layout_height="@dimen/standard_list_item_size"
+            android:layout_gravity="center"
+            android:visibility="gone"
+            app:corners="8" />
 
-            <com.elyeproj.loaderviewlibrary.LoaderImageView
-                android:id="@+id/thumbnail_shimmer"
-                android:layout_width="@dimen/standard_list_item_size"
-                android:layout_height="@dimen/standard_list_item_size"
-                android:visibility="gone" />
-
-            <ImageView
-                android:id="@+id/thumbnail"
-                android:layout_width="@dimen/standard_list_item_size"
-                android:layout_height="@dimen/standard_list_item_size"
-                android:layout_gravity="center"
-                android:contentDescription="@null"
-                android:src="@drawable/folder" />
-        </FrameLayout>
+        <ImageView
+            android:id="@+id/thumbnail"
+            android:layout_width="@dimen/standard_list_item_size"
+            android:layout_height="@dimen/standard_list_item_size"
+            android:layout_gravity="center"
+            android:contentDescription="@null"
+            android:src="@drawable/folder" />
 
         <ImageView
             android:id="@+id/favorite_action"

+ 20 - 27
src/main/res/layout/list_item.xml

@@ -34,36 +34,29 @@
         android:layout_marginEnd="@dimen/standard_quarter_padding"
         android:layout_marginBottom="@dimen/standard_padding">
 
-        <ImageView
-            android:id="@+id/thumbnail"
-            android:layout_width="@dimen/file_icon_size"
-            android:layout_height="@dimen/file_icon_size"
-            android:contentDescription="@null"
-            android:src="@drawable/folder"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
-
-        <RelativeLayout
-            android:id="@+id/shimmer_view_container"
+        <FrameLayout
+            android:id="@+id/thumbnail_layout"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_centerInParent="true"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent">
 
+            <ImageView
+                android:id="@+id/thumbnail"
+                android:layout_width="@dimen/file_icon_size"
+                android:layout_height="@dimen/file_icon_size"
+                android:contentDescription="@null"
+                android:src="@drawable/folder" />
+
             <com.elyeproj.loaderviewlibrary.LoaderImageView
                 android:id="@+id/thumbnail_shimmer"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginStart="@dimen/standard_half_margin"
+                android:layout_width="@dimen/file_icon_size"
+                android:layout_height="@dimen/file_icon_size"
                 android:visibility="gone"
                 app:corners="8" />
-
-        </RelativeLayout>
+        </FrameLayout>
 
         <ImageView
             android:id="@+id/localFileIndicator"
@@ -72,10 +65,10 @@
             android:contentDescription="@string/downloader_download_succeeded_ticker"
             android:scaleType="fitCenter"
             android:src="@drawable/ic_synced"
-            app:layout_constraintBottom_toBottomOf="@+id/thumbnail"
-            app:layout_constraintEnd_toEndOf="@+id/thumbnail"
-            app:layout_constraintStart_toEndOf="@+id/thumbnail"
-            app:layout_constraintTop_toBottomOf="@+id/thumbnail" />
+            app:layout_constraintBottom_toBottomOf="@+id/thumbnail_layout"
+            app:layout_constraintEnd_toEndOf="@+id/thumbnail_layout"
+            app:layout_constraintStart_toEndOf="@+id/thumbnail_layout"
+            app:layout_constraintTop_toBottomOf="@+id/thumbnail_layout" />
 
         <ImageView
             android:id="@+id/favorite_action"
@@ -83,10 +76,10 @@
             android:layout_height="@dimen/list_item_favorite_action_layout_height"
             android:contentDescription="@string/favorite"
             android:src="@drawable/favorite"
-            app:layout_constraintBottom_toTopOf="@+id/thumbnail"
-            app:layout_constraintEnd_toEndOf="@+id/thumbnail"
-            app:layout_constraintStart_toEndOf="@+id/thumbnail"
-            app:layout_constraintTop_toTopOf="@+id/thumbnail" />
+            app:layout_constraintBottom_toTopOf="@+id/thumbnail_layout"
+            app:layout_constraintEnd_toEndOf="@+id/thumbnail_layout"
+            app:layout_constraintStart_toEndOf="@+id/thumbnail_layout"
+            app:layout_constraintTop_toTopOf="@+id/thumbnail_layout" />
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 

+ 3 - 0
src/main/res/values/dims.xml

@@ -32,6 +32,7 @@
     <dimen name="file_icon_size">40dp</dimen>
     <dimen name="file_icon_size_grid">128dp</dimen>
     <dimen name="file_icon_rounded_corner_radius">8dp</dimen>
+    <dimen name="file_icon_rounded_corner_radius_for_grid_mode">3dp</dimen>
     <dimen name="file_avatar_size">128dp</dimen>
     <dimen name="standard_padding">16dp</dimen>
     <dimen name="standard_double_padding">32dp</dimen>
@@ -116,6 +117,8 @@
     <dimen name="grid_image_shared_icon_layout_top_margin">24dp</dimen>
     <dimen name="grid_image_local_file_indicator_layout_width">16dp</dimen>
     <dimen name="grid_image_local_file_indicator_layout_height">16dp</dimen>
+    <dimen name="grid_image_icon_margin">14dp</dimen>
+    <dimen name="grid_image_icon_padding">14dp</dimen>
     <dimen name="grid_item_shared_icon_layout_top_margin">24dp</dimen>
     <dimen name="grid_item_local_file_indicator_layout_width">16dp</dimen>
     <dimen name="grid_item_local_file_indicator_layout_height">16dp</dimen>