diff options
author | iNPUTmice <daniel@gultsch.de> | 2015-01-18 13:00:57 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2015-01-18 13:00:57 +0100 |
commit | d58fadd05f303c594c05fca8307e0ac38425b817 (patch) | |
tree | ec019d4c04bdef20fdf3e0724ac5930aae7c94b9 /src/main/java | |
parent | d453e5501b82e1281adf5f047ecabbf0df82d696 (diff) |
use same helper methods for images and files
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java | 41 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/utils/UIHelper.java | 29 |
2 files changed, 16 insertions, 54 deletions
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<Message> { } }); - 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); } |