Widget: resolve db access in main thread
This commit is contained in:
parent
bd979d24e5
commit
5a0fc8da74
1 changed files with 14 additions and 11 deletions
|
@ -8,6 +8,8 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.HandlerThread
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
|
@ -26,7 +28,6 @@ import info.nightscout.androidaps.plugins.general.overview.OverviewData
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.TrendCalculator
|
import info.nightscout.androidaps.utils.TrendCalculator
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.logging.AAPSLogger
|
import info.nightscout.shared.logging.AAPSLogger
|
||||||
import info.nightscout.shared.logging.LTag
|
import info.nightscout.shared.logging.LTag
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
|
@ -53,6 +54,7 @@ class Widget : AppWidgetProvider() {
|
||||||
@Inject lateinit var sp: SP
|
@Inject lateinit var sp: SP
|
||||||
@Inject lateinit var constraintChecker: ConstraintChecker
|
@Inject lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||||
private val intentAction = "OpenApp"
|
private val intentAction = "OpenApp"
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent?) {
|
override fun onReceive(context: Context, intent: Intent?) {
|
||||||
|
@ -88,16 +90,17 @@ class Widget : AppWidgetProvider() {
|
||||||
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent)
|
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent)
|
||||||
views.setInt(R.id.widget_layout, "setBackgroundColor", Color.argb(alpha, 0, 0, 0))
|
views.setInt(R.id.widget_layout, "setBackgroundColor", Color.argb(alpha, 0, 0, 0))
|
||||||
|
|
||||||
updateBg(views)
|
handler.post {
|
||||||
updateTemporaryBasal(views)
|
updateBg(views)
|
||||||
updateExtendedBolus(views)
|
updateTemporaryBasal(views)
|
||||||
updateIobCob(views)
|
updateExtendedBolus(views)
|
||||||
updateTemporaryTarget(views)
|
updateIobCob(views)
|
||||||
updateProfile(views)
|
updateTemporaryTarget(views)
|
||||||
updateSensitivity(views)
|
updateProfile(views)
|
||||||
|
updateSensitivity(views)
|
||||||
// Instruct the widget manager to update the widget
|
// Instruct the widget manager to update the widget
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateBg(views: RemoteViews) {
|
private fun updateBg(views: RemoteViews) {
|
||||||
|
|
Loading…
Reference in a new issue