mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Attachment download progress view fixes.
This commit is contained in:
committed by
Clark Chen
parent
b434e955ac
commit
e2fe137b05
@@ -25,17 +25,17 @@ import org.thoughtcrime.securesms.databinding.TransferControlsViewBinding
|
||||
import org.thoughtcrime.securesms.events.PartProgressEvent
|
||||
import org.thoughtcrime.securesms.mms.Slide
|
||||
import org.thoughtcrime.securesms.util.MediaUtil
|
||||
import org.thoughtcrime.securesms.util.ThrottledDebouncer
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture
|
||||
import org.thoughtcrime.securesms.util.visible
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
class TransferControlView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||
private val uuid = UUID.randomUUID().toString()
|
||||
private val binding: TransferControlsViewBinding
|
||||
|
||||
private var state = TransferControlViewState()
|
||||
private val progressUpdateDebouncer: ThrottledDebouncer = ThrottledDebouncer(100)
|
||||
|
||||
init {
|
||||
tag = uuid
|
||||
@@ -58,8 +58,10 @@ class TransferControlView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
|
||||
private fun updateState(stateFactory: (TransferControlViewState) -> TransferControlViewState) {
|
||||
val newState = stateFactory.invoke(state)
|
||||
if (newState != state) {
|
||||
applyState(newState)
|
||||
if (newState != state && !(deriveMode(state) == Mode.GONE && deriveMode(newState) == Mode.GONE)) {
|
||||
progressUpdateDebouncer.publish {
|
||||
applyState(newState)
|
||||
}
|
||||
}
|
||||
state = newState
|
||||
}
|
||||
@@ -434,7 +436,7 @@ class TransferControlView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
private fun displayChildrenAsGone() {
|
||||
children.forEach {
|
||||
if (it.visible && it.animation == null) {
|
||||
ViewUtil.fadeOut(it, 250).addListener(AnimationCleanup(it))
|
||||
ViewUtil.fadeOut(it, 250)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -642,8 +644,8 @@ class TransferControlView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
}
|
||||
|
||||
private fun isCompressing(state: TransferControlViewState): Boolean {
|
||||
// We never get a completion event so it never actually reaches 100%
|
||||
return state.compressionProgress.sumTotal() > 0 && state.compressionProgress.values.map { it.completed.toFloat() / it.total }.sum() < 0.99f
|
||||
val total = state.compressionProgress.sumTotal()
|
||||
return total > 0 && state.compressionProgress.sumCompleted() / total < 0.99f
|
||||
}
|
||||
|
||||
private fun calculateProgress(state: TransferControlViewState): Float {
|
||||
@@ -740,14 +742,4 @@ class TransferControlView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
RETRY_UPLOADING,
|
||||
GONE
|
||||
}
|
||||
|
||||
private class AnimationCleanup(val animatedView: View) : ListenableFuture.Listener<Boolean> {
|
||||
override fun onSuccess(result: Boolean?) {
|
||||
animatedView.clearAnimation()
|
||||
}
|
||||
|
||||
override fun onFailure(e: ExecutionException?) {
|
||||
animatedView.clearAnimation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,11 @@ public final class AttachmentCompressionJob extends BaseJob {
|
||||
}, outputStream, cancelationSignal);
|
||||
}
|
||||
|
||||
eventBus.postSticky(new PartProgressEvent(attachment,
|
||||
PartProgressEvent.Type.COMPRESSION,
|
||||
100,
|
||||
100));
|
||||
|
||||
try (MediaStream mediaStream = new MediaStream(ModernDecryptingPartInputStream.createFor(attachmentSecret, file, 0), MimeTypes.VIDEO_MP4, 0, 0)) {
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user