diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-02-01 14:04:10 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-02-01 14:04:10 +0100 |
commit | 857539eac36e5e8a31fce490e7519edd80950f67 (patch) | |
tree | 34b8ad18a49f4d9de487e8ec41146d2d74abaf7c /src | |
parent | 94d125945c980f54579d59d35ac36ed676ce4b34 (diff) |
show progressbar instead of percentages while up-/downloading files
Diffstat (limited to '')
5 files changed, 66 insertions, 17 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java index 440fc959b..e02c92456 100644 --- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java @@ -501,7 +501,7 @@ public class HttpDownloadConnection implements Transferable { throw new FileWriterException(); } } catch (CancellationException e) { - Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": http download failed", e); + Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": http download canceled", e); throw e; } catch (IOException e) { Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": http download failed", e); 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 dee202a5f..a31a4d8f7 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -33,6 +33,7 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -102,8 +103,6 @@ import static de.pixart.messenger.ui.util.MyLinkify.replaceYoutube; public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler { - //private ConversationFragment mConversationFragment; - public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR"; private static final int SENT = 0; private static final int RECEIVED = 1; @@ -248,29 +247,35 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie switch (message.getMergedStatus()) { case Message.STATUS_WAITING: info = getContext().getString(R.string.waiting); + viewHolder.progressBar.setVisibility(View.GONE); break; case Message.STATUS_UNSEND: if (transferable != null) { - info = getContext().getString(R.string.sending_file, transferable.getProgress()); + info = getContext().getString(R.string.sending); + showProgressBar(viewHolder, transferable); } else { info = getContext().getString(R.string.sending); } break; case Message.STATUS_OFFERED: info = getContext().getString(R.string.offering); + viewHolder.progressBar.setVisibility(View.GONE); break; case Message.STATUS_SEND_RECEIVED: if (mIndicateReceived) { viewHolder.indicatorReceived.setVisibility(View.VISIBLE); } + viewHolder.progressBar.setVisibility(View.GONE); break; case Message.STATUS_SEND_DISPLAYED: if (mIndicateReceived) { viewHolder.indicatorReceived.setVisibility(View.VISIBLE); viewHolder.indicatorRead.setVisibility(View.VISIBLE); } + viewHolder.progressBar.setVisibility(View.GONE); break; case Message.STATUS_SEND_FAILED: + viewHolder.progressBar.setVisibility(View.GONE); DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); if (isResendable && file.exists()) { info = getContext().getString(R.string.send_failed_resend); @@ -301,6 +306,13 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie error = true; break; default: + if (transferable == null) { + viewHolder.progressBar.setVisibility(View.GONE); + } else if (transferable.getStatus() != Transferable.STATUS_DOWNLOADING) { + viewHolder.progressBar.setVisibility(View.GONE); + } else { + viewHolder.progressBar.setVisibility(View.VISIBLE); + } if (multiReceived) { info = UIHelper.getMessageDisplayName(message); } @@ -314,7 +326,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); if (file.exists()) { - if (activity.xmppConnectionService.mHttpConnectionManager.getAutoAcceptFileSize() >= message.getFileParams().size) { + if (activity.xmppConnectionService.mHttpConnectionManager.getAutoAcceptFileSize() >= message.getFileParams().size && (transferable != null && transferable.getStatus() == Transferable.STATUS_FAILED)) { isResendable = true; viewHolder.resend_button.setVisibility(View.GONE); } else { @@ -395,7 +407,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } } - private void displayInfoMessage(ViewHolder viewHolder, CharSequence text, boolean darkBackground) { + private void displayInfoMessage(ViewHolder viewHolder, CharSequence text, boolean darkBackground, Message message) { viewHolder.download_button.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); @@ -403,6 +415,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.richlinkview.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); viewHolder.messageBody.setText(text); + showProgressBar(viewHolder, message.getTransferable()); if (darkBackground) { viewHolder.messageBody.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Body1_Secondary_OnDark); } else { @@ -411,6 +424,22 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.messageBody.setTextIsSelectable(false); } + private void showProgressBar(final ViewHolder viewHolder, final Transferable transferable) { + if (transferable != null) { + if (transferable.getStatus() == Transferable.STATUS_DOWNLOADING) { + viewHolder.progressBar.setVisibility(View.VISIBLE); + viewHolder.progressBar.setProgress(transferable.getProgress()); + } else if (transferable.getStatus() == Transferable.STATUS_UPLOADING) { + viewHolder.progressBar.setVisibility(View.VISIBLE); + viewHolder.progressBar.setProgress(transferable.getProgress()); + } else { + viewHolder.progressBar.setVisibility(View.GONE); + } + } else { + viewHolder.progressBar.setVisibility(View.GONE); + } + } + private void displayEmojiMessage(final ViewHolder viewHolder, final String body, final boolean darkBackground) { viewHolder.download_button.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); @@ -1017,6 +1046,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.time = view.findViewById(R.id.message_time); viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received); viewHolder.indicatorRead = view.findViewById(R.id.indicator_read); + viewHolder.progressBar = view.findViewById(R.id.progressBar); break; case RECEIVED: view = activity.getLayoutInflater().inflate(R.layout.message_received, parent, false); @@ -1035,6 +1065,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.time = view.findViewById(R.id.message_time); viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received); viewHolder.encryption = view.findViewById(R.id.message_encryption); + viewHolder.progressBar = view.findViewById(R.id.progressBar); break; case STATUS: view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false); @@ -1130,7 +1161,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie if (checkFileExistence(message, view, viewHolder)) { markFileExisting(message); } else { - displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground); + displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground, message); } } } else if (message.isFileOrImage() && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { @@ -1144,21 +1175,21 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (account.isPgpDecryptionServiceConnected()) { if (conversation instanceof Conversation && !account.hasPendingPgpIntent((Conversation) conversation)) { - displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground); + displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground, message); } else { - displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground); + displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground, message); } } else { - displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground); + displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground, message); viewHolder.message_box.setOnClickListener(this::promptOpenKeychainInstall); viewHolder.messageBody.setOnClickListener(this::promptOpenKeychainInstall); } } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { - displayInfoMessage(viewHolder, activity.getString(R.string.decryption_failed), darkBackground); + displayInfoMessage(viewHolder, activity.getString(R.string.decryption_failed), darkBackground, message); } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) { - displayInfoMessage(viewHolder, activity.getString(R.string.not_encrypted_for_this_device), darkBackground); + displayInfoMessage(viewHolder, activity.getString(R.string.not_encrypted_for_this_device), darkBackground, message); } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_FAILED) { - displayInfoMessage(viewHolder, activity.getString(R.string.omemo_decryption_failed), darkBackground); + displayInfoMessage(viewHolder, activity.getString(R.string.omemo_decryption_failed), darkBackground, message); } else { if (message.isGeoUri()) { displayLocationMessage(viewHolder, message, darkBackground); @@ -1200,7 +1231,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie if (type == RECEIVED) { if (message.isPrivateMessage()) { viewHolder.answer_button.setVisibility(View.VISIBLE); - viewHolder.answer_button.setImageResource(R.drawable.ic_reply_circle_black_24dp); + Drawable icon = activity.getResources().getDrawable(R.drawable.ic_reply_circle_black_24dp); + Drawable drawable = DrawableCompat.wrap(icon); + DrawableCompat.setTint(drawable, StyledAttributes.getColor(getContext(), R.attr.colorAccent)); + viewHolder.answer_button.setImageDrawable(drawable); viewHolder.answer_button.setOnClickListener(v -> { try { if (activity instanceof ConversationsActivity) { @@ -1381,6 +1415,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie protected ImageView contact_picture; protected TextView status_message; protected TextView encryption; + protected ProgressBar progressBar; } private class MessageBodyActionModeCallback implements ActionMode.Callback { diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index c74b34d41..fe933f8ac 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -263,9 +263,8 @@ public class UIHelper { return new Pair<>(context.getString(R.string.checking_x, getFileDescriptionString(context, message)), true); case Transferable.STATUS_DOWNLOADING: - return new Pair<>(context.getString(R.string.receiving_x_file, - getFileDescriptionString(context, message), - d.getProgress()), true); + return new Pair<>(context.getString(R.string.receiving_file, + getFileDescriptionString(context, message)), true); case Transferable.STATUS_OFFER: case Transferable.STATUS_OFFER_CHECK_FILESIZE: return new Pair<>(context.getString(R.string.x_file_offered_for_download, diff --git a/src/main/res/layout/message_content.xml b/src/main/res/layout/message_content.xml index 2e494e914..3d64aa189 100644 --- a/src/main/res/layout/message_content.xml +++ b/src/main/res/layout/message_content.xml @@ -92,6 +92,20 @@ android:progress="100" /> </RelativeLayout> + <ProgressBar + android:id="@+id/progressBar" + style="?android:attr/progressBarStyleHorizontal" + android:layout_width="match_parent" + android:layout_height="5dp" + android:layout_alignParentStart="true" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:indeterminate="false" + android:max="100" + android:minWidth="50dp" + android:progress="1" + android:visibility="gone" /> + <ImageButton android:id="@+id/answer" android:layout_width="wrap_content" diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2c7683112..de702e3c1 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -311,6 +311,7 @@ <string name="notification_restored_backup_subtitle">Do not forget to enable the account.</string> <string name="choose_file">Choose file</string> <string name="receiving_x_file">Receiving %1$s (%2$d%% completed)</string> + <string name="receiving_file">Receiving %1$s</string> <string name="download_x_file">Download %s</string> <string name="delete_x_file">Delete %s</string> <string name="file">file</string> |