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 05b2b0ad0..9ff14a627 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -20,6 +20,7 @@ import com.simplemobiletools.gallery.* import com.simplemobiletools.gallery.adapters.MyPagerAdapter import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.RenameFileDialog +import com.simplemobiletools.gallery.extensions.openWith import com.simplemobiletools.gallery.extensions.setAsWallpaper import com.simplemobiletools.gallery.extensions.shareMedium import com.simplemobiletools.gallery.fragments.ViewPagerFragment @@ -131,7 +132,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View true } R.id.menu_open_with -> { - openWith() + openWith(getCurrentFile()) true } R.id.menu_share -> { @@ -195,18 +196,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun openWith() { - val intent = Intent(Intent.ACTION_VIEW) - intent.setDataAndType(Uri.fromFile(getCurrentFile()), getCurrentMedium().getMimeType()) - val chooser = Intent.createChooser(intent, getString(R.string.open_with)) - - if (intent.resolveActivity(packageManager) != null) { - startActivity(chooser) - } else { - toast(R.string.no_app_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 bc8b61658..a0fe1d753 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -40,9 +40,7 @@ fun Activity.shareMedia(media: List) { fun Activity.setAsWallpaper(file: File) { val intent = Intent(Intent.ACTION_ATTACH_DATA) val uri = Uri.fromFile(file) - var mimeType = getMimeType(uri.toString()) - if (mimeType.isEmpty()) mimeType = "image/jpeg" - intent.setDataAndType(uri, mimeType) + intent.setDataAndType(uri, getImageMimeType(uri)) val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with)) if (intent.resolveActivity(packageManager) != null) { @@ -51,3 +49,24 @@ fun Activity.setAsWallpaper(file: File) { toast(R.string.no_wallpaper_setter_found) } } + +fun Activity.openWith(file: File) { + val intent = Intent(Intent.ACTION_VIEW) + val uri = Uri.fromFile(file) + intent.setDataAndType(uri, getImageMimeType(uri)) + val chooser = Intent.createChooser(intent, getString(R.string.open_with)) + + if (intent.resolveActivity(packageManager) != null) { + startActivity(chooser) + } else { + toast(R.string.no_app_found) + } +} + +fun getImageMimeType(uri: Uri): String { + val mimeType = getMimeType(uri.toString()) + return if (mimeType.isNotEmpty()) + mimeType + else + "image/jpeg" +}