From 9fb2ec55d9626421fccb3ff9d10bfec202ae958e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 4 Dec 2016 15:47:46 +0100 Subject: [PATCH] allow editing third party images --- .../gallery/activities/PhotoVideoActivity.kt | 10 +++++++++- .../gallery/activities/ViewPagerActivity.kt | 14 +------------- .../gallery/extensions/activity.kt | 13 +++++++++++++ app/src/main/res/menu/photo_video_menu.xml | 5 +++++ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index a61b460b3..5016e8e74 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -7,14 +7,15 @@ import android.os.Bundle import android.provider.MediaStore import android.view.Menu import android.view.MenuItem -import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.openEditor import com.simplemobiletools.gallery.extensions.openWith import com.simplemobiletools.gallery.extensions.setAsWallpaper import com.simplemobiletools.gallery.extensions.shareMedium import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.VideoFragment import com.simplemobiletools.gallery.fragments.ViewPagerFragment +import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -72,7 +73,10 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.photo_video_menu, menu) + menu.findItem(R.id.menu_set_as_wallpaper).isVisible = mMedium.isImage() + menu.findItem(R.id.menu_edit).isVisible = mMedium.isImage() + return true } @@ -90,6 +94,10 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic shareMedium(mMedium) true } + R.id.menu_edit -> { + openEditor(File(mMedium.path)) + true + } else -> super.onOptionsItemSelected(item) } } 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 6f6603a79..af612dd29 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -149,7 +149,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View true } R.id.menu_edit -> { - openEditor() + openEditor(getCurrentFile()) true } R.id.menu_properties -> { @@ -185,18 +185,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View }) } - private fun openEditor() { - val intent = Intent(Intent.ACTION_EDIT) - intent.setDataAndType(Uri.fromFile(getCurrentFile()), "image/*") - val chooser = Intent.createChooser(intent, getString(R.string.edit_image_with)) - - if (intent.resolveActivity(packageManager) != null) { - startActivityForResult(chooser, REQUEST_EDIT_IMAGE) - } else { - toast(R.string.no_editor_found) - } - } - private fun showProperties() { PropertiesDialog(this, getCurrentFile().absolutePath, false) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 531925bfe..835680fd9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -10,6 +10,7 @@ import android.view.KeyEvent import android.view.ViewConfiguration import com.simplemobiletools.filepicker.extensions.toast import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER import com.simplemobiletools.gallery.models.Medium import java.io.File @@ -67,6 +68,18 @@ fun Activity.openWith(file: File) { } } +fun Activity.openEditor(file: File) { + val intent = Intent(Intent.ACTION_EDIT) + intent.setDataAndType(Uri.fromFile(file), "image/*") + val chooser = Intent.createChooser(intent, getString(R.string.edit_image_with)) + + if (intent.resolveActivity(packageManager) != null) { + startActivityForResult(chooser, REQUEST_EDIT_IMAGE) + } else { + toast(R.string.no_editor_found) + } +} + fun Activity.hasNavBar(): Boolean { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { val display = windowManager.defaultDisplay diff --git a/app/src/main/res/menu/photo_video_menu.xml b/app/src/main/res/menu/photo_video_menu.xml index 419993caf..661fad548 100644 --- a/app/src/main/res/menu/photo_video_menu.xml +++ b/app/src/main/res/menu/photo_video_menu.xml @@ -6,6 +6,11 @@ android:icon="@mipmap/share" android:title="@string/share" app:showAsAction="ifRoom"/> +