diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-09-29 11:57:16 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-09-29 11:57:16 +0200 |
commit | 34fcdda53fa8ae1174909b62860534d2d874eb72 (patch) | |
tree | 50564c1d946ef1779567c67ad25a646b446a6403 /src/main/java/de/thedevstack/conversationsplus/ui/adapter | |
parent | 297bed106efdfa619d700ae44ce047d7f2663c93 (diff) |
Implements FS#235: Deletion of remote files uploaded via httpupload
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java | 2 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java | 65 |
2 files changed, 52 insertions, 15 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java index e28774f2..98a9a96c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java @@ -90,7 +90,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { convName.setTypeface(null, Typeface.NORMAL); } - if (message.getFileParams().width > 0 + if ((null != message.getFileParams() && message.getFileParams().getWidth() > 0) // TODO: Use FileParams.getMimeType() && (message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) { mLastMessage.setVisibility(View.GONE); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java index b2dca6b9..e93ddbfa 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java @@ -20,6 +20,7 @@ import android.text.style.StyleSpan; import android.text.util.Linkify; import android.util.DisplayMetrics; import android.util.Patterns; +import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; @@ -46,15 +47,17 @@ import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Conversation; import de.thedevstack.conversationsplus.entities.DownloadableFile; +import de.thedevstack.conversationsplus.entities.FileParams; import de.thedevstack.conversationsplus.entities.Message; -import de.thedevstack.conversationsplus.entities.Message.FileParams; import de.thedevstack.conversationsplus.entities.Transferable; +import de.thedevstack.conversationsplus.enums.FileStatus; import de.thedevstack.conversationsplus.persistance.FileBackend; import de.thedevstack.conversationsplus.providers.ConversationsPlusFileProvider; import de.thedevstack.conversationsplus.services.AvatarService; import de.thedevstack.conversationsplus.ui.ConversationActivity; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.GeoHelper; +import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.utils.UIHelper; public class MessageAdapter extends ArrayAdapter<Message> { @@ -138,13 +141,17 @@ public class MessageAdapter extends ArrayAdapter<Message> { boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI && message.getStatus() <= Message.STATUS_RECEIVED; - if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) { + if (message.hasFileAttached() || message.getTransferable() != null) { FileParams params = message.getFileParams(); - if (params.size > (1.5 * 1024 * 1024)) { - filesize = params.size / (1024 * 1024)+ " MiB"; - } else if (params.size > 0) { - filesize = params.size / 1024 + " KiB"; - } + if (null != params) { + long size = params.getSize(); + if (size > (1.5 * 1024 * 1024)) { + filesize = size / (1024 * 1024)+ " MiB"; + } else if (size > 0) { + filesize = size / 1024 + " KiB"; + } + } + if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) { error = true; } @@ -247,6 +254,25 @@ public class MessageAdapter extends ArrayAdapter<Message> { viewHolder.time.setText(formatedTime); } } + + if (message.hasFileAttached() && null != message.getFileParams() && null != viewHolder.remoteFileStatus) { + FileStatus fileStatus = message.getFileParams().getFileStatus(); + if (fileStatus == FileStatus.DELETE_FAILED || fileStatus == FileStatus.DELETED || fileStatus == FileStatus.DELETING) { + viewHolder.remoteFileStatus.setVisibility(View.VISIBLE); + viewHolder.remoteFileStatus.setTypeface(null, Typeface.ITALIC); + switch (fileStatus) { + case DELETE_FAILED: + viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_failed); + break; + case DELETED: + viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_success); + break; + case DELETING: + viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_inprogress); + break; + } + } + } } private void displayInfoMessage(ViewHolder viewHolder, String text, boolean darkBackground) { @@ -434,9 +460,10 @@ public class MessageAdapter extends ArrayAdapter<Message> { } viewHolder.messageBody.setVisibility(View.GONE); viewHolder.image.setVisibility(View.VISIBLE); - FileParams params = message.getFileParams(); //TODO: Check what value add the following lines have (compared with setting height/width in XmppActivity.loadBitmap from thumbnail after thumbnail is created) - /*double target = metrics.density * 288; + /* + FileParams params = message.getFileParams(); + double target = metrics.density * 288; int scalledW; int scalledH; if (params.width <= params.height) { @@ -491,6 +518,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_time); viewHolder.indicatorReceived = (ImageView) view .findViewById(R.id.indicator_received); + viewHolder.remoteFileStatus = (TextView) view.findViewById(R.id.remote_file_status); break; case RECEIVED: view = activity.getLayoutInflater().inflate( @@ -585,7 +613,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { displayImageMessage(viewHolder, message); } else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { - if (message.getFileParams().width > 0) { + if (message.getFileParams() != null && message.getFileParams().getWidth() > 0) { // TODO Use FileParams.getMimeType() displayImageMessage(viewHolder,message); } else { displayOpenableMessage(viewHolder, message); @@ -612,12 +640,20 @@ public class MessageAdapter extends ArrayAdapter<Message> { } } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { displayDecryptionFailed(viewHolder,darkBackground); - } else { + } else if (message.hasFileAttached()) { // TODO: Move to a single block with Message.TYPE_FILE OR Message.TYPE_IMAGE + FileParams fileParams = message.getFileParams(); + String mimeType = (null != fileParams) ? fileParams.getMimeType() : null; + if (null != mimeType && mimeType.startsWith("image/")) { + displayImageMessage(viewHolder, message); + } else { + displayOpenableMessage(viewHolder, message); + } + } else { if (GeoHelper.isGeoUri(message.getBody())) { displayLocationMessage(viewHolder,message); - } else if (message.treatAsDownloadable() == Message.Decision.MUST) { + } else if (MessageUtil.needsDownload(message)) { try { - URL url = new URL(message.getBody()); + URL url = new URL(message.getFileParams().getUrl()); displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize_on_host, @@ -724,7 +760,8 @@ public class MessageAdapter extends ArrayAdapter<Message> { protected ImageView contact_picture; protected TextView status_message; protected TextView encryption; - } + public TextView remoteFileStatus; + } class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { private final WeakReference<ImageView> imageViewReference; |