From 771e59b5cff759e8fa8ed6dfe485d712413685bc Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 20 Feb 2018 14:05:03 +0100 Subject: [PATCH] properly display OTG file thumbnails --- app/build.gradle | 2 +- .../gallery/adapters/MediaAdapter.kt | 15 +++++++++------ .../gallery/asynctasks/GetDirectoriesAsynctask.kt | 6 +++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d535e90f5..1a597b002 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.12.11' + implementation 'com.simplemobiletools:commons:3.12.12' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.2' implementation 'com.google.code.gson:gson:2.8.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 55b9269bc..35c22031d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -10,10 +10,7 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog -import com.simplemobiletools.commons.extensions.applyColorFilter -import com.simplemobiletools.commons.extensions.beVisibleIf -import com.simplemobiletools.commons.extensions.getFilenameFromPath -import com.simplemobiletools.commons.extensions.isActivityDestroyed +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView @@ -38,6 +35,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() + private val hasOTGConnected = activity.hasOTGConnected() private var scrollHorizontally = config.scrollHorizontally private var animateGifs = config.animateGifs @@ -290,15 +288,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, photo_name.text = medium.name photo_name.tag = medium.path + var thumbnailPath = medium.path + if (hasOTGConnected && activity.isPathOnOTG(thumbnailPath)) { + thumbnailPath = thumbnailPath.getOTGPublicPath(context) + } + if (loadImageInstantly) { - activity.loadImage(medium.type, medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) + activity.loadImage(medium.type, thumbnailPath, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) } else { medium_thumbnail.setImageDrawable(null) medium_thumbnail.isHorizontalScrolling = scrollHorizontally delayHandler.postDelayed({ val isVisible = visibleItemPaths.contains(medium.path) if (isVisible) { - activity.loadImage(medium.type, medium.path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) + activity.loadImage(medium.type, thumbnailPath, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) } }, IMAGE_LOAD_DELAY) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index d4b20cf2c..d1f86f01e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -39,8 +39,12 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val lastItem = curMedia.last() val parentDir = if (hasOTG && context.isPathOnOTG(firstItem.path)) firstItem.path.getParentPath() else File(firstItem.path).parent var thumbnail = firstItem.path + if (thumbnail.startsWith(OTG_PATH)) { + thumbnail = thumbnail.getOTGPublicPath(context) + } + albumCovers.forEach { - if (it.path == parentDir && File(it.tmb).exists()) { + if (it.path == parentDir && context.getDoesFilePathExist(it.tmb)) { thumbnail = it.tmb } }