From b6c919be8538d02d58c439d649e3f168dec9fbab Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Oct 2019 23:39:29 +0200 Subject: [PATCH] load the proper Portrait image --- .../gallery/pro/fragments/PhotoFragment.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index e458b52fc..454269e4c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -342,16 +342,17 @@ class PhotoFragment : ViewPagerFragment() { private fun loadImage() { checkScreenDimensions() + + if (mMedium.isPortrait() && context != null) { + showPortraitStripe() + } + mImageOrientation = getImageOrientation() when { mMedium.isGIF() -> loadGif() mMedium.isSVG() -> loadSVG() else -> loadBitmap() } - - if (mMedium.isPortrait() && context != null) { - showPortraitStripe() - } } private fun loadGif() { @@ -386,7 +387,7 @@ class PhotoFragment : ViewPagerFragment() { private fun loadBitmap(addZoomableView: Boolean = true) { val priority = if (mIsFragmentVisible) Priority.IMMEDIATE else Priority.NORMAL val options = RequestOptions() - .signature(mMedium.path.getFileSignature()) + .signature(getFilePathToShow().getFileSignature()) .format(DecodeFormat.PREFER_ARGB_8888) .priority(priority) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) @@ -398,7 +399,7 @@ class PhotoFragment : ViewPagerFragment() { } Glide.with(context!!) - .load(mMedium.path) + .load(getFilePathToShow()) .apply(options) .listener(object : RequestListener { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { @@ -419,7 +420,7 @@ class PhotoFragment : ViewPagerFragment() { } private fun tryLoadingWithPicasso(addZoomableView: Boolean) { - var pathToLoad = if (mMedium.path.startsWith("content://")) mMedium.path else "file://${mMedium.path}" + var pathToLoad = if (getFilePathToShow().startsWith("content://")) getFilePathToShow() else "file://${getFilePathToShow()}" pathToLoad = pathToLoad.replace("%", "%25").replace("#", "%23") try { @@ -468,6 +469,8 @@ class PhotoFragment : ViewPagerFragment() { mView.photo_portrait_stripe.smoothScrollBy((x + itemWidth / 2) - screenWidth / 2, 0) if (paths[position] != mCurrentPortraitPhotoPath) { mCurrentPortraitPhotoPath = paths[position] + hideZoomableView() + loadBitmap() } } @@ -550,6 +553,8 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun getFilePathToShow() = if (mMedium.isPortrait()) mCurrentPortraitPhotoPath else mMedium.path + private fun openPanorama() { Intent(context, PanoramaPhotoActivity::class.java).apply { putExtra(PATH, mMedium.path) @@ -597,7 +602,7 @@ class PhotoFragment : ViewPagerFragment() { rotationEnabled = config.allowRotatingWithGestures isOneToOneZoomEnabled = config.allowOneToOneZoom orientation = newOrientation - setImage(mMedium.path) + setImage(getFilePathToShow()) onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener { override fun onReady() { @@ -661,7 +666,7 @@ class PhotoFragment : ViewPagerFragment() { var orient = defaultOrientation try { - val path = mMedium.path + val path = getFilePathToShow() orient = if (path.startsWith("content:/")) { val inputStream = context!!.contentResolver.openInputStream(Uri.parse(path)) val exif = ExifInterface() @@ -673,7 +678,7 @@ class PhotoFragment : ViewPagerFragment() { exif.getAttributeInt(TAG_ORIENTATION, defaultOrientation) } - if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) { + if (orient == defaultOrientation || context!!.isPathOnOTG(getFilePathToShow())) { val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path)) val inputStream = context!!.contentResolver.openInputStream(uri) val exif2 = ExifInterface()