From 55dcba6f3689b0e4c2377923889542e1f7ec8d83 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 18 Aug 2020 23:56:22 +0200 Subject: [PATCH] Fix progress of message with attachment --- .../helper/ContentUploadStateTrackerBinder.kt | 13 +++++++++---- .../room/detail/timeline/item/MessageFileItem.kt | 8 +++++++- .../detail/timeline/item/MessageImageVideoItem.kt | 8 +++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt index 0bd59bf2fc..8216d36ac9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt @@ -77,7 +77,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, is ContentUploadStateTracker.State.UploadingThumbnail -> handleProgressThumbnail(state) is ContentUploadStateTracker.State.Encrypting -> handleEncrypting(state) is ContentUploadStateTracker.State.Uploading -> handleProgress(state) - is ContentUploadStateTracker.State.Failure -> handleFailure(state) + is ContentUploadStateTracker.State.Failure -> handleFailure(/*state*/) is ContentUploadStateTracker.State.Success -> handleSuccess() } } @@ -120,6 +120,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isIndeterminate = false progressBar?.progress = percent.toInt() + progressTextView.isVisible = true progressTextView?.text = progressLayout.context.getString(resId) progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.ENCRYPTING)) } @@ -132,19 +133,23 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, progressBar?.isVisible = true progressBar?.isIndeterminate = false progressBar?.progress = percent.toInt() + progressTextView.isVisible = true progressTextView?.text = progressLayout.context.getString(resId, TextUtils.formatFileSize(progressLayout.context, current, true), TextUtils.formatFileSize(progressLayout.context, total, true)) progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.SENDING)) } - private fun handleFailure(state: ContentUploadStateTracker.State.Failure) { + private fun handleFailure(/*state: ContentUploadStateTracker.State.Failure*/) { progressLayout.visibility = View.VISIBLE val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isVisible = false - progressTextView?.text = errorFormatter.toHumanReadable(state.throwable) - progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.UNDELIVERED)) + // Do not show the message it's too technical for users, and unfortunate when upload is cancelled + // in the middle by turning airplane mode for example + progressTextView.isVisible = false +// progressTextView?.text = errorFormatter.toHumanReadable(state.throwable) +// progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.UNDELIVERED)) } private fun handleSuccess() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt index 1f3c6147ae..5160a7cd84 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -28,6 +28,7 @@ import com.airbnb.epoxy.EpoxyModelClass import im.vector.app.R import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder +import org.matrix.android.sdk.api.session.room.send.SendState @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageFileItem : AbsMessageItem() { @@ -87,7 +88,12 @@ abstract class MessageFileItem : AbsMessageItem() { holder.fileImageWrapper.setOnLongClickListener(attributes.itemLongClickListener) holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG) - holder.eventSendingIndicator.isVisible = attributes.informationData.sendState.isInProgress() + holder.eventSendingIndicator.isVisible = when (attributes.informationData.sendState) { + SendState.UNSENT, + SendState.ENCRYPTING, + SendState.SENDING -> true + else -> false + } } override fun unbind(holder: Holder) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index 87c7e17fd5..9ada087207 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -28,6 +28,7 @@ import im.vector.app.R import im.vector.app.core.glide.GlideApp import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder import im.vector.app.features.media.ImageContentRenderer +import org.matrix.android.sdk.api.session.room.send.SendState @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageImageVideoItem : AbsMessageItem() { @@ -62,7 +63,12 @@ abstract class MessageImageVideoItem : AbsMessageItem true + else -> false + } } override fun unbind(holder: Holder) {