ViewMediaActivity: add a button to open media file in external application just in case built-in fails

main
Alibek Omarov 5 years ago
parent f1397f3378
commit e14782b691
  1. 14
      app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt
  2. 9
      app/src/main/res/drawable/ic_exit_to_app_24px.xml
  3. 5
      app/src/main/res/menu/view_media_toolbar.xml
  4. 1
      app/src/main/res/values/husky.xml

@ -142,6 +142,7 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
toolbar.setNavigationOnClickListener { supportFinishAfterTransition() }
toolbar.setOnMenuItemClickListener { item: MenuItem ->
when (item.itemId) {
R.id.action_open_in_external_app -> openInExternalApp()
R.id.action_download -> requestDownloadMedia()
R.id.action_open_status -> onOpenStatus()
R.id.action_share_media -> shareMedia()
@ -269,6 +270,19 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
startActivity(Intent.createChooser(sendIntent, resources.getText(R.string.send_media_to)))
}
private fun openInExternalApp() {
val url = attachments!![viewPager.currentItem].attachment.url
val intent = Intent(Intent.ACTION_VIEW)
val extension = MimeTypeMap.getFileExtensionFromUrl(url)
if(extension != null) {
intent.setDataAndType(Uri.parse(url), MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension))
} else {
intent.data = Uri.parse(url)
}
startActivity(intent)
}
private var isCreating: Boolean = false

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_open_in_external_app"
android:icon="@drawable/ic_exit_to_app_24px"
android:title="@string/action_open_in_external_app"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_download"
android:icon="@drawable/ic_file_download_black_24dp"

@ -9,6 +9,7 @@
<string name="action_enable_formatting_syntax">Enable %s</string>
<string name="action_disable_formatting_syntax">Disable %s</string>
<string name="action_sticker">Stickers</string>
<string name="action_open_in_external_app">Open in external app</string>
<string name="title_emoji_reacted_by">%s reacted by</string>

Loading…
Cancel
Save