From 27f00cfe3cd761c27d1828c6fd33c7622de020a3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Nov 2017 19:26:25 +0100 Subject: [PATCH] improve some double-tap zoom ratios --- .../gallery/activities/ViewPagerActivity.kt | 1 + .../gallery/fragments/PhotoFragment.kt | 11 +++++++++-- .../simplemobiletools/gallery/helpers/GlideDecoder.kt | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) 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 936a06623..7e2f54cb8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -74,6 +74,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View companion object { var screenWidth = 0 var screenHeight = 0 + var wasDecodedByGlide = false } override fun onCreate(savedInstanceState: Bundle?) { 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 c46fbf60e..22005b630 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -221,6 +221,7 @@ class PhotoFragment : ViewPagerFragment() { private fun addZoomableView() { if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.isGone()) { + ViewPagerActivity.wasDecodedByGlide = false view.subsampling_view.apply { setBitmapDecoderClass(GlideDecoder::class.java) maxScale = 10f @@ -233,7 +234,8 @@ class PhotoFragment : ViewPagerFragment() { override fun onReady() { background = ColorDrawable(if (context.config.darkBackground) Color.BLACK else context.config.backgroundColor) - setDoubleTapZoomScale(getDoubleTapZoomScale()) + val zoomScale = if (ViewPagerActivity.wasDecodedByGlide) 1f else getDoubleTapZoomScale() + setDoubleTapZoomScale(zoomScale) } override fun onTileLoadError(e: Exception?) { @@ -264,13 +266,18 @@ class PhotoFragment : ViewPagerFragment() { val height = bitmapOptions.outHeight val bitmapAspectRatio = height / (width).toFloat() - if (context == null) + if (context == null) { return 2f + } return if (context!!.portrait && bitmapAspectRatio <= 1f) { ViewPagerActivity.screenHeight / height.toFloat() + } else if (context!!.portrait && bitmapAspectRatio > 1f) { + ViewPagerActivity.screenHeight / width.toFloat() } else if (!context!!.portrait && bitmapAspectRatio >= 1f) { ViewPagerActivity.screenWidth / width.toFloat() + } else if (!context!!.portrait && bitmapAspectRatio < 1f) { + ViewPagerActivity.screenWidth / height.toFloat() } else { 2f } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt index 78ea3c9dc..55e12722a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt @@ -23,6 +23,7 @@ class GlideDecoder : ImageDecoder { val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight + ViewPagerActivity.wasDecodedByGlide = true val options = RequestOptions() .signature(uri.path.getFileSignature()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)