From 964ffe360a42321823467430b715a3a612e4d650 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 13 Feb 2017 20:57:47 +0100 Subject: [PATCH] add the image rotating functions --- .../gallery/activities/ViewPagerActivity.kt | 25 ++++++++++++++++--- .../gallery/fragments/PhotoFragment.kt | 10 +++++--- 2 files changed, 28 insertions(+), 7 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 0e21e0b2b..562bca2a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -21,6 +21,7 @@ import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.RenameFileDialog import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE @@ -39,6 +40,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mIsFullScreen = false private var mPos = -1 private var mShowAll = false + private var mRotationDegrees = 0f override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -125,9 +127,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_edit -> openEditor(getCurrentFile()) R.id.menu_properties -> showProperties() R.id.show_on_map -> showOnMap() - R.id.rotate_right -> {} - R.id.rotate_left -> {} - R.id.rotate_one_eighty -> {} + R.id.rotate_right -> rotateImageRight() + R.id.rotate_left -> rotateImageLeft() + R.id.rotate_one_eighty -> rotateImageOneEighty() else -> return super.onOptionsItemSelected(item) } return true @@ -161,6 +163,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View }) } + private fun rotateImageRight() { + mRotationDegrees += 90 + getCurrentFragment().rotateImageViewBy(mRotationDegrees) + } + + private fun rotateImageLeft() { + mRotationDegrees -= 90 + getCurrentFragment().rotateImageViewBy(mRotationDegrees) + } + + private fun rotateImageOneEighty() { + mRotationDegrees += 180 + getCurrentFragment().rotateImageViewBy(mRotationDegrees) + } + + private fun getCurrentFragment() = ((view_pager.adapter as MyPagerAdapter).getCurrentFragment(view_pager.currentItem) as PhotoFragment) + private fun showProperties() { if (getCurrentMedium() != null) PropertiesDialog(this, getCurrentMedium()!!.path, false) 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 9b83c9348..24a017d3a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -144,17 +144,19 @@ class PhotoFragment : ViewPagerFragment() { } override fun onResourceReady(bitmap: Bitmap?, model: String?, target: Target?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean { - if (degrees == 0f) + if (degrees == 0f) { addZoomableView() + } else { + photo_view.beVisible() + subsampling_view.beGone() + } return false } }).into(glideView) } fun rotateImageViewBy(degrees: Float) { - loadBitmap(degrees) - photo_view.beVisible() - subsampling_view.beGone() + loadBitmap(degrees % 360) } private fun addZoomableView() {