From ea7768674687fac0c313ecd0f520bed0a23d925e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 8 Jul 2019 14:46:14 +0200 Subject: [PATCH] Send file: cleanup --- .../content/ContentUploadStateTracker.kt | 4 +- .../DefaultContentUploadStateTracker.kt | 4 +- .../helper/ContentUploadStateTrackerBinder.kt | 53 +++++++++---------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/content/ContentUploadStateTracker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/content/ContentUploadStateTracker.kt index 83074525..26273ebb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/content/ContentUploadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/content/ContentUploadStateTracker.kt @@ -29,9 +29,9 @@ interface ContentUploadStateTracker { sealed class State { object Idle : State() object EncryptingThumbnail : State() - data class ProgressThumbnailData(val current: Long, val total: Long) : State() + data class UploadingThumbnail(val current: Long, val total: Long) : State() object Encrypting : State() - data class ProgressData(val current: Long, val total: Long) : State() + data class Uploading(val current: Long, val total: Long) : State() object Success : State() data class Failure(val throwable: Throwable) : State() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt index 391a90f1..4bb58fe7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt @@ -59,7 +59,7 @@ internal class DefaultContentUploadStateTracker @Inject constructor() : ContentU } internal fun setProgressThumbnail(key: String, current: Long, total: Long) { - val progressData = ContentUploadStateTracker.State.ProgressThumbnailData(current, total) + val progressData = ContentUploadStateTracker.State.UploadingThumbnail(current, total) updateState(key, progressData) } @@ -69,7 +69,7 @@ internal class DefaultContentUploadStateTracker @Inject constructor() : ContentU } internal fun setProgress(key: String, current: Long, total: Long) { - val progressData = ContentUploadStateTracker.State.ProgressData(current, total) + val progressData = ContentUploadStateTracker.State.Uploading(current, total) updateState(key, progressData) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt index a431d409..5df8d38b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt @@ -26,7 +26,6 @@ import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.features.media.ImageContentRenderer -import java.io.File import javax.inject.Inject class ContentUploadStateTrackerBinder @Inject constructor(private val activeSessionHolder: ActiveSessionHolder) { @@ -61,48 +60,43 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, override fun onUpdate(state: ContentUploadStateTracker.State) { when (state) { - is ContentUploadStateTracker.State.Idle -> handleIdle(state) - is ContentUploadStateTracker.State.EncryptingThumbnail -> handleEncryptingThumbnail(state) - is ContentUploadStateTracker.State.ProgressThumbnailData -> handleProgressThumbnail(state) - is ContentUploadStateTracker.State.Encrypting -> handleEncrypting(state) - is ContentUploadStateTracker.State.ProgressData -> handleProgress(state) - is ContentUploadStateTracker.State.Failure -> handleFailure(state) - is ContentUploadStateTracker.State.Success -> handleSuccess(state) + is ContentUploadStateTracker.State.Idle -> handleIdle(state) + is ContentUploadStateTracker.State.EncryptingThumbnail -> handleEncryptingThumbnail(state) + 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.Success -> handleSuccess(state) } } private fun handleIdle(state: ContentUploadStateTracker.State.Idle) { - if (mediaData.isLocalFile()) { - val file = File(mediaData.url) - progressLayout.visibility = View.VISIBLE - val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) - val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) - progressBar?.isVisible = true - progressBar?.isIndeterminate = true - progressBar?.progress = 0 - progressTextView?.text = progressLayout.context.getString(R.string.send_file_step_idle) - } else { - progressLayout.visibility = View.GONE - } + progressLayout.visibility = View.VISIBLE + val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) + val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) + progressBar?.isVisible = true + progressBar?.isIndeterminate = true + progressBar?.progress = 0 + progressTextView?.text = progressLayout.context.getString(R.string.send_file_step_idle) } private fun handleEncryptingThumbnail(state: ContentUploadStateTracker.State.EncryptingThumbnail) { - _handleEncrypting(R.string.send_file_step_encrypting_thumbnail) + doHandleEncrypting(R.string.send_file_step_encrypting_thumbnail) } - private fun handleProgressThumbnail(state: ContentUploadStateTracker.State.ProgressThumbnailData) { - _handleProgress(R.string.send_file_step_sending_thumbnail, state.current, state.total) + private fun handleProgressThumbnail(state: ContentUploadStateTracker.State.UploadingThumbnail) { + doHandleProgress(R.string.send_file_step_sending_thumbnail, state.current, state.total) } private fun handleEncrypting(state: ContentUploadStateTracker.State.Encrypting) { - _handleEncrypting(R.string.send_file_step_encrypting_file) + doHandleEncrypting(R.string.send_file_step_encrypting_file) } - private fun handleProgress(state: ContentUploadStateTracker.State.ProgressData) { - _handleProgress(R.string.send_file_step_sending_file, state.current, state.total) + private fun handleProgress(state: ContentUploadStateTracker.State.Uploading) { + doHandleProgress(R.string.send_file_step_sending_file, state.current, state.total) } - private fun _handleEncrypting(resId: Int) { + private fun doHandleEncrypting(resId: Int) { progressLayout.visibility = View.VISIBLE val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) @@ -110,7 +104,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, progressTextView?.text = progressLayout.context.getString(resId) } - private fun _handleProgress(resId: Int, current: Long, total: Long) { + private fun doHandleProgress(resId: Int, current: Long, total: Long) { progressLayout.visibility = View.VISIBLE val percent = 100L * (current.toFloat() / total.toFloat()) val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) @@ -128,10 +122,11 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isVisible = false + // TODO Red text progressTextView?.text = state.throwable.localizedMessage } private fun handleSuccess(state: ContentUploadStateTracker.State.Success) { - // Nothing to do + progressLayout.visibility = View.GONE } }