This commit is contained in:
fanchao 2024-05-22 10:54:56 +10:00
parent 75e53c86b1
commit c7c0519a20
2 changed files with 24 additions and 9 deletions

View File

@ -4,8 +4,6 @@ import android.animation.FloatEvaluator
import android.animation.IntEvaluator import android.animation.IntEvaluator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.ImageView import android.widget.ImageView
@ -25,10 +23,12 @@ import java.util.Date
class InputBarRecordingView : RelativeLayout { class InputBarRecordingView : RelativeLayout {
private lateinit var binding: ViewInputBarRecordingBinding private lateinit var binding: ViewInputBarRecordingBinding
private var startTimestamp = 0L private var startTimestamp = 0L
private val snHandler = Handler(Looper.getMainLooper())
private var dotViewAnimation: ValueAnimator? = null private var dotViewAnimation: ValueAnimator? = null
private var pulseAnimation: ValueAnimator? = null private var pulseAnimation: ValueAnimator? = null
var delegate: InputBarRecordingViewDelegate? = null var delegate: InputBarRecordingViewDelegate? = null
private val updateTimerRunnable = Runnable {
updateTimer()
}
val lockView: LinearLayout val lockView: LinearLayout
get() = binding.lockView get() = binding.lockView
@ -134,9 +134,21 @@ class InputBarRecordingView : RelativeLayout {
binding.recordingViewDurationTextView.text = DateUtils.formatElapsedTime(duration) binding.recordingViewDurationTextView.text = DateUtils.formatElapsedTime(duration)
if (isAttachedToWindow) { if (isAttachedToWindow) {
// Make sure there's only one runnable in the handler at a time.
removeCallbacks(updateTimerRunnable)
// Should only update the timer if the view is still attached to the window. // Should only update the timer if the view is still attached to the window.
// Otherwise, the timer will keep running even after the view is detached. // Otherwise, the timer will keep running even after the view is detached.
snHandler.postDelayed({ updateTimer() }, 500) postDelayed(updateTimerRunnable, 500)
}
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (isVisible) {
// If the view was visible (i.e. recording) when it was detached, start the timer again.
updateTimer()
} }
} }

View File

@ -6,7 +6,6 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.util.AttributeSet import android.util.AttributeSet
import android.util.TypedValue import android.util.TypedValue
import android.view.Gravity import android.view.Gravity
@ -21,7 +20,6 @@ import network.loki.messenger.R
import network.loki.messenger.databinding.ActivityPathBinding import network.loki.messenger.databinding.ActivityPathBinding
import org.session.libsession.snode.OnionRequestAPI import org.session.libsession.snode.OnionRequestAPI
import org.session.libsession.utilities.getColorFromAttr import org.session.libsession.utilities.getColorFromAttr
import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.Snode import org.session.libsignal.utilities.Snode
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.util.GlowViewUtilities import org.thoughtcrime.securesms.util.GlowViewUtilities
@ -240,9 +238,6 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
dotViewLayoutParams.addRule(CENTER_IN_PARENT) dotViewLayoutParams.addRule(CENTER_IN_PARENT)
dotView.layoutParams = dotViewLayoutParams dotView.layoutParams = dotViewLayoutParams
addView(dotView) addView(dotView)
postDelayed({
performAnimation()
}, dotAnimationStartDelay)
} }
private fun performAnimation() { private fun performAnimation() {
@ -258,6 +253,14 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
} }
} }
override fun onAttachedToWindow() {
super.onAttachedToWindow()
postDelayed({
performAnimation()
}, dotAnimationStartDelay)
}
private fun expand() { private fun expand() {
dotView.animateSizeChange(R.dimen.path_row_dot_size, R.dimen.path_row_expanded_dot_size) dotView.animateSizeChange(R.dimen.path_row_dot_size, R.dimen.path_row_expanded_dot_size)
@ColorRes val startColorID = if (UiModeUtilities.isDayUiMode(context)) R.color.transparent_black_30 else R.color.black @ColorRes val startColorID = if (UiModeUtilities.isDayUiMode(context)) R.color.transparent_black_30 else R.color.black