update the code style at some activity extensions

This commit is contained in:
tibbi 2017-03-05 23:34:23 +01:00
parent d699293c11
commit 80bfc9183f

View file

@ -48,10 +48,10 @@ fun Activity.shareMedium(medium: Medium) {
fun Activity.shareMedia(media: List<Medium>) {
val shareTitle = resources.getString(R.string.share_via)
val uris = ArrayList<Uri>(media.size)
Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE
type = "image/* video/*"
val uris = ArrayList<Uri>(media.size)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
media.map { File(it.path) }
.mapTo(uris) { Uri.fromFile(it) }
@ -62,42 +62,48 @@ fun Activity.shareMedia(media: List<Medium>) {
}
fun Activity.setAsWallpaper(file: File) {
val intent = Intent(Intent.ACTION_ATTACH_DATA)
val uri = Uri.fromFile(file)
intent.setDataAndType(uri, file.getMimeType("image/*"))
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with))
Intent().apply {
action = Intent.ACTION_ATTACH_DATA
setDataAndType(uri, file.getMimeType("image/*"))
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val chooser = Intent.createChooser(this, getString(R.string.set_as_wallpaper_with))
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(chooser, REQUEST_SET_WALLPAPER)
} else {
toast(R.string.no_wallpaper_setter_found)
if (resolveActivity(packageManager) != null) {
startActivityForResult(chooser, REQUEST_SET_WALLPAPER)
} else {
toast(R.string.no_wallpaper_setter_found)
}
}
}
fun Activity.openWith(file: File, forceChooser: Boolean = true) {
val intent = Intent(Intent.ACTION_VIEW)
val uri = Uri.fromFile(file)
intent.setDataAndType(uri, file.getMimeType("image/jpeg"))
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val chooser = Intent.createChooser(intent, getString(R.string.open_with))
Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, file.getMimeType("image/jpeg"))
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val chooser = Intent.createChooser(this, getString(R.string.open_with))
if (intent.resolveActivity(packageManager) != null) {
startActivity(if (forceChooser) chooser else intent)
} else {
toast(R.string.no_app_found)
if (resolveActivity(packageManager) != null) {
startActivity(if (forceChooser) chooser else this)
} else {
toast(R.string.no_app_found)
}
}
}
fun Activity.openEditor(file: File) {
val intent = Intent(Intent.ACTION_EDIT)
intent.setDataAndType(Uri.fromFile(file), "image/*")
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
Intent().apply {
action = Intent.ACTION_EDIT
setDataAndType(Uri.fromFile(file), "image/*")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
if (intent.resolveActivity(packageManager) != null) {
startActivityForResult(intent, REQUEST_EDIT_IMAGE)
} else {
toast(R.string.no_editor_found)
if (resolveActivity(packageManager) != null) {
startActivityForResult(this, REQUEST_EDIT_IMAGE)
} else {
toast(R.string.no_editor_found)
}
}
}