From 19ac34e2993718f06d9840ad8394129f441b5db6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 12 Nov 2024 10:46:56 +0100 Subject: [PATCH] fix Signed-off-by: alperozturk --- .../android/ui/adapter/OCFileListAdapter.java | 86 ++++++++----------- .../android/ui/adapter/OCFileListDelegate.kt | 49 ++++++----- 2 files changed, 63 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 8725dd6ac5..4e9bc9bd1d 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -18,7 +18,6 @@ import android.content.ContentValues; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; -import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Handler; @@ -97,6 +96,7 @@ import java.util.stream.Collectors; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import me.zhanghai.android.fastscroll.PopupTextProvider; @@ -141,6 +141,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter { - OfflineOperationEntity entity = mStorageManager.offlineOperationDao.getByPath(file.getDecryptedRemotePath()); + if (file.isOfflineOperation()) { + if (file.isFolder()) { + Drawable icon = ContextCompat.getDrawable(context, R.drawable.ic_folder_offline); + holder.getThumbnail().setImageDrawable(icon); + } else { + executorService.execute(() -> { + OfflineOperationEntity entity = mStorageManager.offlineOperationDao.getByPath(file.getDecryptedRemotePath()); - if (entity != null && entity.getType() != null && entity.getType() instanceof OfflineOperationType.CreateFile createFileOperation) { - Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(createFileOperation.getLocalPath(), holder.getThumbnail().getWidth(), holder.getThumbnail().getHeight()); - if (bitmap == null) return; + if (entity != null && entity.getType() != null && entity.getType() instanceof OfflineOperationType.CreateFile createFileOperation) { + Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(createFileOperation.getLocalPath(), holder.getThumbnail().getWidth(), holder.getThumbnail().getHeight()); + if (bitmap == null) return; - Bitmap thumbnail = BitmapUtils.addColorFilter(bitmap, Color.GRAY,100); - mainHandler.post(() -> holder.getThumbnail().setImageBitmap(thumbnail)); + Bitmap thumbnail = BitmapUtils.addColorFilter(bitmap, Color.GRAY,100); + mainHandler.post(() -> holder.getThumbnail().setImageBitmap(thumbnail)); + } + }); } - }); + } else { + boolean isAutoUpload = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, user); + boolean isDarkModeActive = preferences.isDarkModeEnabled(); + Drawable icon = MimeTypeUtil.getOCFileIcon(file, context, viewThemeUtils, isAutoUpload, isDarkModeActive); + holder.getThumbnail().setImageDrawable(icon); + + if (!file.isFolder()) { + ViewExtensionsKt.makeRounded(holder.getThumbnail(), context, 4); + } + } } public void onDestroy() { executorService.shutdown(); } - private void setColorFilterForOfflineCreateFolderOperations(ListViewHolder holder, OCFile file) { - if (file.isOfflineOperation()) { - holder.getThumbnail().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN); - } else { - Drawable drawable = viewThemeUtils.platform.tintDrawable(MainApp.getAppContext(), holder.getThumbnail().getDrawable(), ColorRole.PRIMARY); - holder.getThumbnail().setImageDrawable(drawable); - } - } - @Override public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof ListViewHolder) { diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt index a81f92b5d5..cd74ec3e47 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt @@ -250,7 +250,7 @@ class OCFileListDelegate( if (shouldHideShare) { gridViewHolder.shared.visibility = View.GONE } else { - showShareIcon(gridViewHolder, file) + configureSharedIconView(gridViewHolder, file) } } @@ -367,34 +367,37 @@ class OCFileListDelegate( } } - private fun showShareIcon(gridViewHolder: ListViewHolder, file: OCFile) { - val sharedIconView = gridViewHolder.shared + private fun configureSharedIconView(gridViewHolder: ListViewHolder, file: OCFile) { + val result = getShareIconIdAndContentDescriptionId(gridViewHolder, file) - if (!MDMConfig.sharingSupport(context)) { - sharedIconView.visibility = View.GONE - return + gridViewHolder.shared.run { + if (result == null) { + visibility = View.GONE + return + } + + setImageResource(result.first) + contentDescription = context.getString(result.second) + visibility = View.VISIBLE + setOnClickListener { ocFileListFragmentInterface.onShareIconClick(file) } + } + } + + private fun getShareIconIdAndContentDescriptionId(holder: ListViewHolder, file: OCFile): Pair? { + if (!MDMConfig.sharingSupport(context) || file.isOfflineOperation || holder !is OCFileListItemViewHolder || file.unreadCommentsCount != 0) { + return null } - if (gridViewHolder is OCFileListItemViewHolder || file.unreadCommentsCount == 0) { - sharedIconView.visibility = View.VISIBLE - if (file.isSharedWithSharee || file.isSharedWithMe) { - if (showShareAvatar) { - sharedIconView.visibility = View.GONE - } else { - sharedIconView.visibility = View.VISIBLE - sharedIconView.setImageResource(R.drawable.shared_via_users) - sharedIconView.contentDescription = context.getString(R.string.shared_icon_shared) - } - } else if (file.isSharedViaLink) { - sharedIconView.setImageResource(R.drawable.shared_via_link) - sharedIconView.contentDescription = context.getString(R.string.shared_icon_shared_via_link) + return if (file.isSharedWithSharee || file.isSharedWithMe) { + if (showShareAvatar) { + null } else { - sharedIconView.setImageResource(R.drawable.ic_unshared) - sharedIconView.contentDescription = context.getString(R.string.shared_icon_share) + R.drawable.shared_via_users to R.string.shared_icon_shared } - sharedIconView.setOnClickListener { ocFileListFragmentInterface.onShareIconClick(file) } + } else if (file.isSharedViaLink) { + R.drawable.shared_via_link to R.string.shared_icon_shared_via_link } else { - sharedIconView.visibility = View.GONE + R.drawable.ic_unshared to R.string.shared_icon_share } }