Handle voice message recording view hiding

This commit is contained in:
Niels Andriesse 2021-06-17 16:07:11 +10:00
parent b7000aa58b
commit b5376cd60e
3 changed files with 55 additions and 7 deletions

View File

@ -25,6 +25,7 @@ import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarDelegate import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarDelegate
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarRecordingViewDelegate
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
@ -36,7 +37,7 @@ import kotlin.math.abs
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.math.sqrt import kotlin.math.sqrt
class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate { class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate, InputBarRecordingViewDelegate {
private val lockViewHitMargin by lazy { toPx(40, resources) } private val lockViewHitMargin by lazy { toPx(40, resources) }
private var threadID: Long = -1 private var threadID: Long = -1
private var actionMode: ActionMode? = null private var actionMode: ActionMode? = null
@ -125,6 +126,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
private fun setUpInputBar() { private fun setUpInputBar() {
inputBar.delegate = this inputBar.delegate = this
inputBarRecordingView.delegate = this
// GIF button // GIF button
gifButtonContainer.addView(gifButton) gifButtonContainer.addView(gifButton)
gifButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT) gifButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
@ -155,6 +157,24 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
override fun showVoiceMessageUI() { override fun showVoiceMessageUI() {
inputBarRecordingView.show() inputBarRecordingView.show()
inputBar.alpha = 0.0f
val animation = ValueAnimator.ofObject(FloatEvaluator(), 1.0f, 0.0f)
animation.duration = 250L
animation.addUpdateListener { animator ->
inputBar.alpha = animator.animatedValue as Float
}
animation.start()
}
override fun handleInputBarRecordingViewHidden() {
Log.d("Test", "Here")
inputBar.alpha = 1.0f
val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f)
animation.duration = 250L
animation.addUpdateListener { animator ->
inputBar.alpha = animator.animatedValue as Float
}
animation.start()
} }
// endregion // endregion
@ -243,7 +263,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} }
private fun expandLockView() { private fun expandLockView() {
val animation = ValueAnimator.ofObject(FloatEvaluator(), lockView.scaleX, 1.05f) val animation = ValueAnimator.ofObject(FloatEvaluator(), lockView.scaleX, 1.10f)
animation.duration = 250L animation.duration = 250L
animation.addUpdateListener { animator -> animation.addUpdateListener { animator ->
lockView.scaleX = animator.animatedValue as Float lockView.scaleX = animator.animatedValue as Float

View File

@ -24,6 +24,9 @@ import kotlin.math.roundToLong
class InputBarRecordingView : RelativeLayout { class InputBarRecordingView : RelativeLayout {
private var startTimestamp = 0L private var startTimestamp = 0L
private val snHandler = Handler(Looper.getMainLooper()) private val snHandler = Handler(Looper.getMainLooper())
private var dotViewAnimation: ValueAnimator? = null
private var pulseAnimation: ValueAnimator? = null
var delegate: InputBarRecordingViewDelegate? = null
constructor(context: Context) : super(context) { initialize() } constructor(context: Context) : super(context) { initialize() }
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() } constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
@ -32,10 +35,12 @@ class InputBarRecordingView : RelativeLayout {
private fun initialize() { private fun initialize() {
LayoutInflater.from(context).inflate(R.layout.view_input_bar_recording, this) LayoutInflater.from(context).inflate(R.layout.view_input_bar_recording, this)
inputBarMiddleContentContainer.disableClipping() inputBarMiddleContentContainer.disableClipping()
inputBarCancelButton.setOnClickListener { hide() }
} }
fun show() { fun show() {
startTimestamp = Date().time startTimestamp = Date().time
recordButtonOverlayImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_microphone, context.theme))
isVisible = true isVisible = true
alpha = 0.0f alpha = 0.0f
val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f) val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f)
@ -50,8 +55,25 @@ class InputBarRecordingView : RelativeLayout {
updateTimer() updateTimer()
} }
fun hide() {
alpha = 1.0f
val animation = ValueAnimator.ofObject(FloatEvaluator(), 1.0f, 0.0f)
animation.duration = 250L
animation.addUpdateListener { animator ->
alpha = animator.animatedValue as Float
if (animator.animatedFraction == 1.0f) {
isVisible = false
dotViewAnimation?.repeatCount = 0
pulseAnimation?.removeAllUpdateListeners()
}
}
animation.start()
delegate?.handleInputBarRecordingViewHidden()
}
private fun animateDotView() { private fun animateDotView() {
val animation = ValueAnimator.ofObject(FloatEvaluator(), 1.0f, 0.0f) val animation = ValueAnimator.ofObject(FloatEvaluator(), 1.0f, 0.0f)
dotViewAnimation = animation
animation.duration = 500L animation.duration = 500L
animation.addUpdateListener { animator -> animation.addUpdateListener { animator ->
dotView.alpha = animator.animatedValue as Float dotView.alpha = animator.animatedValue as Float
@ -66,10 +88,11 @@ class InputBarRecordingView : RelativeLayout {
val expandedSize = toPx(104.0f, resources) val expandedSize = toPx(104.0f, resources)
pulseView.animateSizeChange(collapsedSize, expandedSize, 1000) pulseView.animateSizeChange(collapsedSize, expandedSize, 1000)
val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.5, 0.0f) val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.5, 0.0f)
pulseAnimation = animation
animation.duration = 1000L animation.duration = 1000L
animation.addUpdateListener { animator -> animation.addUpdateListener { animator ->
pulseView.alpha = animator.animatedValue as Float pulseView.alpha = animator.animatedValue as Float
if (animator.animatedFraction == 1.0f) { pulse() } if (animator.animatedFraction == 1.0f && isVisible) { pulse() }
} }
animation.start() animation.start()
} }
@ -90,7 +113,6 @@ class InputBarRecordingView : RelativeLayout {
} }
private fun updateTimer() { private fun updateTimer() {
Log.d("Test", "${Date().time - startTimestamp}")
val duration = (Date().time - startTimestamp) / 1000L val duration = (Date().time - startTimestamp) / 1000L
recordingViewDurationTextView.text = DateUtils.formatElapsedTime(duration) recordingViewDurationTextView.text = DateUtils.formatElapsedTime(duration)
snHandler.postDelayed({ updateTimer() }, 500) snHandler.postDelayed({ updateTimer() }, 500)
@ -113,3 +135,8 @@ class InputBarRecordingView : RelativeLayout {
recordButtonOverlayImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_up, context.theme)) recordButtonOverlayImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_up, context.theme))
} }
} }
interface InputBarRecordingViewDelegate {
fun handleInputBarRecordingViewHidden()
}

View File

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="126dp"> android:layout_height="128dp">
<!-- The fake input bar --> <!-- The fake input bar -->
@ -84,10 +84,11 @@
<TextView <TextView
android:id="@+id/inputBarCancelButton" android:id="@+id/inputBarCancelButton"
android:layout_width="wrap_content" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="40dp"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:alpha="0" android:alpha="0"
android:gravity="center"
android:text="@string/cancel" android:text="@string/cancel"
android:textSize="@dimen/small_font_size" android:textSize="@dimen/small_font_size"
android:textColor="@color/text" android:textColor="@color/text"