From 86b22f828a20fba18d771c322c112477b5fb85a1 Mon Sep 17 00:00:00 2001 From: Naveen Date: Tue, 16 Apr 2024 16:11:52 +0530 Subject: [PATCH] Reduce cross fade duration to 150ms --- .../org/fossify/gallery/extensions/Context.kt | 39 ++++++++++++++----- .../org/fossify/gallery/helpers/Constants.kt | 3 ++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/gallery/extensions/Context.kt b/app/src/main/kotlin/org/fossify/gallery/extensions/Context.kt index 94600b0bc..9438687f3 100644 --- a/app/src/main/kotlin/org/fossify/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/gallery/extensions/Context.kt @@ -1,5 +1,6 @@ package org.fossify.gallery.extensions +import android.annotation.SuppressLint import android.appwidget.AppWidgetManager import android.content.ComponentName import android.content.Context @@ -472,8 +473,15 @@ fun Context.getFolderNameFromPath(path: String): String { } fun Context.loadImage( - type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean, - roundCorners: Int, signature: ObjectKey, skipMemoryCacheAtPaths: ArrayList? = null + type: Int, + path: String, + target: MySquareImageView, + horizontalScroll: Boolean, + animateGifs: Boolean, + cropThumbnails: Boolean, + roundCorners: Int, + signature: ObjectKey, + skipMemoryCacheAtPaths: ArrayList? = null, ) { target.isHorizontalScrolling = horizontalScroll if (type == TYPE_SVGS) { @@ -505,6 +513,7 @@ fun Context.getPathLocation(path: String): Int { } } +@SuppressLint("CheckResult") fun Context.loadImageBase( path: String, target: MySquareImageView, @@ -514,7 +523,7 @@ fun Context.loadImageBase( skipMemoryCacheAtPaths: ArrayList? = null, animate: Boolean = false, tryLoadingWithPicasso: Boolean = false, - crossFadeDuration: Int = 300 + crossFadeDuration: Int = THUMBNAIL_FADE_DURATION_MS, ) { val options = RequestOptions() .signature(signature) @@ -572,7 +581,7 @@ fun Context.loadImageBase( model: Any, targetBitmap: Target, dataSource: DataSource, - isFirstResource: Boolean + isFirstResource: Boolean, ): Boolean { return false } @@ -582,7 +591,14 @@ fun Context.loadImageBase( builder.into(target) } -fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, signature: ObjectKey) { +fun Context.loadSVG( + path: String, + target: MySquareImageView, + cropThumbnails: Boolean, + roundCorners: Int, + signature: ObjectKey, + crossFadeDuration: Int = THUMBNAIL_FADE_DURATION_MS, +) { target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER val options = RequestOptions().signature(signature) @@ -591,7 +607,7 @@ fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boo .listener(SvgSoftwareLayerSetter()) .load(path) .apply(options) - .transition(DrawableTransitionOptions.withCrossFade()) + .transition(DrawableTransitionOptions.withCrossFade(crossFadeDuration)) if (roundCorners != ROUNDED_CORNERS_NONE) { val cornerSize = @@ -636,7 +652,7 @@ fun Context.getCachedDirectories( getImagesOnly: Boolean = false, forceShowHidden: Boolean = false, forceShowExcluded: Boolean = false, - callback: (ArrayList) -> Unit + callback: (ArrayList) -> Unit, ) { ensureBackgroundThread { try { @@ -988,8 +1004,13 @@ fun Context.addPathToDB(path: String) { } fun Context.createDirectoryFromMedia( - path: String, curMedia: ArrayList, albumCovers: ArrayList, hiddenString: String, - includedFolders: MutableSet, getProperFileSize: Boolean, noMediaFolders: ArrayList + path: String, + curMedia: ArrayList, + albumCovers: ArrayList, + hiddenString: String, + includedFolders: MutableSet, + getProperFileSize: Boolean, + noMediaFolders: ArrayList, ): Directory { val OTGPath = config.OTGPath val grouped = MediaFetcher(this).groupMedia(curMedia, path) diff --git a/app/src/main/kotlin/org/fossify/gallery/helpers/Constants.kt b/app/src/main/kotlin/org/fossify/gallery/helpers/Constants.kt index b8189eb78..ff34d5e78 100644 --- a/app/src/main/kotlin/org/fossify/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/org/fossify/gallery/helpers/Constants.kt @@ -245,6 +245,9 @@ const val FOLDER_MEDIA_CNT_NONE = 3 const val FOLDER_STYLE_SQUARE = 1 const val FOLDER_STYLE_ROUNDED_CORNERS = 2 +// animations +const val THUMBNAIL_FADE_DURATION_MS = 150 + fun getPermissionToRequest() = if (isTiramisuPlus()) PERMISSION_READ_MEDIA_IMAGES else PERMISSION_WRITE_STORAGE fun getRequiredPermission() = if (isUpsideDownCakePlus()) PERMISSION_READ_MEDIA_VISUAL_USER_SELECTED else getPermissionToRequest()