add more action buttons to PhotoVideoActivity used by third parties
This commit is contained in:
parent
72e56796b9
commit
679deb424a
|
@ -9,6 +9,9 @@ import android.view.Menu
|
|||
import android.view.MenuItem
|
||||
import com.simplemobiletools.gallery.MEDIUM
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.extensions.openWith
|
||||
import com.simplemobiletools.gallery.extensions.setAsWallpaper
|
||||
import com.simplemobiletools.gallery.extensions.shareMedium
|
||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||
import com.simplemobiletools.gallery.fragments.VideoFragment
|
||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||
|
@ -19,6 +22,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
|||
private var mIsFullScreen = false
|
||||
lateinit var mUri: Uri
|
||||
lateinit var mFragment: ViewPagerFragment
|
||||
lateinit var mMedium: Medium
|
||||
|
||||
companion object {
|
||||
var mIsVideo = false
|
||||
|
@ -41,8 +45,8 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
|||
|
||||
val bundle = Bundle()
|
||||
val file = File(mUri.toString())
|
||||
val medium = Medium(file.name, mUri.toString(), mIsVideo, 0, file.length())
|
||||
bundle.putSerializable(MEDIUM, medium)
|
||||
mMedium = Medium(file.name, mUri.toString(), mIsVideo, 0, file.length())
|
||||
bundle.putSerializable(MEDIUM, mMedium)
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mFragment = if (mIsVideo) VideoFragment() else PhotoFragment()
|
||||
|
@ -73,24 +77,22 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.menu_set_as_wallpaper -> {
|
||||
setAsWallpaper(File(mMedium.path))
|
||||
true
|
||||
}
|
||||
R.id.menu_open_with -> {
|
||||
openWith(File(mMedium.path))
|
||||
true
|
||||
}
|
||||
R.id.menu_share -> {
|
||||
shareMedium()
|
||||
shareMedium(mMedium)
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun shareMedium() {
|
||||
val shareTitle = resources.getString(R.string.share_via)
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, mUri)
|
||||
type = if (mIsVideo) "video/*" else "image/*"
|
||||
startActivity(Intent.createChooser(this, shareTitle))
|
||||
}
|
||||
}
|
||||
|
||||
override fun fragmentClicked() {
|
||||
mIsFullScreen = !mIsFullScreen
|
||||
if (mIsFullScreen) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.gallery.extensions
|
|||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.filepicker.extensions.getMimeType
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER
|
||||
|
@ -40,7 +39,7 @@ 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, getImageMimeType(uri))
|
||||
intent.setDataAndType(uri, uri.getImageMimeType())
|
||||
val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with))
|
||||
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
|
@ -53,7 +52,7 @@ fun Activity.setAsWallpaper(file: File) {
|
|||
fun Activity.openWith(file: File) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
val uri = Uri.fromFile(file)
|
||||
intent.setDataAndType(uri, getImageMimeType(uri))
|
||||
intent.setDataAndType(uri, uri.getImageMimeType())
|
||||
val chooser = Intent.createChooser(intent, getString(R.string.open_with))
|
||||
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
|
@ -62,11 +61,3 @@ fun Activity.openWith(file: File) {
|
|||
toast(R.string.no_app_found)
|
||||
}
|
||||
}
|
||||
|
||||
fun getImageMimeType(uri: Uri): String {
|
||||
val mimeType = getMimeType(uri.toString())
|
||||
return if (mimeType.isNotEmpty())
|
||||
mimeType
|
||||
else
|
||||
"image/jpeg"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.simplemobiletools.gallery.extensions
|
||||
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.filepicker.extensions.getMimeType
|
||||
|
||||
fun Uri.getImageMimeType(): String {
|
||||
val mimeType = getMimeType(toString())
|
||||
return if (mimeType.isNotEmpty())
|
||||
mimeType
|
||||
else
|
||||
"image/jpeg"
|
||||
}
|
|
@ -6,4 +6,13 @@
|
|||
android:icon="@mipmap/share"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_edit"
|
||||
android:icon="@mipmap/edit"
|
||||
android:title="@string/edit"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_open_with"
|
||||
android:title="@string/open_with"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
|
|
Loading…
Reference in New Issue