Skip to content

Commit

Permalink
Merge pull request #14030 from nextcloud/bugfix/icon-visibilities
Browse files Browse the repository at this point in the history
BugFix - Icon Visibilities
  • Loading branch information
tobiasKaminsky authored Nov 25, 2024
2 parents 287203e + c0b3ec8 commit d4b4689
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 109 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
sut.storageManager.saveFile(this)
}

OCFile("/offlineOperation/").apply {
mimeType = MimeType.DIRECTORY
decryptedRemotePath = "/offlineOperation/"
modificationTimestamp = System.currentTimeMillis()
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
sut.storageManager.saveFile(this)
}

sut.addFragment(fragment)

shortSleep()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.After
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test

class DrawableUtilTests {

private var sut: DrawableUtil? = null
private var context: Context? = null

@Before
fun setUp() {
sut = DrawableUtil()
context = InstrumentationRegistry.getInstrumentation().context
}

Expand All @@ -32,18 +29,13 @@ class DrawableUtilTests {
val bitmap: Bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888)
val drawable = BitmapDrawable(context?.resources, bitmap)

val layerDrawable = sut?.addDrawableAsOverlay(drawable, drawable)
val layerDrawable = DrawableUtil.addDrawableAsOverlay(drawable, drawable)

if (layerDrawable == null) {
fail("Layer drawable expected to be not null")
}

assert(layerDrawable?.numberOfLayers == 2)
assert(layerDrawable.numberOfLayers == 2)
}

@After
fun destroy() {
sut = null
context = null
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/utils/ShortcutUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ShortcutUtil @Inject constructor(private val mContext: Context) {
val isDarkModeActive = syncedFolderProvider.preferences.isDarkModeEnabled

val overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder)
val drawable = MimeTypeUtil.getFileIcon(isDarkModeActive, overlayIconId, mContext, viewThemeUtils)
val drawable = MimeTypeUtil.getFolderIcon(isDarkModeActive, overlayIconId, mContext, viewThemeUtils)
val bitmapIcon = drawable.toBitmap()
icon = IconCompat.createWithBitmap(bitmapIcon)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ fun View?.setVisibleIf(condition: Boolean) {
visibility = if (condition) View.VISIBLE else View.GONE
}

fun View?.makeRounded(context: Context, cornerRadius: Float) {
this?.let {
it.apply {
outlineProvider = createRoundedOutline(context, cornerRadius)
clipToOutline = true
}
}
}

fun createRoundedOutline(context: Context, cornerRadiusValue: Float): ViewOutlineProvider {
return object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected void setThumbnailView(final User user) {
boolean isAutoUploadFolder = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, user);

Integer overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder);
LayerDrawable drawable = MimeTypeUtil.getFileIcon(preferences.isDarkModeEnabled(), overlayIconId, this, viewThemeUtils);
LayerDrawable drawable = MimeTypeUtil.getFolderIcon(preferences.isDarkModeEnabled(), overlayIconId, this, viewThemeUtils);
binding.thumbnail.setImageDrawable(drawable);
} else {
if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) && file.getRemoteId() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {
boolean isAutoUploadFolder = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, optionalUser.get());

Integer overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder);
LayerDrawable drawable = MimeTypeUtil.getFileIcon(preferences.isDarkModeEnabled(), overlayIconId, this, viewThemeUtils);
LayerDrawable drawable = MimeTypeUtil.getFolderIcon(preferences.isDarkModeEnabled(), overlayIconId, this, viewThemeUtils);
binding.shareFileIcon.setImageDrawable(drawable);
} else {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GroupfolderListAdapter(

private fun getFolderIcon(): LayerDrawable? {
val overlayDrawableId = R.drawable.ic_folder_overlay_account_group
return MimeTypeUtil.getFileIcon(false, overlayDrawableId, context, viewThemeUtils)
return MimeTypeUtil.getFolderIcon(false, overlayDrawableId, context, viewThemeUtils)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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;
Expand Down Expand Up @@ -97,6 +96,7 @@
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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -172,9 +173,8 @@ public OCFileListAdapter(
.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,
Expand Down Expand Up @@ -536,12 +536,7 @@ private void bindListGridItemViewHolder(ListGridItemViewHolder holder, OCFile fi
}
}

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) {
Expand Down Expand Up @@ -651,75 +646,68 @@ private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.nextcloud.client.account.User
import com.nextcloud.client.jobs.download.FileDownloadHelper
import com.nextcloud.client.jobs.upload.FileUploadHelper
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.utils.extensions.createRoundedOutline
import com.nextcloud.utils.extensions.makeRounded
import com.nextcloud.utils.mdm.MDMConfig
import com.owncloud.android.R
import com.owncloud.android.datamodel.FileDataStorageManager
Expand Down Expand Up @@ -250,7 +250,7 @@ class OCFileListDelegate(
if (shouldHideShare) {
gridViewHolder.shared.visibility = View.GONE
} else {
showShareIcon(gridViewHolder, file)
configureSharedIconView(gridViewHolder, file)
}
}

Expand Down Expand Up @@ -307,9 +307,8 @@ class OCFileListDelegate(
R.color.bg_default
}

gridViewHolder.itemLayout.apply {
outlineProvider = createRoundedOutline(context, cornerRadius)
clipToOutline = true
gridViewHolder.itemLayout.run {
makeRounded(context, cornerRadius)
setBackgroundColor(ContextCompat.getColor(context, itemLayoutBackgroundColorId))
}
}
Expand Down Expand Up @@ -367,34 +366,38 @@ 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)

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) }
}
}

@Suppress("ReturnCount")
private fun getShareIconIdAndContentDescriptionId(holder: ListViewHolder, file: OCFile): Pair<Int, Int>? {
if (!MDMConfig.sharingSupport(context)) {
sharedIconView.visibility = View.GONE
return
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)
} else {
sharedIconView.setImageResource(R.drawable.ic_unshared)
sharedIconView.contentDescription = context.getString(R.string.shared_icon_share)
if (file.isOfflineOperation) return null

if (holder !is OCFileListItemViewHolder && file.unreadCommentsCount != 0) return null

return when {
file.isSharedWithSharee || file.isSharedWithMe -> {
if (showShareAvatar) null else R.drawable.shared_via_users to R.string.shared_icon_shared
}
sharedIconView.setOnClickListener { ocFileListFragmentInterface.onShareIconClick(file) }
} else {
sharedIconView.visibility = View.GONE
file.isSharedViaLink -> R.drawable.shared_via_link to R.string.shared_icon_shared_via_link
else -> R.drawable.ic_unshared to R.string.shared_icon_share
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ReceiveExternalFilesAdapter(
val isAutoUploadFolder = SyncedFolderProvider.isAutoUploadFolder(syncedFolderProvider, file, user)
val isDarkModeActive = syncedFolderProvider.preferences.isDarkModeEnabled
val overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder)
val icon = MimeTypeUtil.getFileIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils)
val icon = MimeTypeUtil.getFolderIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils)
thumbnailImageView.setImageDrawable(icon)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ public static void setThumbnail(OCFile file,
boolean isDarkModeActive = preferences.isDarkModeEnabled();

Integer overlayIconId = file.getFileOverlayIconId(isAutoUploadFolder);
LayerDrawable fileIcon = MimeTypeUtil.getFileIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils);
LayerDrawable fileIcon = MimeTypeUtil.getFolderIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils);
thumbnailView.setImageDrawable(fileIcon);
} else {
if (file.getRemoteId() != null && file.isPreviewAvailable()) {
Expand Down
Loading

0 comments on commit d4b4689

Please sign in to comment.