From d55c9bb2cb1d6ee702fa3fa0fcab0f3ff56895bc Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 6 Feb 2019 21:33:36 +0100 Subject: [PATCH] adding some rotation related improvements --- app/build.gradle | 2 +- .../pro/activities/ViewPagerActivity.kt | 18 +++++++---------- .../gallery/pro/fragments/PhotoFragment.kt | 20 +++++++++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f1c2c4b9d..dbee20658 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:f8559f7f43' + implementation 'com.github.tibbi:subsampling-scale-image-view:7be04d9b93' 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/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 681bca548..ac06ffe53 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -54,7 +54,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mPos = -1 private var mShowAll = false private var mIsSlideshowActive = false - private var mRotationDegrees = 0 private var mPrevHashcode = 0 private var mSlideshowHandler = Handler() @@ -142,7 +141,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path) val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0 - getCurrentPhotoFragment()?.mCurrentRotationDegrees = mRotationDegrees + val rotationDegrees = getCurrentPhotoFragment()?.mCurrentRotationDegrees menu.apply { findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0 findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0 @@ -154,16 +153,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0 findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0 findItem(R.id.menu_copy_to).isVisible = visibleBottomActions and BOTTOM_ACTION_COPY == 0 - findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0 + findItem(R.id.menu_save_as).isVisible = rotationDegrees != 0 findItem(R.id.menu_hide).isVisible = !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin() findItem(R.id.menu_unhide).isVisible = currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin() findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath) - findItem(R.id.menu_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0 + findItem(R.id.menu_change_orientation).isVisible = rotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0 findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon()) findItem(R.id.menu_rotate).setShowAsAction( - if (mRotationDegrees != 0) { + if (rotationDegrees != 0) { MenuItem.SHOW_AS_ACTION_ALWAYS } else { MenuItem.SHOW_AS_ACTION_IF_ROOM @@ -563,8 +562,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun rotateBy(degrees: Int) { - mRotationDegrees = (mRotationDegrees + degrees) % 360 - getCurrentPhotoFragment()?.rotateImageViewBy(mRotationDegrees) + getCurrentPhotoFragment()?.rotateImageViewBy(degrees) supportInvalidateOptionsMenu() } @@ -592,10 +590,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View handleSAFDialog(it) { toast(R.string.saving) Thread { - saveRotatedImageToFile(currPath, it, mRotationDegrees, true) { + val photoFragment = getCurrentPhotoFragment() ?: return@Thread + saveRotatedImageToFile(currPath, it, photoFragment.mCurrentRotationDegrees, true) { toast(R.string.file_saved) - mRotationDegrees = 0 - getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0 invalidateOptionsMenu() } }.start() @@ -1075,7 +1072,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (mPos != position) { mPos = position updateActionbarTitle() - mRotationDegrees = 0 invalidateOptionsMenu() scheduleSwipe() } 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 a84d5bf37..86770742d 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 @@ -65,6 +65,7 @@ class PhotoFragment : ViewPagerFragment() { ) var mCurrentRotationDegrees = 0 + private var mOriginalRotationDegrees = 0 private var mIsFragmentVisible = false private var mIsFullscreen = false private var mWasInit = false @@ -356,7 +357,7 @@ class PhotoFragment : ViewPagerFragment() { .into(mView.gestures_view) } - private fun loadBitmap(degrees: Int = mCurrentRotationDegrees) { + private fun loadBitmap(degrees: Int = mCurrentRotationDegrees, addZoomableView: Boolean = true) { val options = RequestOptions() .signature(mMedium.path.getFileSignature()) .format(DecodeFormat.PREFER_ARGB_8888) @@ -374,13 +375,13 @@ class PhotoFragment : ViewPagerFragment() { .listener(object : RequestListener { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { if (activity != null) { - tryLoadingWithPicasso(degrees) + tryLoadingWithPicasso(degrees, addZoomableView) } return false } override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - if (mIsFragmentVisible) { + if (mIsFragmentVisible && addZoomableView) { scheduleZoomableView() } return false @@ -388,7 +389,7 @@ class PhotoFragment : ViewPagerFragment() { }).into(mView.gestures_view) } - private fun tryLoadingWithPicasso(degrees: Int = 0) { + private fun tryLoadingWithPicasso(degrees: Int = 0, addZoomableView: Boolean) { var pathToLoad = if (mMedium.path.startsWith("content://")) mMedium.path else "file://${mMedium.path}" pathToLoad = pathToLoad.replace("%", "%25").replace("#", "%23") @@ -408,7 +409,7 @@ class PhotoFragment : ViewPagerFragment() { picasso.into(mView.gestures_view, object : Callback { override fun onSuccess() { mView.gestures_view.controller.settings.isZoomEnabled = degrees != 0 || context?.config?.allowZoomingImages == false - if (mIsFragmentVisible) { + if (mIsFragmentVisible && addZoomableView) { scheduleZoomableView() } } @@ -476,6 +477,13 @@ class PhotoFragment : ViewPagerFragment() { mIsSubsamplingVisible = false beGone() } + + override fun onImageRotation(degrees: Int) { + if (mCurrentRotationDegrees != degrees) { + loadBitmap(degrees, false) + } + mCurrentRotationDegrees = degrees + } } } } @@ -548,7 +556,7 @@ class PhotoFragment : ViewPagerFragment() { } fun rotateImageViewBy(degrees: Int) { - mCurrentRotationDegrees = degrees + mCurrentRotationDegrees = (mCurrentRotationDegrees + degrees) % 360 mLoadZoomableViewHandler.removeCallbacksAndMessages(null) mIsSubsamplingVisible = false loadBitmap(degrees)