From 94da492db0dab36ae4aad2331442a08cc2808bab Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Mon, 6 Mar 2017 11:54:50 +0100 Subject: [PATCH] add a helper function for the uris --- .../gallery/activities/MainActivity.kt | 7 ++----- .../simplemobiletools/gallery/extensions/activity.kt | 12 +++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 36a517b7a..e7f6caf0a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -20,10 +20,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.launchAbout -import com.simplemobiletools.gallery.extensions.launchCamera -import com.simplemobiletools.gallery.extensions.launchSettings +import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.views.MyScalableRecyclerView @@ -286,7 +283,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { if (requestCode == PICK_MEDIA && resultData != null) { Intent().apply { val path = resultData.data.path - val uri = FileProvider.getUriForFile(this@MainActivity, "$packageName.provider", File(path)) + val uri = getFileUri(File(path)) if (mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsGetAnyContentIntent) { val type = File(path).getMimeType("image/jpeg") setDataAndTypeAndNormalize(uri, type) 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 2e37a0d6e..dbbe3e847 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -37,7 +37,7 @@ fun Activity.shareUri(medium: Medium, uri: Uri) { fun Activity.shareMedium(medium: Medium) { val shareTitle = resources.getString(R.string.share_via) val file = File(medium.path) - val uri = FileProvider.getUriForFile(this, "$packageName.provider", file) + val uri = getFileUri(file) Intent().apply { action = Intent.ACTION_SEND putExtra(Intent.EXTRA_STREAM, uri) @@ -55,7 +55,7 @@ fun Activity.shareMedia(media: List) { type = "image/* video/*" addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) media.map { File(it.path) } - .mapTo(uris) { FileProvider.getUriForFile(this@shareMedia, "$packageName.provider", it) } + .mapTo(uris) { getFileUri(it) } putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris) startActivity(Intent.createChooser(this, shareTitle)) @@ -63,7 +63,7 @@ fun Activity.shareMedia(media: List) { } fun Activity.setAsWallpaper(file: File) { - val uri = FileProvider.getUriForFile(this, "$packageName.provider", file) + val uri = getFileUri(file) Intent().apply { action = Intent.ACTION_ATTACH_DATA setDataAndType(uri, file.getMimeType("image/*")) @@ -79,7 +79,7 @@ fun Activity.setAsWallpaper(file: File) { } fun Activity.openWith(file: File, forceChooser: Boolean = true) { - val uri = FileProvider.getUriForFile(this, "$packageName.provider", file) + val uri = getFileUri(file) Intent().apply { action = Intent.ACTION_VIEW setDataAndType(uri, file.getMimeType("image/jpeg")) @@ -95,7 +95,7 @@ fun Activity.openWith(file: File, forceChooser: Boolean = true) { } fun Activity.openEditor(file: File) { - val uri = FileProvider.getUriForFile(this, "$packageName.provider", file) + val uri = getFileUri(file) Intent().apply { action = Intent.ACTION_EDIT setDataAndType(uri, "image/*") @@ -109,6 +109,8 @@ fun Activity.openEditor(file: File) { } } +fun Activity.getFileUri(file: File) = FileProvider.getUriForFile(this, "$packageName.provider", file) + fun Activity.hasNavBar(): Boolean { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { val display = windowManager.defaultDisplay