From 083e708e005f087fb3e4ebddbb365b131bdc43b4 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sat, 16 Mar 2024 07:52:00 -0400 Subject: [PATCH] Prevent whistle quick action from crashing tools --- .../tools/whistle/quickactions/QuickActionWhistle.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/whistle/quickactions/QuickActionWhistle.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/whistle/quickactions/QuickActionWhistle.kt index a2371c362..72b766311 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/whistle/quickactions/QuickActionWhistle.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/whistle/quickactions/QuickActionWhistle.kt @@ -3,8 +3,10 @@ package com.kylecorry.trail_sense.tools.whistle.quickactions import android.annotation.SuppressLint import android.view.MotionEvent import android.widget.ImageButton +import androidx.core.view.isVisible import androidx.fragment.app.Fragment import com.kylecorry.andromeda.core.coroutines.onDefault +import com.kylecorry.andromeda.core.coroutines.onMain import com.kylecorry.andromeda.fragments.inBackground import com.kylecorry.andromeda.sound.ISoundPlayer import com.kylecorry.trail_sense.R @@ -23,7 +25,15 @@ class QuickActionWhistle(btn: ImageButton, fragment: Fragment) : fragment.inBackground { onDefault { - whistle = Whistle() + try { + whistle = Whistle() + } catch (e: Exception) { + e.printStackTrace() + // The whistle couldn't be instantiated + onMain { + button.isVisible = false + } + } } }