From c9f6668fc1a0df8dd1cdaeb1836533c718bda8f7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 27 Oct 2017 14:08:33 +0200 Subject: [PATCH] force an app chooser at some openFile intents --- .../com/simplemobiletools/gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../simplemobiletools/gallery/activities/ViewPagerActivity.kt | 2 +- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 2 +- .../com/simplemobiletools/gallery/extensions/activity.kt | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index f20aa4c39..facb606a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -504,7 +504,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val file = File(path) val isVideo = file.isVideoFast() if (isVideo) { - openFile(Uri.fromFile(file)) + openFile(Uri.fromFile(file), false) } else { Intent(this, ViewPagerActivity::class.java).apply { putExtra(MEDIUM, path) 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 cd2bf4902..ca6d1c0a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -130,7 +130,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList when (item.itemId) { R.id.menu_set_as -> setAs(mUri) - R.id.menu_open_with -> openFile(mUri) + R.id.menu_open_with -> openFile(mUri, true) R.id.menu_share -> shareUri(mUri) R.id.menu_edit -> openEditor(mUri) R.id.menu_properties -> showProperties() 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 7214b6a00..18eb2f5df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -250,7 +250,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.slideshow -> initSlideshow() R.id.menu_copy_to -> copyMoveTo(true) R.id.menu_move_to -> copyMoveTo(false) - R.id.menu_open_with -> openFile(Uri.fromFile(getCurrentFile())) + R.id.menu_open_with -> openFile(Uri.fromFile(getCurrentFile()), true) R.id.menu_hide -> toggleFileVisibility(true) R.id.menu_unhide -> toggleFileVisibility(false) R.id.menu_share_1 -> shareMedium(getCurrentMedium()!!) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index b71a694a7..6ede29e0d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -87,7 +87,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) R.id.cab_select_all -> selectAll() - R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile())) + R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true) R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile())) R.id.cab_delete -> checkDeleteConfirmation() else -> return 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 b2b64e339..b721d60cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -79,7 +79,7 @@ fun Activity.setAs(uri: Uri) { } } -fun Activity.openFile(uri: Uri) { +fun Activity.openFile(uri: Uri, forceChooser: Boolean) { val newUri = ensurePublicUri(uri) Intent().apply { action = Intent.ACTION_VIEW @@ -93,7 +93,7 @@ fun Activity.openFile(uri: Uri) { if (resolveActivity(packageManager) != null) { val chooser = Intent.createChooser(this, getString(R.string.open_with)) - startActivity(chooser) + startActivity(if (forceChooser) chooser else this) } else { toast(R.string.no_app_found) }