Merge pull request #1045 from kekkyojin/open-file-external

Offer opening unsupported filetypes with external app
This commit is contained in:
Akinwale Ariwodola 2020-11-13 15:42:59 +01:00 committed by GitHub
commit 896c566a02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -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
" </html>";
}
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) {

View file

@ -157,6 +157,13 @@
android:textFontWeight="300"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.button.MaterialButton
android:id="@+id/file_view_open_external_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/inter"
android:textSize="14sp"
android:text="@string/open" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

View file

@ -91,6 +91,7 @@
<string name="please_select_repost_channel">Please select a channel to repost on.</string>
<string name="reply">Reply</string>
<string name="replying_to">Replying to %1$s</string>
<string name="choose_app">Choose app</string>
<plurals name="post_and_tip">
<item quantity="one">Post and tip %1$s credit?</item>
<item quantity="other">Post and tip %1$s credits?</item>