mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 07:52:18 +03:00
fix
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
0a1336a10f
commit
19ac34e299
2 changed files with 63 additions and 72 deletions
|
@ -18,7 +18,6 @@ import android.content.ContentValues;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
@ -97,6 +96,7 @@ import java.util.stream.Collectors;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import me.zhanghai.android.fastscroll.PopupTextProvider;
|
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 footerId = UUID.randomUUID().getLeastSignificantBits();
|
||||||
private final long headerId = UUID.randomUUID().getLeastSignificantBits();
|
private final long headerId = UUID.randomUUID().getLeastSignificantBits();
|
||||||
|
private final SyncedFolderProvider syncedFolderProvider;
|
||||||
|
|
||||||
public OCFileListAdapter(
|
public OCFileListAdapter(
|
||||||
Activity activity,
|
Activity activity,
|
||||||
|
@ -172,9 +173,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||||
.get(activity)
|
.get(activity)
|
||||||
.getUserData(this.user.toPlatformAccount(),
|
.getUserData(this.user.toPlatformAccount(),
|
||||||
AccountUtils.Constants.KEY_USER_ID);
|
AccountUtils.Constants.KEY_USER_ID);
|
||||||
|
this.syncedFolderProvider = syncedFolderProvider;
|
||||||
this.viewThemeUtils = viewThemeUtils;
|
this.viewThemeUtils = viewThemeUtils;
|
||||||
|
|
||||||
ocFileListDelegate = new OCFileListDelegate(FileUploadHelper.Companion.instance(),
|
ocFileListDelegate = new OCFileListDelegate(FileUploadHelper.Companion.instance(),
|
||||||
activity,
|
activity,
|
||||||
ocFileListFragmentInterface,
|
ocFileListFragmentInterface,
|
||||||
|
@ -536,12 +536,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewExtensionsKt.setVisibleIf(holder.getShared(), !file.isOfflineOperation());
|
configureThumbnail(holder, file);
|
||||||
if (file.isFolder()) {
|
|
||||||
setColorFilterForOfflineCreateFolderOperations(holder, file);
|
|
||||||
} else {
|
|
||||||
setColorFilterForOfflineCreateFileOperations(holder, file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindListItemViewHolder(ListItemViewHolder holder, OCFile 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);
|
holder.getOverflowMenu().setImageResource(R.drawable.ic_dots_vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyVisualsForOfflineOperations(holder, file);
|
configureThumbnail(holder, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareFileSize(ListItemViewHolder holder, OCFile file, long size) {
|
private void prepareFileSize(ListItemViewHolder holder, OCFile file, long size) {
|
||||||
holder.getFileSize().setVisibility(View.VISIBLE);
|
holder.getFileSize().setVisibility(View.VISIBLE);
|
||||||
ViewExtensionsKt.setVisibleIf(holder.getFileSizeSeparator(), !file.isOfflineOperation());
|
|
||||||
String fileSizeText = getFileSizeText(file, size);
|
String fileSizeText = getFileSizeText(file, size);
|
||||||
holder.getFileSize().setText(fileSizeText);
|
holder.getFileSize().setText(fileSizeText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFileSizeText(OCFile file, long size) {
|
private String getFileSizeText(OCFile file, long size) {
|
||||||
OfflineOperationEntity entity = mStorageManager.getOfflineEntityFromOCFile(file);
|
if (!file.isOfflineOperation()) {
|
||||||
boolean isRemoveOperation = entity != null && entity.getType() instanceof OfflineOperationType.RemoveFile;
|
return DisplayUtils.bytesToHumanReadable(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
OfflineOperationEntity entity = mStorageManager.getOfflineEntityFromOCFile(file);
|
||||||
|
boolean isRemoveOperation = (entity != null && entity.getType() instanceof OfflineOperationType.RemoveFile);
|
||||||
if (isRemoveOperation) {
|
if (isRemoveOperation) {
|
||||||
return activity.getString(R.string.oc_file_list_adapter_offline_operation_remove_description_text);
|
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 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ExecutorService executorService = Executors.newCachedThreadPool();
|
private final ExecutorService executorService = Executors.newCachedThreadPool();
|
||||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
private void setColorFilterForOfflineCreateFileOperations(ListViewHolder holder, OCFile file) {
|
private void configureThumbnail(ListViewHolder holder, OCFile file) {
|
||||||
if (!file.isOfflineOperation()) {
|
final var context = MainApp.getAppContext();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
executorService.execute(() -> {
|
if (file.isOfflineOperation()) {
|
||||||
OfflineOperationEntity entity = mStorageManager.offlineOperationDao.getByPath(file.getDecryptedRemotePath());
|
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) {
|
if (entity != null && entity.getType() != null && entity.getType() instanceof OfflineOperationType.CreateFile createFileOperation) {
|
||||||
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(createFileOperation.getLocalPath(), holder.getThumbnail().getWidth(), holder.getThumbnail().getHeight());
|
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(createFileOperation.getLocalPath(), holder.getThumbnail().getWidth(), holder.getThumbnail().getHeight());
|
||||||
if (bitmap == null) return;
|
if (bitmap == null) return;
|
||||||
|
|
||||||
Bitmap thumbnail = BitmapUtils.addColorFilter(bitmap, Color.GRAY,100);
|
Bitmap thumbnail = BitmapUtils.addColorFilter(bitmap, Color.GRAY,100);
|
||||||
mainHandler.post(() -> holder.getThumbnail().setImageBitmap(thumbnail));
|
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() {
|
public void onDestroy() {
|
||||||
executorService.shutdown();
|
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
|
@Override
|
||||||
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
if (holder instanceof ListViewHolder) {
|
if (holder instanceof ListViewHolder) {
|
||||||
|
|
|
@ -250,7 +250,7 @@ class OCFileListDelegate(
|
||||||
if (shouldHideShare) {
|
if (shouldHideShare) {
|
||||||
gridViewHolder.shared.visibility = View.GONE
|
gridViewHolder.shared.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
showShareIcon(gridViewHolder, file)
|
configureSharedIconView(gridViewHolder, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,34 +367,37 @@ class OCFileListDelegate(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showShareIcon(gridViewHolder: ListViewHolder, file: OCFile) {
|
private fun configureSharedIconView(gridViewHolder: ListViewHolder, file: OCFile) {
|
||||||
val sharedIconView = gridViewHolder.shared
|
val result = getShareIconIdAndContentDescriptionId(gridViewHolder, file)
|
||||||
|
|
||||||
if (!MDMConfig.sharingSupport(context)) {
|
gridViewHolder.shared.run {
|
||||||
sharedIconView.visibility = View.GONE
|
if (result == null) {
|
||||||
return
|
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) {
|
return if (file.isSharedWithSharee || file.isSharedWithMe) {
|
||||||
sharedIconView.visibility = View.VISIBLE
|
if (showShareAvatar) {
|
||||||
if (file.isSharedWithSharee || file.isSharedWithMe) {
|
null
|
||||||
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)
|
|
||||||
} else {
|
} else {
|
||||||
sharedIconView.setImageResource(R.drawable.ic_unshared)
|
R.drawable.shared_via_users to R.string.shared_icon_shared
|
||||||
sharedIconView.contentDescription = context.getString(R.string.shared_icon_share)
|
|
||||||
}
|
}
|
||||||
sharedIconView.setOnClickListener { ocFileListFragmentInterface.onShareIconClick(file) }
|
} else if (file.isSharedViaLink) {
|
||||||
|
R.drawable.shared_via_link to R.string.shared_icon_shared_via_link
|
||||||
} else {
|
} else {
|
||||||
sharedIconView.visibility = View.GONE
|
R.drawable.ic_unshared to R.string.shared_icon_share
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue