add a helper function for the uris

This commit is contained in:
Tibor Kaputa 2017-03-06 11:54:50 +01:00
parent eac2a37bad
commit 94da492db0
2 changed files with 9 additions and 10 deletions

View file

@ -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)

View file

@ -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<Medium>) {
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<Medium>) {
}
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