Skip to content

Commit

Permalink
rendering only if layout and konfetti view exists - to avoid null ref…
Browse files Browse the repository at this point in the history
…erence errors
  • Loading branch information
Gokul K authored and iSoron committed Feb 4, 2024
1 parent b09306e commit 1280e79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinearLayout>(R.id.konfettiLayout)
val kv = view.findViewById<KonfettiView>(viewId)
linearLayout.bringToFront()
if (linearLayout != null) {
linearLayout.bringToFront()
}
val party = Party(
speed = 0f,
maxSpeed = 32f,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion uhabits-android/src/main/res/layout/konfetti.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<nl.dionsegijn.konfetti.xml.KonfettiView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/konfettttiView"/>
android:id="@+id/konfetttiView"/>

</LinearLayout>

0 comments on commit 1280e79

Please sign in to comment.