From 77b4a65ac3f0d5fe6457078aefb6e873bcb1dbe7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 7 Feb 2019 11:26:13 +0100 Subject: [PATCH] improving rotation handling --- app/build.gradle | 2 +- .../gallery/pro/fragments/PhotoFragment.kt | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 37ebe515f..6fa7f87ad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,7 +75,7 @@ dependencies { implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.caverock:androidsvg-aar:1.3' implementation 'com.github.tibbi:gestureviews:985ba285fb' - implementation 'com.github.tibbi:subsampling-scale-image-view:40dc6ee2b1' + implementation 'com.github.tibbi:subsampling-scale-image-view:51cb8f922c' kapt 'com.github.bumptech.glide:compiler:4.8.0' // keep it here too, not just in Commons, else loading SVGs wont work kapt 'androidx.room:room-compiler:2.0.0' 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 bef05133e..761490ebf 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 @@ -444,6 +444,11 @@ class PhotoFragment : ViewPagerFragment() { override fun make() = PicassoRegionDecoder() } + var newOrientation = (rotation + mCurrentRotationDegrees) % 360 + if (newOrientation < 0) { + newOrientation += 360 + } + val config = context!!.config mView.subsampling_view.apply { setMaxTileSize(if (config.showHighestQuality) Integer.MAX_VALUE else 4096) @@ -454,7 +459,7 @@ class PhotoFragment : ViewPagerFragment() { maxScale = 10f beVisible() isOneToOneZoomEnabled = config.allowOneToOneZoom - orientation = (rotation + mCurrentRotationDegrees) % 360 + orientation = newOrientation setImage(path) onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener { override fun onReady() { @@ -472,15 +477,13 @@ class PhotoFragment : ViewPagerFragment() { } override fun onImageRotation(degrees: Int) { - if (mCurrentRotationDegrees != degrees) { - val fullRotation = (rotation + degrees) % 360 - val useWidth = if (fullRotation == 90 || fullRotation == 270) sHeight else sWidth - val useHeight = if (fullRotation == 90 || fullRotation == 270) sWidth else sHeight - doubleTapZoomScale = getDoubleTapZoomScale(useWidth, useHeight) - loadBitmap(degrees, false) - activity?.invalidateOptionsMenu() - } - mCurrentRotationDegrees = degrees + val fullRotation = (rotation + degrees) % 360 + val useWidth = if (fullRotation == 90 || fullRotation == 270) sHeight else sWidth + val useHeight = if (fullRotation == 90 || fullRotation == 270) sWidth else sHeight + doubleTapZoomScale = getDoubleTapZoomScale(useWidth, useHeight) + mCurrentRotationDegrees = (mCurrentRotationDegrees + degrees) % 360 + loadBitmap(mCurrentRotationDegrees, false) + activity?.invalidateOptionsMenu() } } }