removing some code related to OTG file special handling

This commit is contained in:
tibbi 2019-02-15 20:47:33 +01:00
parent 3624091994
commit 574c3138c9
4 changed files with 13 additions and 93 deletions

View file

@ -455,11 +455,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
medium_check?.background?.applyColorFilter(primaryColor) medium_check?.background?.applyColorFilter(primaryColor)
} }
var path = medium.path val path = medium.path
if (hasOTGConnected && context.isPathOnOTG(path)) {
path = path.getOTGPublicPath(context)
}
if (loadImageInstantly) { if (loadImageInstantly) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, rotatedImagePaths) activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, rotatedImagePaths)
} else { } else {

View file

@ -325,11 +325,11 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadGif() { private fun loadGif() {
try { try {
val pathToLoad = getPathToLoad(mMedium) val path = mMedium.path
val source = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { val source = if (path.startsWith("content://") || path.startsWith("file://")) {
InputSource.UriSource(context!!.contentResolver, Uri.parse(pathToLoad)) InputSource.UriSource(context!!.contentResolver, Uri.parse(path))
} else { } else {
InputSource.FileSource(pathToLoad) InputSource.FileSource(path)
} }
mView.apply { mView.apply {
@ -365,7 +365,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
Glide.with(context!!) Glide.with(context!!)
.load(getPathToLoad(mMedium)) .load(mMedium.path)
.apply(options) .apply(options)
.listener(object : RequestListener<Drawable> { .listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
@ -433,11 +433,10 @@ class PhotoFragment : ViewPagerFragment() {
private fun addZoomableView() { private fun addZoomableView() {
val rotation = degreesForRotation(mImageOrientation) val rotation = degreesForRotation(mImageOrientation)
val path = getPathToLoad(mMedium)
mIsSubsamplingVisible = true mIsSubsamplingVisible = true
val bitmapDecoder = object : DecoderFactory<ImageDecoder> { val bitmapDecoder = object : DecoderFactory<ImageDecoder> {
override fun make() = PicassoDecoder(path, Picasso.get(), rotation) override fun make() = PicassoDecoder(mMedium.path, Picasso.get(), rotation)
} }
val regionDecoder = object : DecoderFactory<ImageRegionDecoder> { val regionDecoder = object : DecoderFactory<ImageRegionDecoder> {
@ -461,7 +460,7 @@ class PhotoFragment : ViewPagerFragment() {
rotationEnabled = config.allowRotatingWithGestures rotationEnabled = config.allowRotatingWithGestures
isOneToOneZoomEnabled = config.allowOneToOneZoom isOneToOneZoomEnabled = config.allowOneToOneZoom
orientation = newOrientation orientation = newOrientation
setImage(path) setImage(mMedium.path)
onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener { onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener {
override fun onReady() { override fun onReady() {
background = ColorDrawable(if (config.blackBackground) Color.BLACK else config.backgroundColor) background = ColorDrawable(if (config.blackBackground) Color.BLACK else config.backgroundColor)
@ -524,12 +523,12 @@ class PhotoFragment : ViewPagerFragment() {
var orient = defaultOrientation var orient = defaultOrientation
try { try {
val pathToLoad = getPathToLoad(mMedium) val path = mMedium.path
val exif = android.media.ExifInterface(pathToLoad) val exif = android.media.ExifInterface(path)
orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation)
if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) { if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) {
val uri = if (pathToLoad.startsWith("content:/")) Uri.parse(pathToLoad) else Uri.fromFile(File(pathToLoad)) val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path))
val inputStream = context!!.contentResolver.openInputStream(uri) val inputStream = context!!.contentResolver.openInputStream(uri)
val exif2 = ExifInterface() val exif2 = ExifInterface()
exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL) exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL)

View file

@ -76,8 +76,6 @@ abstract class ViewPagerFragment : Fragment() {
return details.toString().trim() return details.toString().trim()
} }
fun getPathToLoad(medium: Medium) = medium.path //if (context!!.isPathOnOTG(medium.path)) medium.path.getOTGPublicPath(context!!) else medium.path
private fun getFileLastModified(file: File): String { private fun getFileLastModified(file: File): String {
val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED) val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED)
val uri = MediaStore.Files.getContentUri("external") val uri = MediaStore.Files.getContentUri("external")

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.pro.helpers
import android.content.Context import android.content.Context
import android.database.Cursor import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore import android.provider.MediaStore
import android.text.format.DateFormat import android.text.format.DateFormat
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
@ -26,15 +25,8 @@ class MediaFetcher(val context: Context) {
} }
val curMedia = ArrayList<Medium>() val curMedia = ArrayList<Medium>()
if (context.isPathOnOTG(curPath)) { val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, favoritePaths, getVideoDurations)
if (context.hasOTGConnected()) { curMedia.addAll(newMedia)
val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia, favoritePaths, getVideoDurations)
curMedia.addAll(newMedia)
}
} else {
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, favoritePaths, getVideoDurations)
curMedia.addAll(newMedia)
}
if (sortMedia) { if (sortMedia) {
sortMedia(curMedia, context.config.getFileSorting(curPath)) sortMedia(curMedia, context.config.getFileSorting(curPath))
@ -259,71 +251,6 @@ class MediaFetcher(val context: Context) {
return media return media
} }
private fun getMediaOnOTG(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, favoritePaths: ArrayList<String>,
getVideoDurations: Boolean): ArrayList<Medium> {
val media = ArrayList<Medium>()
val files = context.getDocumentFile(folder)?.listFiles() ?: return media
val doExtraCheck = context.config.doExtraCheck
val showHidden = context.config.shouldShowHidden
for (file in files) {
if (shouldStop) {
break
}
val filename = file.name ?: continue
val isImage = filename.isImageFast()
val isVideo = if (isImage) false else filename.isVideoFast()
val isGif = if (isImage || isVideo) false else filename.isGif()
val isRaw = if (isImage || isVideo || isGif) false else filename.isRawFast()
val isSvg = if (isImage || isVideo || isGif || isRaw) false else filename.isSvg()
if (!isImage && !isVideo && !isGif && !isRaw && !isSvg)
continue
if (isVideo && (isPickImage || filterMedia and TYPE_VIDEOS == 0))
continue
if (isImage && (isPickVideo || filterMedia and TYPE_IMAGES == 0))
continue
if (isGif && filterMedia and TYPE_GIFS == 0)
continue
if (isRaw && filterMedia and TYPE_RAWS == 0)
continue
if (isSvg && filterMedia and TYPE_SVGS == 0)
continue
if (!showHidden && filename.startsWith('.'))
continue
val size = file.length()
if (size <= 0L || (doExtraCheck && !file.exists()))
continue
val dateTaken = file.lastModified()
val dateModified = file.lastModified()
val type = when {
isVideo -> TYPE_VIDEOS
isGif -> TYPE_GIFS
isRaw -> TYPE_RAWS
isSvg -> TYPE_SVGS
else -> TYPE_IMAGES
}
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", context.config.OTGPath))
val videoDuration = if (getVideoDurations) path.getVideoDuration() else 0
val isFavorite = favoritePaths.contains(path)
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, videoDuration, isFavorite, 0L)
media.add(medium)
}
return media
}
private fun getFolderDateTakens(folder: String): HashMap<String, Long> { private fun getFolderDateTakens(folder: String): HashMap<String, Long> {
val projection = arrayOf( val projection = arrayOf(
MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME,