From 4dd33bc3c7a001c5a4e5e6da1c5a9d50a6e00d42 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 26 Sep 2018 20:42:38 +0200 Subject: use internal viewer for images and videos --- .../messenger/ui/adapter/MessageAdapter.java | 23 ----------- .../java/de/pixart/messenger/ui/util/ViewUtil.java | 46 ++++++++++++++++------ 2 files changed, 34 insertions(+), 35 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index ae124e950..b13ccb910 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -2,7 +2,6 @@ package de.pixart.messenger.ui.adapter; import android.Manifest; import android.app.Activity; -import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -70,7 +69,6 @@ import de.pixart.messenger.services.MessageArchiveService; import de.pixart.messenger.services.NotificationService; import de.pixart.messenger.ui.ConversationFragment; import de.pixart.messenger.ui.ConversationsActivity; -import de.pixart.messenger.ui.ShowFullscreenMessageActivity; import de.pixart.messenger.ui.XmppActivity; import de.pixart.messenger.ui.text.DividerSpan; import de.pixart.messenger.ui.text.QuoteSpan; @@ -1046,27 +1044,6 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie return; } String mime = file.getMimeType(); - if (mime.startsWith("image/")) { - Intent intent = new Intent(getContext(), ShowFullscreenMessageActivity.class); - intent.putExtra("image", Uri.fromFile(file)); - try { - activity.startActivity(intent); - activity.overridePendingTransition(R.animator.fade_in, R.animator.fade_out); - return; - } catch (ActivityNotFoundException e) { - //ignored - } - } else if (mime.startsWith("video/")) { - Intent intent = new Intent(getContext(), ShowFullscreenMessageActivity.class); - intent.putExtra("video", Uri.fromFile(file)); - try { - activity.startActivity(intent); - activity.overridePendingTransition(R.animator.fade_in, R.animator.fade_out); - return; - } catch (ActivityNotFoundException e) { - //ignored - } - } if (mime == null) { mime = "*/*"; } diff --git a/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java b/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java index 2442df8dc..b1905479b 100644 --- a/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java +++ b/src/main/java/de/pixart/messenger/ui/util/ViewUtil.java @@ -15,6 +15,7 @@ import java.util.List; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.persistance.FileBackend; +import de.pixart.messenger.ui.ShowFullscreenMessageActivity; public class ViewUtil { @@ -25,7 +26,6 @@ public class ViewUtil { } public static void view(Context context, File file, String mime) { - Intent openIntent = new Intent(Intent.ACTION_VIEW); Uri uri; try { uri = FileBackend.getUriForFile(context, file); @@ -34,17 +34,39 @@ public class ViewUtil { Toast.makeText(context, context.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show(); return; } - openIntent.setDataAndType(uri, mime); - openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - PackageManager manager = context.getPackageManager(); - List info = manager.queryIntentActivities(openIntent, 0); - if (info.size() == 0) { - openIntent.setDataAndType(uri, "*/*"); - } - try { - context.startActivity(openIntent); - } catch (ActivityNotFoundException e) { - Toast.makeText(context, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + // use internal viewer for images and videos + if (mime.startsWith("image/")) { + Intent intent = new Intent(context, ShowFullscreenMessageActivity.class); + intent.putExtra("image", Uri.fromFile(file)); + try { + context.startActivity(intent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + } else if (mime.startsWith("video/")) { + Intent intent = new Intent(context, ShowFullscreenMessageActivity.class); + intent.putExtra("video", Uri.fromFile(file)); + try { + context.startActivity(intent); + return; + } catch (ActivityNotFoundException e) { + //ignored + } + } else { + Intent openIntent = new Intent(Intent.ACTION_VIEW); + openIntent.setDataAndType(uri, mime); + openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + PackageManager manager = context.getPackageManager(); + List info = manager.queryIntentActivities(openIntent, 0); + if (info.size() == 0) { + openIntent.setDataAndType(uri, "*/*"); + } + try { + context.startActivity(openIntent); + } catch (ActivityNotFoundException e) { + Toast.makeText(context, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + } } } } \ No newline at end of file -- cgit v1.2.3