optimize widget calls
This commit is contained in:
parent
eee6fca854
commit
e5a9cc5a10
|
@ -151,7 +151,7 @@ class MainApp : DaggerApplication() {
|
||||||
// schedule widget update
|
// schedule widget update
|
||||||
refreshWidget = Runnable {
|
refreshWidget = Runnable {
|
||||||
handler.postDelayed(refreshWidget, 60000)
|
handler.postDelayed(refreshWidget, 60000)
|
||||||
Widget.updateWidget(this)
|
Widget.updateWidget(this, "ScheduleEveryMin")
|
||||||
}
|
}
|
||||||
handler.postDelayed(refreshWidget, 60000)
|
handler.postDelayed(refreshWidget, 60000)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,8 +70,8 @@ class UiInteractionImpl @Inject constructor(
|
||||||
context.startActivity(i)
|
context.startActivity(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateWidget(context: Context) {
|
override fun updateWidget(context: Context, from: String) {
|
||||||
Widget.updateWidget(context)
|
Widget.updateWidget(context, from)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun runWizardDialog(fragmentManager: FragmentManager, carbs: Int?, name: String?) {
|
override fun runWizardDialog(fragmentManager: FragmentManager, carbs: Int?, name: String?) {
|
||||||
|
|
|
@ -33,7 +33,6 @@ import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import info.nightscout.ui.widget.Widget
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -108,7 +107,6 @@ class KeepAliveWorker(
|
||||||
}
|
}
|
||||||
lastRun = dateUtil.now()
|
lastRun = dateUtil.now()
|
||||||
|
|
||||||
Widget.updateWidget(context)
|
|
||||||
localAlertUtils.shortenSnoozeInterval()
|
localAlertUtils.shortenSnoozeInterval()
|
||||||
localAlertUtils.checkStaleBGAlert()
|
localAlertUtils.checkStaleBGAlert()
|
||||||
checkPump()
|
checkPump()
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.os.SystemClock
|
||||||
import androidx.work.Data
|
import androidx.work.Data
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.OneTimeWorkRequest
|
||||||
import androidx.work.WorkContinuation
|
|
||||||
import androidx.work.WorkInfo
|
import androidx.work.WorkInfo
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
|
@ -44,6 +43,7 @@ import info.nightscout.workflow.PrepareTemporaryTargetDataWorker
|
||||||
import info.nightscout.workflow.PrepareTreatmentsDataWorker
|
import info.nightscout.workflow.PrepareTreatmentsDataWorker
|
||||||
import info.nightscout.workflow.UpdateGraphWorker
|
import info.nightscout.workflow.UpdateGraphWorker
|
||||||
import info.nightscout.workflow.UpdateIobCobSensWorker
|
import info.nightscout.workflow.UpdateIobCobSensWorker
|
||||||
|
import info.nightscout.workflow.UpdateWidgetWorker
|
||||||
import info.nightscout.workflow.iob.IobCobOref1Worker
|
import info.nightscout.workflow.iob.IobCobOref1Worker
|
||||||
import info.nightscout.workflow.iob.IobCobOrefWorker
|
import info.nightscout.workflow.iob.IobCobOrefWorker
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
|
@ -209,6 +209,10 @@ class CalculationWorkflowImpl @Inject constructor(
|
||||||
.setInputData(dataWorkerStorage.storeInputData(InvokeLoopWorker.InvokeLoopData(cause)))
|
.setInputData(dataWorkerStorage.storeInputData(InvokeLoopWorker.InvokeLoopData(cause)))
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
.then(
|
||||||
|
job == MAIN_CALCULATION,
|
||||||
|
OneTimeWorkRequest.Builder(UpdateWidgetWorker::class.java).build()
|
||||||
|
)
|
||||||
.then(
|
.then(
|
||||||
job == MAIN_CALCULATION,
|
job == MAIN_CALCULATION,
|
||||||
OneTimeWorkRequest.Builder(PreparePredictionsWorker::class.java)
|
OneTimeWorkRequest.Builder(PreparePredictionsWorker::class.java)
|
||||||
|
|
|
@ -33,7 +33,7 @@ interface UiInteraction {
|
||||||
*/
|
*/
|
||||||
fun runAlarm(status: String, title: String, @RawRes soundId: Int = 0)
|
fun runAlarm(status: String, title: String, @RawRes soundId: Int = 0)
|
||||||
|
|
||||||
fun updateWidget(context: Context)
|
fun updateWidget(context: Context, from: String)
|
||||||
|
|
||||||
fun runWizardDialog(fragmentManager: FragmentManager, carbs: Int? = null, name: String? = null)
|
fun runWizardDialog(fragmentManager: FragmentManager, carbs: Int? = null, name: String? = null)
|
||||||
fun runLoopDialog(fragmentManager: FragmentManager, showOkCancel: Int)
|
fun runLoopDialog(fragmentManager: FragmentManager, showOkCancel: Int)
|
||||||
|
|
|
@ -45,7 +45,7 @@ class CompatDBHelper @Inject constructor(
|
||||||
.changeObservable()
|
.changeObservable()
|
||||||
.doOnSubscribe {
|
.doOnSubscribe {
|
||||||
rxBus.send(EventNewBG(null))
|
rxBus.send(EventNewBG(null))
|
||||||
uiInteraction.updateWidget(context)
|
uiInteraction.updateWidget(context, "OnStart")
|
||||||
}
|
}
|
||||||
.subscribe {
|
.subscribe {
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +58,6 @@ class CompatDBHelper @Inject constructor(
|
||||||
it.filterIsInstance<GlucoseValue>().maxByOrNull { gv -> gv.timestamp }?.let { gv ->
|
it.filterIsInstance<GlucoseValue>().maxByOrNull { gv -> gv.timestamp }?.let { gv ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv")
|
||||||
rxBus.send(EventNewBG(gv.timestamp))
|
rxBus.send(EventNewBG(gv.timestamp))
|
||||||
uiInteraction.updateWidget(context)
|
|
||||||
newestGlucoseValue = gv
|
newestGlucoseValue = gv
|
||||||
}
|
}
|
||||||
it.filterIsInstance<GlucoseValue>().minOfOrNull { gv -> gv.timestamp }?.let { timestamp ->
|
it.filterIsInstance<GlucoseValue>().minOfOrNull { gv -> gv.timestamp }?.let { timestamp ->
|
||||||
|
|
|
@ -69,9 +69,10 @@ class Widget : AppWidgetProvider() {
|
||||||
// many threads were created. Making handler static resolve this issue
|
// many threads were created. Making handler static resolve this issue
|
||||||
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||||
|
|
||||||
fun updateWidget(context: Context) {
|
fun updateWidget(context: Context, from: String) {
|
||||||
context.sendBroadcast(Intent().also {
|
context.sendBroadcast(Intent().also {
|
||||||
it.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, AppWidgetManager.getInstance(context)?.getAppWidgetIds(ComponentName(context, Widget::class.java)))
|
it.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, AppWidgetManager.getInstance(context)?.getAppWidgetIds(ComponentName(context, Widget::class.java)))
|
||||||
|
it.putExtra("from", from)
|
||||||
it.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
it.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -80,6 +81,7 @@ class Widget : AppWidgetProvider() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent?) {
|
override fun onReceive(context: Context, intent: Intent?) {
|
||||||
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
||||||
|
aapsLogger.debug(LTag.WIDGET, "onReceive ${intent?.extras?.getString("from")}")
|
||||||
super.onReceive(context, intent)
|
super.onReceive(context, intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +101,6 @@ class Widget : AppWidgetProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
|
private fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
|
||||||
aapsLogger.debug(LTag.WIDGET, "updateAppWidget called")
|
|
||||||
|
|
||||||
val views = RemoteViews(context.packageName, R.layout.widget_layout)
|
val views = RemoteViews(context.packageName, R.layout.widget_layout)
|
||||||
val alpha = sp.getInt(WidgetConfigureActivity.PREF_PREFIX_KEY + appWidgetId, WidgetConfigureActivity.DEFAULT_OPACITY)
|
val alpha = sp.getInt(WidgetConfigureActivity.PREF_PREFIX_KEY + appWidgetId, WidgetConfigureActivity.DEFAULT_OPACITY)
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class WidgetConfigureActivity : DaggerActivity() {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
value = progress
|
value = progress
|
||||||
saveTitlePref(appWidgetId, value)
|
saveTitlePref(appWidgetId, value)
|
||||||
Widget.updateWidget(this@WidgetConfigureActivity)
|
Widget.updateWidget(this@WidgetConfigureActivity, "WidgetConfigure")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package info.nightscout.workflow
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import info.nightscout.core.utils.worker.LoggingWorker
|
||||||
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateWidgetWorker(
|
||||||
|
private val context: Context,
|
||||||
|
params: WorkerParameters
|
||||||
|
) : LoggingWorker(context, params, Dispatchers.Default) {
|
||||||
|
|
||||||
|
@Inject lateinit var uiInteraction: UiInteraction
|
||||||
|
|
||||||
|
override suspend fun doWorkAndLog(): Result {
|
||||||
|
uiInteraction.updateWidget(context, "WorkFlow")
|
||||||
|
return Result.success()
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import info.nightscout.workflow.PrepareTemporaryTargetDataWorker
|
||||||
import info.nightscout.workflow.PrepareTreatmentsDataWorker
|
import info.nightscout.workflow.PrepareTreatmentsDataWorker
|
||||||
import info.nightscout.workflow.UpdateGraphWorker
|
import info.nightscout.workflow.UpdateGraphWorker
|
||||||
import info.nightscout.workflow.UpdateIobCobSensWorker
|
import info.nightscout.workflow.UpdateIobCobSensWorker
|
||||||
|
import info.nightscout.workflow.UpdateWidgetWorker
|
||||||
import info.nightscout.workflow.iob.IobCobOref1Worker
|
import info.nightscout.workflow.iob.IobCobOref1Worker
|
||||||
import info.nightscout.workflow.iob.IobCobOrefWorker
|
import info.nightscout.workflow.iob.IobCobOrefWorker
|
||||||
|
|
||||||
|
@ -34,5 +35,6 @@ abstract class WorkflowModule {
|
||||||
@ContributesAndroidInjector abstract fun prepareBucketedDataWorkerInjector(): PrepareBucketedDataWorker
|
@ContributesAndroidInjector abstract fun prepareBucketedDataWorkerInjector(): PrepareBucketedDataWorker
|
||||||
@ContributesAndroidInjector abstract fun loadBgDataWorkerInjector(): LoadBgDataWorker
|
@ContributesAndroidInjector abstract fun loadBgDataWorkerInjector(): LoadBgDataWorker
|
||||||
@ContributesAndroidInjector abstract fun invokeLoopWorkerInjector(): InvokeLoopWorker
|
@ContributesAndroidInjector abstract fun invokeLoopWorkerInjector(): InvokeLoopWorker
|
||||||
|
@ContributesAndroidInjector abstract fun updateWidgetWorkerInjector(): UpdateWidgetWorker
|
||||||
@ContributesAndroidInjector abstract fun dummyWorkerInjector(): DummyWorker
|
@ContributesAndroidInjector abstract fun dummyWorkerInjector(): DummyWorker
|
||||||
}
|
}
|
Loading…
Reference in a new issue