From da9352cc68f0aa55ba2ab464360206b1eecd113b Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Tue, 27 Oct 2020 14:28:15 +0100 Subject: [PATCH] Offer opening unsupported filetypes with external app --- .../ui/findcontent/FileViewFragment.java | 20 +++++++++++++++++++ .../main/res/layout/fragment_file_view.xml | 7 +++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 28 insertions(+) diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index 78d26966..e45e0c9a 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -1522,6 +1522,12 @@ public class FileViewFragment extends BaseFragment implements onMainActionButtonClicked(); } }); + root.findViewById(R.id.file_view_open_external_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + openClaimExternally(claim, claim.getMediaType()); + } + }); if (metadata instanceof Claim.StreamMetadata) { Claim.StreamMetadata streamMetadata = (Claim.StreamMetadata) metadata; @@ -2069,6 +2075,8 @@ public class FileViewFragment extends BaseFragment implements } handled = true; } + } else { + openClaimExternally(claim, mediaType); } } @@ -2155,6 +2163,18 @@ public class FileViewFragment extends BaseFragment implements " "; } + private void openClaimExternally(Claim claim, String mediaType) { + File file = new File(claim.getFile().getDownloadPath()); + Uri fileUri = Uri.parse(claim.getFile().getDownloadPath()); + + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.setDataAndType(fileUri, mediaType.toLowerCase()); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Intent chooser = Intent.createChooser(intent, getString(R.string.choose_app)); + startActivityForResult(chooser, 419); + } + public void showError(String message) { View root = getView(); if (root != null) { diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index 810a81ff..eb8be245 100644 --- a/app/src/main/res/layout/fragment_file_view.xml +++ b/app/src/main/res/layout/fragment_file_view.xml @@ -157,6 +157,13 @@ android:textFontWeight="300" android:layout_width="wrap_content" android:layout_height="wrap_content" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65537a8a..6a77488d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,6 +91,7 @@ Please select a channel to repost on. Reply Replying to %1$s + Choose app Post and tip %1$s credit? Post and tip %1$s credits?