|
@@ -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) {
|