From da45219b98b44a9f61977a09261c8a3fddbcb5d2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 30 Oct 2021 16:24:19 +0200 Subject: [PATCH] EROS: do not run commands on UI thread --- .../pump/omnipod/eros/ui/ErosPodManagementActivity.kt | 5 ++++- .../pump/omnipod/eros/ui/OmnipodErosOverviewFragment.kt | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodManagementActivity.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodManagementActivity.kt index 5054d6a14e..06d42d307d 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodManagementActivity.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/ErosPodManagementActivity.kt @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros.ui import android.content.Context import android.content.Intent import android.os.Bundle +import android.os.Handler +import android.os.HandlerThread import dagger.android.HasAndroidInjector import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity @@ -54,6 +56,7 @@ class ErosPodManagementActivity : NoSplashAppCompatActivity() { @Inject lateinit var aapsSchedulers: AapsSchedulers private var disposables: CompositeDisposable = CompositeDisposable() + private val loopHandler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private lateinit var binding: OmnipodErosPodManagementBinding @@ -97,7 +100,7 @@ class ErosPodManagementActivity : NoSplashAppCompatActivity() { binding.buttonResetRileylinkConfig.setOnClickListener { // TODO improvement: properly disable button until task is finished - serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector)) + loopHandler.post { serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector)) } } binding.buttonPlayTestBeep.setOnClickListener { diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodErosOverviewFragment.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodErosOverviewFragment.kt index 57f48a4a9a..710c76c37c 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodErosOverviewFragment.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodErosOverviewFragment.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.graphics.Color import android.os.Bundle import android.os.Handler +import android.os.HandlerThread import android.os.Looper import android.text.TextUtils import android.view.LayoutInflater @@ -86,7 +87,7 @@ class OmnipodErosOverviewFragment : DaggerFragment() { private var disposables: CompositeDisposable = CompositeDisposable() - private val loopHandler = Handler(Looper.getMainLooper()) + private val loopHandler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private lateinit var refreshLoop: Runnable init {