From 1280e798d21d3d03f8705e8b0db2b48e89ee551f Mon Sep 17 00:00:00 2001 From: Gokul K Date: Tue, 11 Jul 2023 18:48:55 +0530 Subject: [PATCH] rendering only if layout and konfetti view exists - to avoid null reference errors --- .../java/org/isoron/uhabits/utils/ViewExtensions.kt | 10 +++++++--- uhabits-android/src/main/res/layout/konfetti.xml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/utils/ViewExtensions.kt b/uhabits-android/src/main/java/org/isoron/uhabits/utils/ViewExtensions.kt index 9334ab569..583bc5048 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/utils/ViewExtensions.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/utils/ViewExtensions.kt @@ -115,10 +115,12 @@ fun ViewGroup.buildKonfettiView(): View { } fun showConfetti(view: View) { - val viewId = R.id.konfettttiView + val viewId = R.id.konfetttiView val linearLayout = view.findViewById(R.id.konfettiLayout) val kv = view.findViewById(viewId) - linearLayout.bringToFront() + if (linearLayout != null) { + linearLayout.bringToFront() + } val party = Party( speed = 0f, maxSpeed = 32f, @@ -128,7 +130,9 @@ fun showConfetti(view: View) { position = Position.Relative(0.5, 0.3), emitter = Emitter(duration = 300, TimeUnit.MILLISECONDS).max(300) ) - kv.start(party) + if (kv != null) { + kv.start(party) + } } fun View.showMessage(msg: String) { diff --git a/uhabits-android/src/main/res/layout/konfetti.xml b/uhabits-android/src/main/res/layout/konfetti.xml index 49bd60daa..1f7f918dc 100644 --- a/uhabits-android/src/main/res/layout/konfetti.xml +++ b/uhabits-android/src/main/res/layout/konfetti.xml @@ -24,6 +24,6 @@ + android:id="@+id/konfetttiView"/>