session-android/app/src/main/java/org/thoughtcrime/securesms/onboarding/FakeChatView.kt

79 lines
3.1 KiB
Kotlin
Raw Normal View History

2021-07-09 03:14:21 +02:00
package org.thoughtcrime.securesms.onboarding
2019-12-16 16:20:48 +01:00
2020-09-08 06:44:57 +02:00
import android.animation.FloatEvaluator
import android.animation.ValueAnimator
2019-12-16 16:20:48 +01:00
import android.content.Context
import android.os.Handler
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ScrollView
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewFakeChatBinding
2021-07-09 05:18:48 +02:00
import org.thoughtcrime.securesms.util.disableClipping
2019-12-16 16:20:48 +01:00
class FakeChatView : ScrollView {
private lateinit var binding: ViewFakeChatBinding
2019-12-16 16:20:48 +01:00
// region Settings
private val spacing = context.resources.getDimension(R.dimen.medium_spacing)
2020-10-21 01:20:23 +02:00
private val startDelay: Long = 1000
private val delayBetweenMessages: Long = 1500
2019-12-16 16:20:48 +01:00
private val animationDuration: Long = 400
// endregion
// region Lifecycle
constructor(context: Context) : super(context) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
setUpViewHierarchy()
}
private fun setUpViewHierarchy() {
binding = ViewFakeChatBinding.inflate(LayoutInflater.from(context), this, true)
binding.root.disableClipping()
2019-12-16 16:20:48 +01:00
isVerticalScrollBarEnabled = false
}
// endregion
// region Animation
fun startAnimating() {
listOf( binding.bubble1, binding.bubble2, binding.bubble3, binding.bubble4, binding.bubble5 ).forEach { it.alpha = 0.0f }
2020-09-08 06:44:57 +02:00
fun show(bubble: View) {
val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f)
animation.duration = animationDuration
animation.addUpdateListener { animator ->
bubble.alpha = animator.animatedValue as Float
}
animation.start()
2019-12-16 16:20:48 +01:00
}
Handler().postDelayed({
show(binding.bubble1)
2019-12-16 16:20:48 +01:00
Handler().postDelayed({
show(binding.bubble2)
2019-12-16 16:20:48 +01:00
Handler().postDelayed({
show(binding.bubble3)
smoothScrollTo(0, (binding.bubble1.height + spacing).toInt())
2019-12-16 16:20:48 +01:00
Handler().postDelayed({
show(binding.bubble4)
smoothScrollTo(0, (binding.bubble1.height + spacing).toInt() + (binding.bubble2.height + spacing).toInt())
2019-12-16 16:20:48 +01:00
Handler().postDelayed({
show(binding.bubble5)
smoothScrollTo(0, (binding.bubble1.height + spacing).toInt() + (binding.bubble2.height + spacing).toInt() + (binding.bubble3.height + spacing).toInt())
2019-12-16 16:20:48 +01:00
}, delayBetweenMessages)
}, delayBetweenMessages)
}, delayBetweenMessages)
}, delayBetweenMessages)
}, startDelay)
}
// endregion
}