FadableView: Fix crash

animationRunning variable is mysteriously null at some point
This commit is contained in:
Geoffrey Métais
2019-08-08 11:00:59 +02:00
committed by Geoffrey Métais
parent 57a94f84f8
commit 2c9b38fc1e

View File

@@ -11,7 +11,9 @@ import androidx.appcompat.widget.AppCompatImageView
import java.util.concurrent.atomic.AtomicBoolean
class FadableImageView : AppCompatImageView {
private var animationRunning = AtomicBoolean(false)
//FIXME This field is sometimes null, despite a correct initialization order
// and non-nullable declaration
private var animationRunning : AtomicBoolean? = AtomicBoolean(false)
constructor(context: Context) : super(context)
@@ -20,10 +22,10 @@ class FadableImageView : AppCompatImageView {
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
private fun fade() {
if (animationRunning.get()) return
if (animationRunning?.get() == true) return
alpha = 0f
animationRunning.set(true)
animate().withEndAction { animationRunning.set(false) }.alpha(1f)
animationRunning?.set(true)
animate().withEndAction { animationRunning?.set(false) }.alpha(1f)
}
fun resetFade() {