feat(ui): complete ABox app experience redesign #10
+10
-1
@@ -4,13 +4,22 @@ import com.flagship.abox.manager.domain.ProviderProfileStore
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import com.flagship.abox.manager.domain.ProviderProfileId
|
||||
|
||||
class AutomationBootstrapper(
|
||||
private val profileStore: ProviderProfileStore,
|
||||
private val scheduler: AutomationScheduler,
|
||||
private val scope: CoroutineScope,
|
||||
) {
|
||||
private var previousProfileId: ProviderProfileId? = null
|
||||
|
||||
fun start() {
|
||||
scope.launch { profileStore.observeActiveProfile().collectLatest { scheduler.reconcileActiveProfile() } }
|
||||
scope.launch {
|
||||
profileStore.observeActiveProfile().collectLatest { active ->
|
||||
previousProfileId?.takeIf { it != active?.id }?.let { scheduler.cancel(it) }
|
||||
previousProfileId = active?.id
|
||||
scheduler.reconcileActiveProfile()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ class WorkManagerAutomationScheduleStore(context: Context) : AutomationScheduleS
|
||||
private val workManager = WorkManager.getInstance(context)
|
||||
|
||||
override suspend fun replace(profileId: ProviderProfileId, scenes: List<Scene>): DomainResult<Unit> {
|
||||
if (scenes.isEmpty()) return remove(profileId)
|
||||
val request = PeriodicWorkRequestBuilder<AutomationPollWorker>(15, TimeUnit.MINUTES)
|
||||
.setInputData(androidx.work.Data.Builder().putString(KEY_PROFILE_ID, profileId.value).build())
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user