浏览代码

wip after CR

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 2 年之前
父节点
当前提交
17d67a2078

+ 96 - 3
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt

@@ -22,8 +22,12 @@
 package com.owncloud.android.ui.adapter
 
 import android.content.Context
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.AsyncTask
 import android.view.View
 import android.widget.ImageView
+import androidx.core.content.res.ResourcesCompat
 import com.elyeproj.loaderviewlibrary.LoaderImageView
 import com.nextcloud.client.account.User
 import com.nextcloud.client.preferences.AppPreferences
@@ -31,13 +35,18 @@ import com.owncloud.android.R
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.ThumbnailsCacheManager
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncGalleryImageDrawable
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.GalleryImageGenerationTask
+import com.owncloud.android.datamodel.ThumbnailsCacheManager.GalleryImageGenerationTask.GalleryListener
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.ThumbnailGenerationTask
 import com.owncloud.android.lib.common.utils.Log_OC
 import com.owncloud.android.ui.activity.ComponentsGetter
 import com.owncloud.android.ui.fragment.SearchType
 import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
+import com.owncloud.android.utils.BitmapUtils
 import com.owncloud.android.utils.DisplayUtils
 import com.owncloud.android.utils.theme.ViewThemeUtils
+import com.owncloud.android.utils.MimeTypeUtil
 
 @Suppress("LongParameterList", "TooManyFunctions")
 class OCFileListDelegate(
@@ -100,16 +109,14 @@ class OCFileListDelegate(
     ) {
         // thumbnail
         imageView.tag = file.fileId
-        DisplayUtils.setGalleryImage(
+        setGalleryImage(
             file,
             imageView,
             user,
             storageManager,
             asyncGalleryTasks,
-            gridView,
             context,
             shimmer,
-            preferences,
             themeColorUtils,
             themeDrawableUtils,
             galleryRowHolder,
@@ -119,6 +126,92 @@ class OCFileListDelegate(
         imageView.setOnClickListener { ocFileListFragmentInterface.onItemClicked(file) }
     }
 
+    @Suppress("ComplexMethod")
+    private fun setGalleryImage(
+        file: OCFile,
+        thumbnailView: ImageView,
+        user: User?,
+        storageManager: FileDataStorageManager?,
+        asyncTasks: MutableList<GalleryImageGenerationTask>,
+        context: Context,
+        shimmerThumbnail: LoaderImageView?,
+        themeColorUtils: ThemeColorUtils?,
+        themeDrawableUtils: ThemeDrawableUtils?,
+        galleryRowHolder: GalleryRowHolder,
+        width: Int
+    ) {
+        // cancel previous generation, if view is re-used
+        if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
+            for (task in asyncTasks) {
+                if (file.remoteId != null && task.imageKey != null && file.remoteId == task.imageKey) {
+                    return
+                }
+            }
+            try {
+                val task = GalleryImageGenerationTask(
+                    thumbnailView,
+                    user,
+                    storageManager,
+                    asyncTasks,
+                    file.remoteId,
+                    context.resources.getColor(R.color.bg_default)
+                )
+                var drawable = MimeTypeUtil.getFileTypeIcon(
+                    file.mimeType,
+                    file.fileName,
+                    user,
+                    context,
+                    themeColorUtils,
+                    themeDrawableUtils
+                )
+                if (drawable == null) {
+                    drawable = ResourcesCompat.getDrawable(
+                        context.resources,
+                        R.drawable.file_image,
+                        null
+                    )
+                }
+                if (drawable == null) {
+                    drawable = ColorDrawable(Color.GRAY)
+                }
+                val thumbnail = BitmapUtils.drawableToBitmap(drawable, width / 2, width / 2)
+                val asyncDrawable = AsyncGalleryImageDrawable(
+                    context.resources,
+                    thumbnail,
+                    task
+                )
+                if (shimmerThumbnail != null) {
+                    Log_OC.d("Shimmer", "start Shimmer")
+                    DisplayUtils.startShimmer(shimmerThumbnail, thumbnailView)
+                }
+                task.setListener(object : GalleryListener {
+                    override fun onSuccess() {
+                        galleryRowHolder.binding.rowLayout.invalidate()
+                        Log_OC.d("Shimmer", "stop Shimmer")
+                        DisplayUtils.stopShimmer(shimmerThumbnail, thumbnailView)
+                    }
+
+                    override fun onNewGalleryImage() {
+                        galleryRowHolder.redraw()
+                    }
+
+                    override fun onError() {
+                        Log_OC.d("Shimmer", "stop Shimmer")
+                        DisplayUtils.stopShimmer(shimmerThumbnail, thumbnailView)
+                    }
+                })
+                thumbnailView.setImageDrawable(asyncDrawable)
+                asyncTasks.add(task)
+                task.executeOnExecutor(
+                    AsyncTask.THREAD_POOL_EXECUTOR,
+                    file
+                )
+            } catch (e: IllegalArgumentException) {
+                Log_OC.d(this, "ThumbnailGenerationTask : " + e.message)
+            }
+        }
+    }
+
     fun bindGridViewHolder(
         gridViewHolder: ListGridImageViewHolder,
         file: OCFile,

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java

@@ -266,7 +266,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
 
         startDate = endDate - (daySpan * 24 * 60 * 60);
 
-        // runGallerySearchTask();
+        runGallerySearchTask();
     }
 
     @Override

+ 2 - 92
app/src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -76,7 +76,6 @@ import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.TextDrawable;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
-import com.owncloud.android.ui.adapter.GalleryRowHolder;
 import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
 import com.owncloud.android.ui.events.SearchEvent;
 import com.owncloud.android.ui.fragment.OCFileListFragment;
@@ -836,95 +835,6 @@ public final class DisplayUtils {
         return df.format(timestamp);
     }
 
-    public static void setGalleryImage(OCFile file,
-                                       ImageView thumbnailView,
-                                       User user,
-                                       FileDataStorageManager storageManager,
-                                       List<ThumbnailsCacheManager.GalleryImageGenerationTask> asyncTasks,
-                                       boolean gridView,
-                                       Context context,
-                                       LoaderImageView shimmerThumbnail,
-                                       AppPreferences preferences,
-                                       ThemeColorUtils themeColorUtils,
-                                       ThemeDrawableUtils themeDrawableUtils,
-                                       GalleryRowHolder galleryRowHolder,
-                                       Integer width) {
-
-        // cancel previous generation, if view is re-used
-        if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
-            for (ThumbnailsCacheManager.GalleryImageGenerationTask task : asyncTasks) {
-                if (file.getRemoteId() != null && task.getImageKey() != null &&
-                    file.getRemoteId().equals(task.getImageKey())) {
-                    return;
-                }
-            }
-            try {
-                final ThumbnailsCacheManager.GalleryImageGenerationTask task =
-                    new ThumbnailsCacheManager.GalleryImageGenerationTask(
-                        thumbnailView,
-                        user,
-                        storageManager,
-                        asyncTasks,
-                        file.getRemoteId(),
-                        context.getResources().getColor(R.color.bg_default));
-                Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
-                                                                 file.getFileName(),
-                                                                 user,
-                                                                 context,
-                                                                 themeColorUtils,
-                                                                 themeDrawableUtils);
-                if (drawable == null) {
-                    drawable = ResourcesCompat.getDrawable(context.getResources(),
-                                                           R.drawable.file_image,
-                                                           null);
-                }
-
-                if (drawable == null) {
-                    drawable = new ColorDrawable(Color.GRAY);
-                }
-
-                Bitmap thumbnail = BitmapUtils.drawableToBitmap(drawable, width / 2, width / 2);
-
-                final ThumbnailsCacheManager.AsyncGalleryImageDrawable asyncDrawable =
-                    new ThumbnailsCacheManager.AsyncGalleryImageDrawable(context.getResources(),
-                                                                         thumbnail,
-                                                                         task);
-
-                if (shimmerThumbnail != null) {
-                    Log_OC.d("Shimmer", "start Shimmer");
-                    startShimmer(shimmerThumbnail, thumbnailView);
-                }
-
-                task.setListener(new ThumbnailsCacheManager.GalleryImageGenerationTask.GalleryListener() {
-                    @Override
-                    public void onSuccess() {
-                        galleryRowHolder.getBinding().rowLayout.invalidate();
-                        Log_OC.d("Shimmer", "stop Shimmer");
-                        stopShimmer(shimmerThumbnail, thumbnailView);
-                    }
-
-                    @Override
-                    public void onNewGalleryImage() {
-                        galleryRowHolder.redraw();
-                    }
-
-                    @Override
-                    public void onError() {
-                        Log_OC.d("Shimmer", "stop Shimmer");
-                        stopShimmer(shimmerThumbnail, thumbnailView);
-                    }
-                });
-
-                thumbnailView.setImageDrawable(asyncDrawable);
-                asyncTasks.add(task);
-                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
-                                       file);
-            } catch (IllegalArgumentException e) {
-                Log_OC.d(TAG, "ThumbnailGenerationTask : " + e.getMessage());
-            }
-        }
-    }
-
     public static void setThumbnail(OCFile file,
                                     ImageView thumbnailView,
                                     User user,
@@ -1046,14 +956,14 @@ public final class DisplayUtils {
         }
     }
 
-    private static void startShimmer(LoaderImageView thumbnailShimmer, ImageView thumbnailView) {
+    public static void startShimmer(LoaderImageView thumbnailShimmer, ImageView thumbnailView) {
         thumbnailShimmer.setImageResource(R.drawable.background);
         thumbnailShimmer.resetLoader();
         thumbnailView.setVisibility(View.GONE);
         thumbnailShimmer.setVisibility(View.VISIBLE);
     }
 
-    private static void stopShimmer(@Nullable LoaderImageView thumbnailShimmer, ImageView thumbnailView) {
+    public static void stopShimmer(@Nullable LoaderImageView thumbnailShimmer, ImageView thumbnailView) {
         if (thumbnailShimmer != null) {
             thumbnailShimmer.setVisibility(View.GONE);
         }

+ 2 - 3
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,5 @@
-#Wed Oct 12 12:37:36 CEST 2022
 distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
 distributionPath=wrapper/dists
-zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
 zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists