Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-12 10:46:56 +01:00 committed by Alper Öztürk
parent 0a1336a10f
commit 19ac34e299
2 changed files with 63 additions and 72 deletions

View file

@ -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<RecyclerView.ViewHol
private final long footerId = UUID.randomUUID().getLeastSignificantBits();
private final long headerId = UUID.randomUUID().getLeastSignificantBits();
private final SyncedFolderProvider syncedFolderProvider;
public OCFileListAdapter(
Activity activity,
@ -172,9 +173,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
.get(activity)
.getUserData(this.user.toPlatformAccount(),
AccountUtils.Constants.KEY_USER_ID);
this.syncedFolderProvider = syncedFolderProvider;
this.viewThemeUtils = viewThemeUtils;
ocFileListDelegate = new OCFileListDelegate(FileUploadHelper.Companion.instance(),
activity,
ocFileListFragmentInterface,
@ -536,12 +536,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
}
ViewExtensionsKt.setVisibleIf(holder.getShared(), !file.isOfflineOperation());
if (file.isFolder()) {
setColorFilterForOfflineCreateFolderOperations(holder, file);
} else {
setColorFilterForOfflineCreateFileOperations(holder, file);
}
configureThumbnail(holder, file);
}
private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {
@ -651,75 +646,68 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
holder.getOverflowMenu().setImageResource(R.drawable.ic_dots_vertical);
}
applyVisualsForOfflineOperations(holder, file);
configureThumbnail(holder, file);
}
private void prepareFileSize(ListItemViewHolder holder, OCFile file, long size) {
holder.getFileSize().setVisibility(View.VISIBLE);
ViewExtensionsKt.setVisibleIf(holder.getFileSizeSeparator(), !file.isOfflineOperation());
String fileSizeText = getFileSizeText(file, size);
holder.getFileSize().setText(fileSizeText);
}
private String getFileSizeText(OCFile file, long size) {
OfflineOperationEntity entity = mStorageManager.getOfflineEntityFromOCFile(file);
boolean isRemoveOperation = entity != null && entity.getType() instanceof OfflineOperationType.RemoveFile;
if (!file.isOfflineOperation()) {
return DisplayUtils.bytesToHumanReadable(size);
}
OfflineOperationEntity entity = mStorageManager.getOfflineEntityFromOCFile(file);
boolean isRemoveOperation = (entity != null && entity.getType() instanceof OfflineOperationType.RemoveFile);
if (isRemoveOperation) {
return activity.getString(R.string.oc_file_list_adapter_offline_operation_remove_description_text);
}
if (file.isOfflineOperation()) {
return activity.getString(R.string.oc_file_list_adapter_offline_operation_description_text);
}
return DisplayUtils.bytesToHumanReadable(size);
}
private void applyVisualsForOfflineOperations(ListItemViewHolder holder, OCFile file) {
ViewExtensionsKt.setVisibleIf(holder.getShared(), !file.isOfflineOperation());
if (file.isFolder()) {
setColorFilterForOfflineCreateFolderOperations(holder, file);
} else {
setColorFilterForOfflineCreateFileOperations(holder, file);
}
return activity.getString(R.string.oc_file_list_adapter_offline_operation_description_text);
}
private final ExecutorService executorService = Executors.newCachedThreadPool();
private final Handler mainHandler = new Handler(Looper.getMainLooper());
private void setColorFilterForOfflineCreateFileOperations(ListViewHolder holder, OCFile file) {
if (!file.isOfflineOperation()) {
return;
}
private void configureThumbnail(ListViewHolder holder, OCFile file) {
final var context = MainApp.getAppContext();
executorService.execute(() -> {
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) {

View file

@ -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<Int, Int>? {
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
}
}