fix thumbnail generating of OTG files

This commit is contained in:
tibbi 2019-03-28 09:51:10 +01:00
parent 521545191c
commit 307e10d713

View File

@ -49,6 +49,7 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
private lateinit var fileDrawable: Drawable private lateinit var fileDrawable: Drawable
private var currentItemsHash = listItems.hashCode() private var currentItemsHash = listItems.hashCode()
private var textToHighlight = "" private var textToHighlight = ""
private val hasOTGConnected = activity.hasOTGConnected()
var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() var adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
init { init {
@ -594,7 +595,7 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
.error(fileDrawable) .error(fileDrawable)
.centerCrop() .centerCrop()
val itemToLoad = if (listItem.name.endsWith(".apk", true)) { var itemToLoad = if (listItem.name.endsWith(".apk", true)) {
val packageInfo = context.packageManager.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES) val packageInfo = context.packageManager.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES)
if (packageInfo != null) { if (packageInfo != null) {
val appInfo = packageInfo.applicationInfo val appInfo = packageInfo.applicationInfo
@ -608,6 +609,11 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
path path
} }
if (hasOTGConnected && itemToLoad is String && activity.isPathOnOTG(itemToLoad) && baseConfig.OTGTreeUri.isNotEmpty() && baseConfig.OTGPartition.isNotEmpty()) {
itemToLoad = getOTGPublicPath(itemToLoad)
}
if (!activity.isDestroyed) { if (!activity.isDestroyed) {
Glide.with(activity).load(itemToLoad).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(item_icon) Glide.with(activity).load(itemToLoad).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(item_icon)
} }
@ -620,4 +626,6 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
val children = item.children val children = item.children
return activity.resources.getQuantityString(R.plurals.items, children, children) return activity.resources.getQuantityString(R.plurals.items, children, children)
} }
private fun getOTGPublicPath(itemToLoad: String) = "${baseConfig.OTGTreeUri}/document/${baseConfig.OTGPartition}%3A${itemToLoad.substring(baseConfig.OTGPath.length).replace("/", "%2F")}"
} }