From b70292652bb032f83af9fe1bf5e65472c332dbc1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 20 Feb 2018 15:43:26 +0100 Subject: [PATCH] fix loading of fullscreen OTG media --- app/build.gradle | 2 +- .../gallery/activities/EditActivity.kt | 3 ++- .../gallery/activities/PhotoVideoActivity.kt | 4 ++-- .../gallery/activities/ViewPagerActivity.kt | 8 ++++---- .../gallery/adapters/MediaAdapter.kt | 3 ++- .../asynctasks/GetDirectoriesAsynctask.kt | 2 +- .../simplemobiletools/gallery/extensions/File.kt | 3 --- .../gallery/fragments/PhotoFragment.kt | 16 ++++++++++------ .../gallery/helpers/MediaFetcher.kt | 2 +- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1a597b002..9c2198418 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.12.12' + implementation 'com.simplemobiletools:commons:3.12.13' 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/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index bfda0f48c..4b8c448c6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -11,6 +11,7 @@ import android.provider.MediaStore import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.commons.models.FileDirItem @@ -65,7 +66,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener saveUri = when { intent.extras?.containsKey(REAL_FILE_PATH) == true -> { val realPath = intent.extras.get(REAL_FILE_PATH) as String - if (isPathOnOTG(realPath)) { + if (realPath.startsWith(OTG_PATH)) { Uri.parse(realPath) } else { Uri.fromFile(File(realPath)) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 3305f0086..beb01858a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -11,6 +11,7 @@ import android.view.View import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.gallery.R @@ -60,13 +61,12 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList mUri = intent.data ?: return if (intent.extras?.containsKey(REAL_FILE_PATH) == true) { val realPath = intent.extras.get(REAL_FILE_PATH) as String - if (!isPathOnOTG(realPath)) { + if (!realPath.startsWith(OTG_PATH)) { mUri = Uri.fromFile(File(realPath)) } } mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false) - if (mUri!!.scheme == "file") { scanPath(mUri!!.path) sendViewPagerIntent(mUri!!.path) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index c5f9dfa70..e0cc68a17 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -29,10 +29,7 @@ import com.bumptech.glide.Glide import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY -import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE -import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE -import com.simplemobiletools.commons.helpers.REQUEST_SET_AS +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MyPagerAdapter @@ -202,6 +199,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View showSystemUI() mDirectory = mPath.getParentPath().trimEnd('/') + if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) { + mDirectory += "/" + } supportActionBar?.title = mPath.getFilenameFromPath() view_pager.onGlobalLayout { 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 72731aaa2..7c599a9b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView @@ -288,7 +289,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, photo_name.tag = medium.path var thumbnailPath = medium.path - if (hasOTGConnected && activity.isPathOnOTG(thumbnailPath)) { + if (hasOTGConnected && thumbnailPath.startsWith(OTG_PATH)) { thumbnailPath = thumbnailPath.getOTGPublicPath(context) } 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 d1f86f01e..a7165c1c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -37,7 +37,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val firstItem = curMedia.first() val lastItem = curMedia.last() - val parentDir = if (hasOTG && context.isPathOnOTG(firstItem.path)) firstItem.path.getParentPath() else File(firstItem.path).parent + val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) firstItem.path.getParentPath() else File(firstItem.path).parent var thumbnail = firstItem.path if (thumbnail.startsWith(OTG_PATH)) { thumbnail = thumbnail.getOTGPublicPath(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt index 668c3acb5..2f05233c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt @@ -1,9 +1,6 @@ package com.simplemobiletools.gallery.extensions -import android.os.Environment import com.simplemobiletools.gallery.helpers.NOMEDIA import java.io.File fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists() - -fun File.isDownloadsFolder() = absolutePath == Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 18a2d23a3..fba95f9f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -24,6 +24,7 @@ import com.bumptech.glide.request.target.Target import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.PhotoActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity @@ -204,10 +205,11 @@ class PhotoFragment : ViewPagerFragment() { private fun loadGif() { try { - gifDrawable = if (medium.path.startsWith("content://") || medium.path.startsWith("file://")) { - GifDrawable(context!!.contentResolver, Uri.parse(medium.path)) + val pathToLoad = getPathToLoad() + gifDrawable = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { + GifDrawable(context!!.contentResolver, Uri.parse(pathToLoad)) } else { - GifDrawable(medium.path) + GifDrawable(pathToLoad) } if (!isFragmentVisible) { @@ -241,7 +243,7 @@ class PhotoFragment : ViewPagerFragment() { Glide.with(this) .asBitmap() - .load(medium.path) + .load(getPathToLoad()) .apply(options) .listener(object : RequestListener { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean) = false @@ -259,7 +261,7 @@ class PhotoFragment : ViewPagerFragment() { Glide.with(this) .asBitmap() - .load(medium.path) + .load(getPathToLoad()) .thumbnail(0.2f) .apply(options) .into(view.gif_view) @@ -273,7 +275,7 @@ class PhotoFragment : ViewPagerFragment() { maxScale = 10f beVisible() isQuickScaleEnabled = context.config.oneFingerZoom - setImage(ImageSource.uri(medium.path)) + setImage(ImageSource.uri(getPathToLoad())) orientation = if (imageOrientation == -1) SubsamplingScaleImageView.ORIENTATION_USE_EXIF else degreesForRotation(imageOrientation) setEagerLoadingEnabled(false) setExecutor(AsyncTask.SERIAL_EXECUTOR) @@ -308,6 +310,8 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun getPathToLoad() = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path + private fun getImageOrientation(): Int { val defaultOrientation = -1 var orient = defaultOrientation diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 838741c1f..6413485a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -199,7 +199,7 @@ class MediaFetcher(val context: Context) { } config.includedFolders.filter { it.isNotEmpty() && (curPath.isEmpty() || it == curPath) }.forEach { - if (context.isPathOnOTG(it)) { + if (it.startsWith(OTG_PATH)) { getMediaOnOTG(it, curMedia, isPickImage, isPickVideo, filterMedia) } else { getMediaInFolder(it, curMedia, isPickImage, isPickVideo, filterMedia)