mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
update the code style at some activity extensions
This commit is contained in:
parent
d699293c11
commit
80bfc9183f
1 changed files with 30 additions and 24 deletions
|
@ -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,44 +62,50 @@ 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) {
|
||||
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)
|
||||
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)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivityForResult(this, REQUEST_EDIT_IMAGE)
|
||||
} else {
|
||||
toast(R.string.no_editor_found)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.hasNavBar(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
|
|
Loading…
Reference in a new issue