diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/ExpirationTimerView.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/ExpirationTimerView.java index 5a04e77ac2..6765232c77 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/ExpirationTimerView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/ExpirationTimerView.java @@ -1,16 +1,18 @@ package org.thoughtcrime.securesms.conversation.v2.components; import android.content.Context; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.util.AttributeSet; -import network.loki.messenger.R; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import org.session.libsession.utilities.Util; import java.lang.ref.WeakReference; import java.util.concurrent.TimeUnit; +import network.loki.messenger.R; + public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImageView { private long startedAt; @@ -86,10 +88,12 @@ public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImag long progressed = System.currentTimeMillis() - startedAt; long remaining = expiresIn - progressed; - if (remaining < TimeUnit.SECONDS.toMillis(30)) { - return 50; - } else { + if (remaining <= 0) { + return 0; + } else if (remaining < TimeUnit.SECONDS.toMillis(30)) { return 1000; + } else { + return 5000; } } @@ -106,16 +110,20 @@ public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImag ExpirationTimerView timerView = expirationTimerViewReference.get(); if (timerView == null) return; - timerView.setExpirationTime(timerView.startedAt, timerView.expiresIn); - + long nextUpdate = timerView.calculateAnimationDelay(timerView.startedAt, timerView.expiresIn); synchronized (timerView) { - if (!timerView.visible) { + if (timerView.visible) { + timerView.setExpirationTime(timerView.startedAt, timerView.expiresIn); + } else { + timerView.stopped = true; + return; + } + if (nextUpdate <= 0) { timerView.stopped = true; return; } } - - Util.runOnMainDelayed(this, timerView.calculateAnimationDelay(timerView.startedAt, timerView.expiresIn)); + Util.runOnMainDelayed(this, nextUpdate); } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index 5e5b1da220..ac945c5fc4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -217,7 +217,9 @@ class VisibleMessageView : LinearLayout { if (message.expireStarted + message.expiresIn <= System.currentTimeMillis()) { ApplicationContext.getInstance(context).expiringMessageManager.checkSchedule() } - } else if (!message.isOutgoing && !message.isMediaPending) { + } else if (!message.isMediaPending) { + expirationTimerView.setPercentComplete(0.0f) + expirationTimerView.stopAnimation() ThreadUtils.queue { val expirationManager = ApplicationContext.getInstance(context).expiringMessageManager val id = message.getId() @@ -225,6 +227,9 @@ class VisibleMessageView : LinearLayout { if (mms) DatabaseFactory.getMmsDatabase(context).markExpireStarted(id) else DatabaseFactory.getSmsDatabase(context).markExpireStarted(id) expirationManager.scheduleDeletion(id, mms, message.expiresIn) } + } else { + expirationTimerView.stopAnimation() + expirationTimerView.setPercentComplete(0.0f) } } else { expirationTimerView.isVisible = false