Throttle pod device data for the UI, notifications or widgets.

We don't need faster updates than 1 per second.
(We keep reactions at maximum speed tho)
This commit is contained in:
darken
2022-11-05 12:11:09 +01:00
committed by Matthias Urhahn
parent b9f4992a33
commit 6340f73d61
5 changed files with 16 additions and 1 deletions
+2
View File
@@ -8,6 +8,7 @@ import dagger.hilt.android.HiltAndroidApp
import eu.darken.capod.common.coroutine.AppScope
import eu.darken.capod.common.debug.autoreport.AutoReporting
import eu.darken.capod.common.debug.logging.*
import eu.darken.capod.common.flow.throttleLatest
import eu.darken.capod.common.upgrade.UpgradeRepo
import eu.darken.capod.main.ui.widget.WidgetManager
import eu.darken.capod.monitor.core.PodMonitor
@@ -49,6 +50,7 @@ open class App : Application(), Configuration.Provider {
podMonitor.mainDevice
.distinctUntilChanged()
.throttleLatest(1000)
.onEach {
log(TAG) { "Main device changed, refreshing widgets." }
widgetManager.refreshWidgets()
@@ -9,6 +9,7 @@ import eu.darken.capod.common.coroutine.DispatcherProvider
import eu.darken.capod.common.debug.autoreport.DebugSettings
import eu.darken.capod.common.debug.logging.log
import eu.darken.capod.common.flow.combine
import eu.darken.capod.common.flow.throttleLatest
import eu.darken.capod.common.livedata.SingleLiveEvent
import eu.darken.capod.common.navigation.navVia
import eu.darken.capod.common.permissions.Permission
@@ -96,6 +97,7 @@ class OverviewFragmentVM @Inject constructor(
}
}
.catch { errorEvents.postValue(it) }
.throttleLatest(1000)
val listItems: LiveData<List<OverviewAdapter.Item>> = combine(
updateTicker,
@@ -17,6 +17,7 @@ import eu.darken.capod.common.debug.logging.asLog
import eu.darken.capod.common.debug.logging.log
import eu.darken.capod.common.debug.logging.logTag
import eu.darken.capod.common.flow.setupCommonEventHandlers
import eu.darken.capod.common.flow.throttleLatest
import eu.darken.capod.main.core.GeneralSettings
import eu.darken.capod.main.core.MonitorMode
import eu.darken.capod.main.core.PermissionTool
@@ -101,6 +102,7 @@ class MonitorWorker @AssistedInject constructor(
.setupCommonEventHandlers(TAG) { "PodMonitor" }
.onStart { setForeground(monitorNotifications.getForegroundInfo(null)) }
.distinctUntilChanged()
.throttleLatest(1000)
.onEach { currentDevice ->
notificationManager.notify(
MonitorNotifications.NOTIFICATION_ID,