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 android.view.MenuItem
|
||||||
import com.simplemobiletools.gallery.MEDIUM
|
import com.simplemobiletools.gallery.MEDIUM
|
||||||
import com.simplemobiletools.gallery.R
|
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.PhotoFragment
|
||||||
import com.simplemobiletools.gallery.fragments.VideoFragment
|
import com.simplemobiletools.gallery.fragments.VideoFragment
|
||||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||||
|
@ -19,6 +22,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
||||||
private var mIsFullScreen = false
|
private var mIsFullScreen = false
|
||||||
lateinit var mUri: Uri
|
lateinit var mUri: Uri
|
||||||
lateinit var mFragment: ViewPagerFragment
|
lateinit var mFragment: ViewPagerFragment
|
||||||
|
lateinit var mMedium: Medium
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var mIsVideo = false
|
var mIsVideo = false
|
||||||
|
@ -41,8 +45,8 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
||||||
|
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
val file = File(mUri.toString())
|
val file = File(mUri.toString())
|
||||||
val medium = Medium(file.name, mUri.toString(), mIsVideo, 0, file.length())
|
mMedium = Medium(file.name, mUri.toString(), mIsVideo, 0, file.length())
|
||||||
bundle.putSerializable(MEDIUM, medium)
|
bundle.putSerializable(MEDIUM, mMedium)
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mFragment = if (mIsVideo) VideoFragment() else PhotoFragment()
|
mFragment = if (mIsVideo) VideoFragment() else PhotoFragment()
|
||||||
|
@ -73,24 +77,22 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
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 -> {
|
R.id.menu_share -> {
|
||||||
shareMedium()
|
shareMedium(mMedium)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
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() {
|
override fun fragmentClicked() {
|
||||||
mIsFullScreen = !mIsFullScreen
|
mIsFullScreen = !mIsFullScreen
|
||||||
if (mIsFullScreen) {
|
if (mIsFullScreen) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.gallery.extensions
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.simplemobiletools.filepicker.extensions.getMimeType
|
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER
|
import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER
|
||||||
|
@ -40,7 +39,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)
|
||||||
intent.setDataAndType(uri, getImageMimeType(uri))
|
intent.setDataAndType(uri, uri.getImageMimeType())
|
||||||
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) {
|
||||||
|
@ -53,7 +52,7 @@ fun Activity.setAsWallpaper(file: File) {
|
||||||
fun Activity.openWith(file: File) {
|
fun Activity.openWith(file: File) {
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
val uri = Uri.fromFile(file)
|
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))
|
val chooser = Intent.createChooser(intent, getString(R.string.open_with))
|
||||||
|
|
||||||
if (intent.resolveActivity(packageManager) != null) {
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
|
@ -62,11 +61,3 @@ fun Activity.openWith(file: File) {
|
||||||
toast(R.string.no_app_found)
|
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:icon="@mipmap/share"
|
||||||
android:title="@string/share"
|
android:title="@string/share"
|
||||||
app:showAsAction="ifRoom"/>
|
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>
|
</menu>
|
||||||
|
|
Loading…
Reference in New Issue