add a Save as button for saving rotated images

This commit is contained in:
tibbi 2017-02-13 22:44:03 +01:00
parent a8e95ce736
commit 9a9ce890ca
3 changed files with 21 additions and 14 deletions

View file

@ -20,6 +20,7 @@ import com.simplemobiletools.gallery.adapters.MyPagerAdapter
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.dialogs.RenameFileDialog import com.simplemobiletools.gallery.dialogs.RenameFileDialog
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.PhotoFragment
import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.fragments.ViewPagerFragment
@ -102,6 +103,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium()!!.isImage() == true findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium()!!.isImage() == true
findItem(R.id.menu_edit).isVisible = getCurrentMedium()!!.isImage() == true findItem(R.id.menu_edit).isVisible = getCurrentMedium()!!.isImage() == true
findItem(R.id.menu_rotate).isVisible = getCurrentMedium()!!.isImage() == true findItem(R.id.menu_rotate).isVisible = getCurrentMedium()!!.isImage() == true
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0f
findItem(R.id.menu_rotate).subMenu.apply { findItem(R.id.menu_rotate).subMenu.apply {
clearHeader() clearHeader()
@ -127,10 +129,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
R.id.menu_rename -> renameFile() R.id.menu_rename -> renameFile()
R.id.menu_edit -> openEditor(getCurrentFile()) R.id.menu_edit -> openEditor(getCurrentFile())
R.id.menu_properties -> showProperties() R.id.menu_properties -> showProperties()
R.id.menu_save_as -> saveImageAs()
R.id.show_on_map -> showOnMap() R.id.show_on_map -> showOnMap()
R.id.rotate_right -> rotateImageRight() R.id.rotate_right -> rotateImage(90f)
R.id.rotate_left -> rotateImageLeft() R.id.rotate_left -> rotateImage(-90f)
R.id.rotate_one_eighty -> rotateImageOneEighty() R.id.rotate_one_eighty -> rotateImage(180f)
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
} }
return true return true
@ -164,19 +167,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}) })
} }
private fun rotateImageRight() { private fun saveImageAs() {
mRotationDegrees += 90 SaveAsDialog(this, getCurrentMedium()!!.path) {
getCurrentFragment().rotateImageViewBy(mRotationDegrees)
}
} }
private fun rotateImageLeft() { private fun rotateImage(degrees: Float) {
mRotationDegrees -= 90 mRotationDegrees = (mRotationDegrees + degrees) % 360
getCurrentFragment().rotateImageViewBy(mRotationDegrees)
}
private fun rotateImageOneEighty() {
mRotationDegrees += 180
getCurrentFragment().rotateImageViewBy(mRotationDegrees) getCurrentFragment().rotateImageViewBy(mRotationDegrees)
supportInvalidateOptionsMenu()
} }
private fun getCurrentFragment() = ((view_pager.adapter as MyPagerAdapter).getCurrentFragment(view_pager.currentItem) as PhotoFragment) private fun getCurrentFragment() = ((view_pager.adapter as MyPagerAdapter).getCurrentFragment(view_pager.currentItem) as PhotoFragment)
@ -395,6 +395,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
mPos = position mPos = position
updateActionbarTitle() updateActionbarTitle()
mRotationDegrees = 0f
supportInvalidateOptionsMenu() supportInvalidateOptionsMenu()
} }

View file

@ -156,7 +156,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
fun rotateImageViewBy(degrees: Float) { fun rotateImageViewBy(degrees: Float) {
loadBitmap(degrees % 360) loadBitmap(degrees)
} }
private fun addZoomableView() { private fun addZoomableView() {

View file

@ -18,6 +18,12 @@
android:title="@string/rotate_one_eighty"/> android:title="@string/rotate_one_eighty"/>
</menu> </menu>
</item> </item>
<item
android:id="@+id/menu_save_as"
android:icon="@drawable/ic_check"
android:title="@string/save_as"
android:visible="false"
app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/menu_delete" android:id="@+id/menu_delete"
android:icon="@drawable/ic_delete" android:icon="@drawable/ic_delete"