diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/paths/services/BacktrackToolService.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/paths/services/BacktrackToolService.kt index 6457d42df..63f482aef 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/paths/services/BacktrackToolService.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/paths/services/BacktrackToolService.kt @@ -4,6 +4,7 @@ import android.content.Context import android.util.Log import androidx.core.os.bundleOf import com.kylecorry.andromeda.permissions.Permissions +import com.kylecorry.luna.coroutines.onMain import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.receivers.ServiceRestartAlerter import com.kylecorry.trail_sense.shared.UserPreferences @@ -61,11 +62,12 @@ class BacktrackToolService(private val context: Context) : ToolService { Log.d("BacktrackSubsystem", "Cannot start backtrack") return } - - + prefs.backtrackEnabled = true Tools.broadcast(PathsToolRegistration.BROADCAST_BACKTRACK_ENABLED) - restart() + if (!isBlocked()) { + start(true) + } } override suspend fun disable() { diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/tools/infrastructure/Tools.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/tools/infrastructure/Tools.kt index f90a4d518..d4f5824e0 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/tools/infrastructure/Tools.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/tools/infrastructure/Tools.kt @@ -3,11 +3,9 @@ package com.kylecorry.trail_sense.tools.tools.infrastructure import android.content.Context import android.os.Bundle import com.kylecorry.andromeda.core.capitalizeWords -import com.kylecorry.andromeda.core.system.Intents import com.kylecorry.andromeda.core.system.Resources import com.kylecorry.luna.hooks.Hooks import com.kylecorry.luna.topics.generic.Topic -import com.kylecorry.luna.topics.generic.ITopic import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.settings.SettingsToolRegistration import com.kylecorry.trail_sense.shared.quickactions.QuickActionOpenTool @@ -52,6 +50,9 @@ import com.kylecorry.trail_sense.tools.waterpurification.WaterBoilTimerToolRegis import com.kylecorry.trail_sense.tools.weather.WeatherToolRegistration import com.kylecorry.trail_sense.tools.whistle.WhistleToolRegistration import com.kylecorry.trail_sense.tools.whitenoise.WhiteNoiseToolRegistration +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch object Tools { @@ -99,6 +100,8 @@ object Tools { LocalTalkToolRegistration ) private val topics = mutableMapOf>() + private val broadcastScope = CoroutineScope(Dispatchers.Main) + fun isToolAvailable(context: Context, toolId: Long): Boolean { return getTool(context, toolId) != null @@ -146,7 +149,9 @@ object Tools { } fun broadcast(toolBroadcastId: String, data: Bundle? = null) { - topics[toolBroadcastId]?.publish(data ?: Bundle()) + broadcastScope.launch { + topics[toolBroadcastId]?.publish(data ?: Bundle()) + } } fun subscribe(toolBroadcastId: String, callback: (Bundle) -> Boolean) {