From d58fadd05f303c594c05fca8307e0ac38425b817 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 18 Jan 2015 13:00:57 +0100 Subject: use same helper methods for images and files --- .../conversations/ui/adapter/MessageAdapter.java | 41 +++++----------------- .../eu/siacs/conversations/utils/UIHelper.java | 29 +++++---------- src/main/res/values/strings.xml | 10 ++---- 3 files changed, 19 insertions(+), 61 deletions(-) (limited to 'src') 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 a1361fa1..1d8b2e44 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -487,39 +487,14 @@ public class MessageAdapter extends ArrayAdapter { } }); - if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) { - Downloadable d = message.getDownloadable(); - if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) { - if (message.getType() == Message.TYPE_FILE) { - displayInfoMessage(viewHolder,activity.getString(R.string.receiving_x_file, - UIHelper.getFileDescriptionString(activity,message), - d.getProgress())); - } else { - displayInfoMessage(viewHolder,activity.getString(R.string.receiving_image,d.getProgress())); - } - } else if (d.getStatus() == Downloadable.STATUS_CHECKING) { - displayInfoMessage(viewHolder,activity.getString(R.string.checking_image)); - } else if (d.getStatus() == Downloadable.STATUS_DELETED) { - if (message.getType() == Message.TYPE_FILE) { - displayInfoMessage(viewHolder, activity.getString(R.string.file_deleted)); - } else { - displayInfoMessage(viewHolder, activity.getString(R.string.image_file_deleted)); - } - } else if (d.getStatus() == Downloadable.STATUS_OFFER) { - if (message.getType() == Message.TYPE_FILE) { - displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, - UIHelper.getFileDescriptionString(activity,message))); - } else { - displayDownloadableMessage(viewHolder, message,activity.getString(R.string.download_image)); - } - } else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) { - displayDownloadableMessage(viewHolder, message,activity.getString(R.string.check_image_filesize)); - } else if (d.getStatus() == Downloadable.STATUS_FAILED) { - if (message.getType() == Message.TYPE_FILE) { - displayInfoMessage(viewHolder, activity.getString(R.string.file_transmission_failed)); - } else { - displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed)); - } + final Downloadable downloadable = message.getDownloadable(); + if (downloadable != null && downloadable.getStatus() != Downloadable.STATUS_UPLOADING) { + if (downloadable.getStatus() == Downloadable.STATUS_OFFER) { + displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message))); + } else if (downloadable.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) { + displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_image_filesize)); + } else { + displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first); } } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { displayImageMessage(viewHolder, message); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index b2ca8e4a..d1a4b4a9 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -118,33 +118,17 @@ public class UIHelper { case Downloadable.STATUS_CHECKING: return new Pair<>(context.getString(R.string.checking_image),true); case Downloadable.STATUS_DOWNLOADING: - if (message.getType() == Message.TYPE_FILE) { - return new Pair<>(context.getString(R.string.receiving_x_file, + return new Pair<>(context.getString(R.string.receiving_x_file, getFileDescriptionString(context,message), d.getProgress()),true); - } else { - return new Pair<>(context.getString(R.string.receiving_image, d.getProgress()),true); - } case Downloadable.STATUS_OFFER: case Downloadable.STATUS_OFFER_CHECK_FILESIZE: - if (message.getType() == Message.TYPE_FILE) { - return new Pair<>(context.getString(R.string.x_file_offered_for_download, + return new Pair<>(context.getString(R.string.x_file_offered_for_download, getFileDescriptionString(context,message)),true); - } else { - return new Pair<>(context.getString(R.string.image_offered_for_download),true); - } case Downloadable.STATUS_DELETED: - if (message.getType() == Message.TYPE_FILE) { - return new Pair<>(context.getString(R.string.file_deleted),true); - } else { - return new Pair<>(context.getString(R.string.image_file_deleted),true); - } + return new Pair<>(context.getString(R.string.file_deleted),true); case Downloadable.STATUS_FAILED: - if (message.getType() == Message.TYPE_FILE) { - return new Pair<>(context.getString(R.string.file_transmission_failed),true); - } else { - return new Pair<>(context.getString(R.string.image_transmission_failed),true); - } + return new Pair<>(context.getString(R.string.file_transmission_failed),true); default: return new Pair<>("",false); } @@ -167,13 +151,16 @@ public class UIHelper { } public static String getFileDescriptionString(final Context context, final Message message) { + if (message.getType() == Message.TYPE_IMAGE) { + return context.getString(R.string.image); + } final String path = message.getRelativeFilePath(); if (path == null) { return ""; } final String mime; try { - mime = URLConnection.guessContentTypeFromName(path); + mime = URLConnection.guessContentTypeFromName(path.replace("#","")); } catch (final StringIndexOutOfBoundsException ignored) { return context.getString(R.string.file); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 8baf794a..c50355ed 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -72,7 +72,6 @@ Add contact delivery failed rejected - Receiving image file (%1$d%%) Preparing image for transmission Clear history Clear Conversation History @@ -85,7 +84,6 @@ Send OpenPGP encrypted message Your nickname has been changed Download Image - Image file offered for download Send unencrypted Decryption failed. Maybe you don’t have the proper private key. OpenKeychain @@ -99,8 +97,6 @@ No OpenPGP Keys found Conversations is unable to encrypt your messages because your contacts are not announcing their public key.\n\nPlease ask your contacts to setup OpenPGP. Encrypted message received. Touch to view and decrypt. - Encrypted image received. Touch to view and decrypt. - Image received. Touch to view General XMPP resource The name this client identifies itself with @@ -437,9 +433,9 @@ Use enter key to send message Show enter key Change the emoticons key to an enter key - audio file - video file - image file + audio + video + image PDF document Android App Contact -- cgit v1.2.3