mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-31 04:06:43 +01:00
move OpenWith in extension
This commit is contained in:
parent
56ba895302
commit
72e56796b9
2 changed files with 24 additions and 16 deletions
|
@ -20,6 +20,7 @@ import com.simplemobiletools.gallery.*
|
||||||
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
|
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
|
||||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
|
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
|
||||||
|
import com.simplemobiletools.gallery.extensions.openWith
|
||||||
import com.simplemobiletools.gallery.extensions.setAsWallpaper
|
import com.simplemobiletools.gallery.extensions.setAsWallpaper
|
||||||
import com.simplemobiletools.gallery.extensions.shareMedium
|
import com.simplemobiletools.gallery.extensions.shareMedium
|
||||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||||
|
@ -131,7 +132,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_open_with -> {
|
R.id.menu_open_with -> {
|
||||||
openWith()
|
openWith(getCurrentFile())
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_share -> {
|
R.id.menu_share -> {
|
||||||
|
@ -195,18 +196,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openWith() {
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
|
||||||
intent.setDataAndType(Uri.fromFile(getCurrentFile()), getCurrentMedium().getMimeType())
|
|
||||||
val chooser = Intent.createChooser(intent, getString(R.string.open_with))
|
|
||||||
|
|
||||||
if (intent.resolveActivity(packageManager) != null) {
|
|
||||||
startActivity(chooser)
|
|
||||||
} else {
|
|
||||||
toast(R.string.no_app_found)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showProperties() {
|
private fun showProperties() {
|
||||||
PropertiesDialog(this, getCurrentFile().absolutePath, false)
|
PropertiesDialog(this, getCurrentFile().absolutePath, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,7 @@ fun Activity.shareMedia(media: List<Medium>) {
|
||||||
fun Activity.setAsWallpaper(file: File) {
|
fun Activity.setAsWallpaper(file: File) {
|
||||||
val intent = Intent(Intent.ACTION_ATTACH_DATA)
|
val intent = Intent(Intent.ACTION_ATTACH_DATA)
|
||||||
val uri = Uri.fromFile(file)
|
val uri = Uri.fromFile(file)
|
||||||
var mimeType = getMimeType(uri.toString())
|
intent.setDataAndType(uri, getImageMimeType(uri))
|
||||||
if (mimeType.isEmpty()) mimeType = "image/jpeg"
|
|
||||||
intent.setDataAndType(uri, mimeType)
|
|
||||||
val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with))
|
val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with))
|
||||||
|
|
||||||
if (intent.resolveActivity(packageManager) != null) {
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
|
@ -51,3 +49,24 @@ fun Activity.setAsWallpaper(file: File) {
|
||||||
toast(R.string.no_wallpaper_setter_found)
|
toast(R.string.no_wallpaper_setter_found)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Activity.openWith(file: File) {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
val uri = Uri.fromFile(file)
|
||||||
|
intent.setDataAndType(uri, getImageMimeType(uri))
|
||||||
|
val chooser = Intent.createChooser(intent, getString(R.string.open_with))
|
||||||
|
|
||||||
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
|
startActivity(chooser)
|
||||||
|
} else {
|
||||||
|
toast(R.string.no_app_found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getImageMimeType(uri: Uri): String {
|
||||||
|
val mimeType = getMimeType(uri.toString())
|
||||||
|
return if (mimeType.isNotEmpty())
|
||||||
|
mimeType
|
||||||
|
else
|
||||||
|
"image/jpeg"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue