properly display OTG file thumbnails

This commit is contained in:
tibbi 2018-02-20 14:05:03 +01:00
parent 55fa9a04d5
commit 771e59b5cf
3 changed files with 15 additions and 8 deletions

View file

@ -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'

View file

@ -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<Medium>,
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<Medium>,
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)
}

View file

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