From c5e35dc4b382564c3e228ea1e1588ec9289ddad4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 12 Jan 2019 10:29:41 +0100 Subject: [PATCH] extend open with to audio files --- .../conversations/ui/ConversationFragment.java | 7 ++++++- .../conversations/ui/adapter/MessageAdapter.java | 12 ++---------- .../eu/siacs/conversations/ui/util/ViewUtil.java | 13 +++++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 84bec2646..16763c329 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -100,6 +100,7 @@ import eu.siacs.conversations.ui.util.ScrollState; import eu.siacs.conversations.ui.util.SendButtonAction; import eu.siacs.conversations.ui.util.SendButtonTool; import eu.siacs.conversations.ui.util.ShareUtil; +import eu.siacs.conversations.ui.util.ViewUtil; import eu.siacs.conversations.ui.widget.EditMessage; import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.GeoHelper; @@ -1135,7 +1136,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (showError) { showErrorMessage.setVisible(true); } - if (m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(),m)) { + final String mime = m.isFileOrImage() ? m.getMimeType() : null; + if ((m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(),m)) || (mime != null && mime.startsWith("audio/"))) { openWith.setVisible(true); } } @@ -1630,6 +1632,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private void openWith(final Message message) { if (message.isGeoUri()) { GeoHelper.view(getActivity(),message); + } else { + final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); + ViewUtil.view(activity, file); } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 800b9c984..a53dd8be1 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -898,16 +898,8 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_OPEN_MESSAGE); return; } - DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); - if (!file.exists()) { - Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); - return; - } - String mime = file.getMimeType(); - if (mime == null) { - mime = "*/*"; - } - ViewUtil.view(activity, file, mime); + final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); + ViewUtil.view(activity, file); } public void showLocation(Message message) { diff --git a/src/main/java/eu/siacs/conversations/ui/util/ViewUtil.java b/src/main/java/eu/siacs/conversations/ui/util/ViewUtil.java index c2f89cba3..013927c4e 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/ViewUtil.java +++ b/src/main/java/eu/siacs/conversations/ui/util/ViewUtil.java @@ -14,6 +14,7 @@ import java.util.List; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.persistance.FileBackend; public class ViewUtil { @@ -24,6 +25,18 @@ public class ViewUtil { view(context, file, mime); } + public static void view (Context context, DownloadableFile file) { + if (!file.exists()) { + Toast.makeText(context, R.string.file_deleted, Toast.LENGTH_SHORT).show(); + return; + } + String mime = file.getMimeType(); + if (mime == null) { + mime = "*/*"; + } + view(context, file, mime); + } + public static void view(Context context, File file, String mime) { Intent openIntent = new Intent(Intent.ACTION_VIEW); Uri uri;