diff --git a/app/build.gradle b/app/build.gradle index 5a8a8c5d..2a024249 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,7 +64,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:db51b86628' + implementation 'com.github.SimpleMobileTools:Simple-Commons:a1ecb048c0' implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'com.shawnlin:number-picker:2.4.6' diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/services/StopwatchService.kt b/app/src/main/kotlin/com/simplemobiletools/clock/services/StopwatchService.kt index 8fc7e0d0..ef1d5636 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/services/StopwatchService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/services/StopwatchService.kt @@ -17,6 +17,7 @@ import com.simplemobiletools.clock.helpers.STOPWATCH_RUNNING_NOTIF_ID import com.simplemobiletools.clock.helpers.Stopwatch import com.simplemobiletools.clock.helpers.Stopwatch.State import com.simplemobiletools.clock.helpers.Stopwatch.UpdateListener +import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.helpers.isOreoPlus import org.greenrobot.eventbus.EventBus @@ -24,7 +25,6 @@ import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode class StopwatchService : Service() { - private val bus = EventBus.getDefault() private lateinit var notificationManager: NotificationManager private lateinit var notificationBuilder: NotificationCompat.Builder @@ -114,7 +114,11 @@ class StopwatchService : Service() { fun startStopwatchService(context: Context) { Handler(Looper.getMainLooper()).post { - ContextCompat.startForegroundService(context, Intent(context, StopwatchService::class.java)) + try { + ContextCompat.startForegroundService(context, Intent(context, StopwatchService::class.java)) + } catch (e: Exception) { + context.showErrorToast(e) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt b/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt index 124b4eec..b94e7c72 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt @@ -19,6 +19,7 @@ import com.simplemobiletools.clock.helpers.INVALID_TIMER_ID import com.simplemobiletools.clock.helpers.TIMER_RUNNING_NOTIF_ID import com.simplemobiletools.clock.models.TimerEvent import com.simplemobiletools.clock.models.TimerState +import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.helpers.isOreoPlus import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe @@ -55,7 +56,11 @@ class TimerService : Service() { } Handler(Looper.getMainLooper()).post { - startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!)) + try { + startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!)) + } catch (e: Exception) { + showErrorToast(e) + } } } else { stopService() @@ -122,7 +127,11 @@ class TimerService : Service() { fun startTimerService(context: Context) { Handler(Looper.getMainLooper()).post { - ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java)) + try { + ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java)) + } catch (e: Exception) { + context.showErrorToast(e) + } } }