[Android] FadableView: Fix crash

Geoffrey Métais git at videolan.org
Thu Aug 8 13:54:22 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Aug  8 11:00:59 2019 +0200| [a25b0f5e6b62733c428c7ab4fabd9ca149f4220f] | committer: Geoffrey Métais

FadableView: Fix crash

animationRunning variable is mysteriously null at some point

(cherry picked from commit 2c9b38fc1e6e4bd28253ae58295c0782a25cdc4d)

> https://code.videolan.org/videolan/vlc-android/commit/a25b0f5e6b62733c428c7ab4fabd9ca149f4220f
---

 vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt b/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt
index 33170be6b..92c060542 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt
@@ -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() {



More information about the Android mailing list