Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

refactor(settings): add operations boundary

David Nashash07e2564f88e6
diff --git a/.superpowers/sdd/2026-09-05-settings-data-boundary/task-3-report.md b/.superpowers/sdd/2026-09-05-settings-data-boundary/task-3-report.md
new file mode 100644
index 00000000..eb070855
--- /dev/null
+++ b/.superpowers/sdd/2026-09-05-settings-data-boundary/task-3-report.md
@@ -0,0 +1,96 @@
+# Task 3 Report — Settings Operations Contract
+
+## Scope completed
+
+Introduced the `SettingsOperations` domain boundary and the three settings-facing snapshots. Added the data adapter and Hilt binding, then migrated settings operational reads and commands from Room DAOs and `ProviderSyncCommands` to the domain contract. `SettingsPreferences` was left as its existing binding.
+
+The feature still retains its `:data` dependency and the Task 1 production source guard was not activated, as required for this phase.
+
+## Red / green evidence
+
+All commands ran from `tmp/phase7-provider-boundary`. `ANDROID_HOME` and `ANDROID_SDK_ROOT` were set to `E:\androidSdk` for Android Gradle commands only; no `local.properties` or build configuration was changed.
+
+### Red
+
+1. Added the domain contract test, feature snapshot-to-UI test, and data adapter tests before creating any Task 3 production source.
+2. Initial combined Android command:
+
+ ```powershell
+ .\gradlew.bat :domain:test --tests com.streamvault.domain.settings.SettingsOperationsContractTest :feature:settings:testDebugUnitTest --tests com.streamvault.feature.settings.presentation.SettingsOperationalModelsTest :data:testDebugUnitTest --tests com.streamvault.data.settings.SettingsOperationsImplTest -x :feature:settings:verifyFeatureSettingsBoundary
+ ```
+
+ failed during Android configuration because the worktree had no SDK path, before test compilation.
+3. Domain red command:
+
+ ```powershell
+ .\gradlew.bat :domain:test --tests com.streamvault.domain.settings.SettingsOperationsContractTest
+ ```
+
+ failed as expected at `:domain:compileTestKotlin` with unresolved `SettingsXtreamIndexJob`, `SettingsXtreamLiveOnboarding`, and `SettingsSyncSection` references (10 compiler diagnostics), proving the new domain contract was absent.
+
+### Green
+
+```powershell
+.\gradlew.bat :domain:test --tests com.streamvault.domain.settings.SettingsOperationsContractTest
+```
+
+Passed: 1 test, 0 failures/errors.
+
+```powershell
+.\gradlew.bat :data:testDebugUnitTest --tests com.streamvault.data.settings.SettingsOperationsImplTest
+```
+
+Passed: 7 tests, 0 failures/errors.
+
+```powershell
+.\gradlew.bat :feature:settings:testDebugUnitTest --tests com.streamvault.feature.settings.presentation.SettingsOperationalModelsTest --tests com.streamvault.feature.settings.presentation.SettingsDerivedStateObserversTest --tests com.streamvault.feature.settings.presentation.SettingsProviderActionsTest -x :feature:settings:verifyFeatureSettingsBoundary
+```
+
+Passed: 7 tests across 3 classes, 0 failures/errors.
+
+```powershell
+.\gradlew.bat :app:kspDebugKotlin -x :feature:settings:verifyFeatureSettingsBoundary
+```
+
+Passed: app Hilt/KSP compilation (155 actionable tasks; 17 executed, 138 up-to-date).
+
+During green work, the first data test run exposed a test-double mismatch: Mockito `any()` does not match the adapter's nullable default `movieFastSyncOverride = null`. The test was corrected to match the actual `null`/`MANUAL_SETTINGS` defaults, then passed. No production behavior changed for that issue.
+
+## Field mapping audit
+
+| Domain field | Data source |
+| --- | --- |
+| `SettingsXtreamIndexJob.providerId` | `XtreamIndexJobEntity.providerId` |
+| `section` | `section` |
+| `state` | `state` |
+| `indexedRows` | `indexedRows` |
+| `lastError` | `lastError` |
+| `SettingsXtreamLiveOnboarding.providerId` | `XtreamLiveOnboardingStateEntity.providerId` |
+| `phase` | `phase` |
+| `importStrategy` | `importStrategy` |
+| `acceptedRowCount` | `acceptedRowCount` |
+| `stagedFlushCount` | `stagedFlushCount` |
+| `syncProfileTier` | `syncProfileTier` |
+| `syncProfileBatchSize` | `syncProfileBatchSize` |
+| `syncProfileStrategy` | `syncProfileStrategy` |
+| `syncProfileLowMemory` | `syncProfileLowMemory` |
+| `syncProfileMemoryClassMb` | `syncProfileMemoryClassMb` |
+| `syncProfileAvailableMemMb` | `syncProfileAvailableMemMb` |
+| `lastError` | `lastError` |
+| `updatedAt` | `updatedAt` |
+
+`SettingsSyncSection` is mapped explicitly in the adapter: `LIVE → LIVE`, `MOVIES → MOVIES`, `SERIES → SERIES`, and `EPG → EPG`. The retry adapter leaves existing `ProviderSyncCommands` defaults intact, including `MANUAL_SETTINGS`, and forwards the progress callback unchanged.
+
+## Self-review
+
+- `SettingsOperations` defines only the seven requested APIs and requested snapshots/section enum; it has no Room or data dependency.
+- `SettingsOperationsImpl` is the only new operational data boundary and maps all requested snapshot fields explicitly.
+- `SettingsDataModule` binds only `SettingsOperations`; it does not duplicate the existing `SettingsPreferences` binding.
+- Settings operational consumers use `SettingsOperations`; a source audit found no DAO/entity/sync-command data references in `feature/settings/src/main`.
+- Sync selection order, callbacks, UI strings, result handling, and defaults were retained. The existing domain `SyncProvider` use case remains for its richer settings flow; the former `ProviderSyncCommands` calls use the new operations adapter.
+- `git diff --check` passed. `graphify update .` completed after the code changes.
+
+## Concerns
+
+- The first combined red command was blocked by the missing SDK path, so only the domain contract's missing-symbol red compilation was directly observed. The feature and data tests were nevertheless authored before their production types, then executed green once the existing SDK was supplied.
+- The intentional Task 1 settings boundary failure was excluded from Android test and app KSP commands. It remains for Task 4; this task did not remove the feature `:data` dependency or activate that production source guard.
diff --git a/data/src/main/java/com/streamvault/data/di/SettingsDataModule.kt b/data/src/main/java/com/streamvault/data/di/SettingsDataModule.kt
new file mode 100644
index 00000000..ce992846
--- /dev/null
+++ b/data/src/main/java/com/streamvault/data/di/SettingsDataModule.kt
@@ -0,0 +1,15 @@
+package com.streamvault.data.di
+
+import com.streamvault.data.settings.SettingsOperationsImpl
+import com.streamvault.domain.settings.SettingsOperations
+import dagger.Binds
+import dagger.Module
+import dagger.hilt.InstallIn
+import dagger.hilt.components.SingletonComponent
+
+@Module
+@InstallIn(SingletonComponent::class)
+abstract class SettingsDataModule {
+ @Binds
+ abstract fun bindSettingsOperations(impl: SettingsOperationsImpl): SettingsOperations
+}
diff --git a/data/src/main/java/com/streamvault/data/settings/SettingsOperationsImpl.kt b/data/src/main/java/com/streamvault/data/settings/SettingsOperationsImpl.kt
new file mode 100644
index 00000000..33f81975
--- /dev/null
+++ b/data/src/main/java/com/streamvault/data/settings/SettingsOperationsImpl.kt
@@ -0,0 +1,88 @@
+package com.streamvault.data.settings
+
+import com.streamvault.data.local.dao.ProgramDao
+import com.streamvault.data.local.dao.XtreamIndexJobDao
+import com.streamvault.data.local.dao.XtreamLiveOnboardingDao
+import com.streamvault.data.local.entity.XtreamIndexJobEntity
+import com.streamvault.data.local.entity.XtreamLiveOnboardingStateEntity
+import com.streamvault.data.sync.ProviderSyncCommands
+import com.streamvault.data.sync.SyncRepairSection
+import com.streamvault.domain.model.Result
+import com.streamvault.domain.settings.SettingsOperations
+import com.streamvault.domain.settings.SettingsSyncSection
+import com.streamvault.domain.settings.SettingsXtreamIndexJob
+import com.streamvault.domain.settings.SettingsXtreamLiveOnboarding
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.map
+import javax.inject.Inject
+
+class SettingsOperationsImpl @Inject constructor(
+ private val programDao: ProgramDao,
+ private val xtreamIndexJobDao: XtreamIndexJobDao,
+ private val xtreamLiveOnboardingDao: XtreamLiveOnboardingDao,
+ private val syncCommands: ProviderSyncCommands
+) : SettingsOperations {
+ override fun observeProgramCount(providerId: Long): Flow<Int> =
+ programDao.observeCountByProvider(providerId)
+
+ override fun observeXtreamIndexJobs(): Flow<List<SettingsXtreamIndexJob>> =
+ xtreamIndexJobDao.observeAll().map { jobs -> jobs.map { it.toSettingsSnapshot() } }
+
+ override fun observeIncompleteXtreamLiveOnboarding(): Flow<List<SettingsXtreamLiveOnboarding>> =
+ xtreamLiveOnboardingDao.observeIncomplete().map { states ->
+ states.map { it.toSettingsSnapshot() }
+ }
+
+ override suspend fun syncProvider(providerId: Long, force: Boolean): Result<Unit> =
+ syncCommands.sync(providerId = providerId, force = force)
+
+ override suspend fun retryProviderSection(
+ providerId: Long,
+ section: SettingsSyncSection,
+ onProgress: ((String) -> Unit)?
+ ): Result<Unit> = syncCommands.retrySection(
+ providerId = providerId,
+ section = section.toSyncRepairSection(),
+ onProgress = onProgress
+ )
+
+ override suspend fun rebuildXtreamIndex(
+ providerId: Long,
+ onProgress: ((String) -> Unit)?
+ ): Result<Unit> = syncCommands.rebuildXtreamIndex(providerId, onProgress)
+
+ override fun scheduleBackgroundEpgSync(providerId: Long) {
+ syncCommands.scheduleBackgroundEpgSync(providerId)
+ }
+
+ private fun XtreamIndexJobEntity.toSettingsSnapshot() = SettingsXtreamIndexJob(
+ providerId = providerId,
+ section = section,
+ state = state,
+ indexedRows = indexedRows,
+ lastError = lastError
+ )
+
+ private fun XtreamLiveOnboardingStateEntity.toSettingsSnapshot() = SettingsXtreamLiveOnboarding(
+ providerId = providerId,
+ phase = phase,
+ importStrategy = importStrategy,
+ acceptedRowCount = acceptedRowCount,
+ stagedFlushCount = stagedFlushCount,
+ syncProfileTier = syncProfileTier,
+ syncProfileBatchSize = syncProfileBatchSize,
+ syncProfileStrategy = syncProfileStrategy,
+ syncProfileLowMemory = syncProfileLowMemory,
+ syncProfileMemoryClassMb = syncProfileMemoryClassMb,
+ syncProfileAvailableMemMb = syncProfileAvailableMemMb,
+ lastError = lastError,
+ updatedAt = updatedAt
+ )
+
+ private fun SettingsSyncSection.toSyncRepairSection(): SyncRepairSection = when (this) {
+ SettingsSyncSection.LIVE -> SyncRepairSection.LIVE
+ SettingsSyncSection.MOVIES -> SyncRepairSection.MOVIES
+ SettingsSyncSection.SERIES -> SyncRepairSection.SERIES
+ SettingsSyncSection.EPG -> SyncRepairSection.EPG
+ }
+}
diff --git a/data/src/test/java/com/streamvault/data/settings/SettingsOperationsImplTest.kt b/data/src/test/java/com/streamvault/data/settings/SettingsOperationsImplTest.kt
new file mode 100644
index 00000000..46cf4474
--- /dev/null
+++ b/data/src/test/java/com/streamvault/data/settings/SettingsOperationsImplTest.kt
@@ -0,0 +1,156 @@
+package com.streamvault.data.settings
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.data.local.dao.ProgramDao
+import com.streamvault.data.local.dao.XtreamIndexJobDao
+import com.streamvault.data.local.dao.XtreamLiveOnboardingDao
+import com.streamvault.data.local.entity.XtreamIndexJobEntity
+import com.streamvault.data.local.entity.XtreamLiveOnboardingStateEntity
+import com.streamvault.data.sync.ProviderSyncCommands
+import com.streamvault.data.sync.SyncRepairSection
+import com.streamvault.data.sync.XtreamLiveSyncReason
+import com.streamvault.domain.model.Result
+import com.streamvault.domain.settings.SettingsSyncSection
+import com.streamvault.domain.settings.SettingsXtreamIndexJob
+import com.streamvault.domain.settings.SettingsXtreamLiveOnboarding
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.mockito.kotlin.any
+import org.mockito.kotlin.eq
+import org.mockito.kotlin.isNull
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.verify
+import org.mockito.kotlin.whenever
+
+class SettingsOperationsImplTest {
+ private val programDao = mock<ProgramDao>()
+ private val xtreamIndexJobDao = mock<XtreamIndexJobDao>()
+ private val xtreamLiveOnboardingDao = mock<XtreamLiveOnboardingDao>()
+ private val syncCommands = mock<ProviderSyncCommands>()
+ private val operations = SettingsOperationsImpl(
+ programDao = programDao,
+ xtreamIndexJobDao = xtreamIndexJobDao,
+ xtreamLiveOnboardingDao = xtreamLiveOnboardingDao,
+ syncCommands = syncCommands
+ )
+
+ @Test
+ fun `observe program count forwards provider count`() = runTest {
+ whenever(programDao.observeCountByProvider(7L)).thenReturn(flowOf(18))
+
+ assertThat(operations.observeProgramCount(7L).first()).isEqualTo(18)
+ }
+
+ @Test
+ fun `observe index jobs maps every settings-facing field`() = runTest {
+ whenever(xtreamIndexJobDao.observeAll()).thenReturn(
+ flowOf(listOf(XtreamIndexJobEntity(7L, "MOVIE", "PARTIAL", indexedRows = 18, lastError = "bad row")))
+ )
+
+ assertThat(operations.observeXtreamIndexJobs().first()).containsExactly(
+ SettingsXtreamIndexJob(7L, "MOVIE", "PARTIAL", 18, "bad row")
+ )
+ }
+
+ @Test
+ fun `observe incomplete onboarding maps every settings-facing field`() = runTest {
+ whenever(xtreamLiveOnboardingDao.observeIncomplete()).thenReturn(
+ flowOf(
+ listOf(
+ XtreamLiveOnboardingStateEntity(
+ providerId = 7L,
+ phase = "INDEXING",
+ importStrategy = "STREAMING",
+ acceptedRowCount = 18,
+ stagedFlushCount = 2,
+ syncProfileTier = "LOW",
+ syncProfileBatchSize = 16,
+ syncProfileStrategy = "SEQUENTIAL",
+ syncProfileLowMemory = true,
+ syncProfileMemoryClassMb = 384,
+ syncProfileAvailableMemMb = 192L,
+ lastError = "bad row",
+ updatedAt = 99L
+ )
+ )
+ )
+ )
+
+ assertThat(operations.observeIncompleteXtreamLiveOnboarding().first()).containsExactly(
+ SettingsXtreamLiveOnboarding(
+ providerId = 7L,
+ phase = "INDEXING",
+ importStrategy = "STREAMING",
+ acceptedRowCount = 18,
+ stagedFlushCount = 2,
+ syncProfileTier = "LOW",
+ syncProfileBatchSize = 16,
+ syncProfileStrategy = "SEQUENTIAL",
+ syncProfileLowMemory = true,
+ syncProfileMemoryClassMb = 384,
+ syncProfileAvailableMemMb = 192L,
+ lastError = "bad row",
+ updatedAt = 99L
+ )
+ )
+ }
+
+ @Test
+ fun `sync provider delegates force unchanged`() = runTest {
+ whenever(syncCommands.sync(7L, force = true)).thenReturn(Result.success(Unit))
+
+ assertThat(operations.syncProvider(7L, force = true)).isEqualTo(Result.success(Unit))
+ verify(syncCommands).sync(7L, force = true)
+ }
+
+ @Test
+ fun `retry section translates settings section and preserves progress callback`() = runTest {
+ whenever(
+ syncCommands.retrySection(
+ eq(7L),
+ eq(SyncRepairSection.MOVIES),
+ isNull(),
+ eq(XtreamLiveSyncReason.MANUAL_SETTINGS),
+ any()
+ )
+ )
+ .thenAnswer { invocation ->
+ invocation.getArgument<((String) -> Unit)?>(4)?.invoke("Movies")
+ Result.success(Unit)
+ }
+ var progress: String? = null
+
+ assertThat(
+ operations.retryProviderSection(7L, SettingsSyncSection.MOVIES) { progress = it }
+ ).isEqualTo(Result.success(Unit))
+ assertThat(progress).isEqualTo("Movies")
+ verify(syncCommands).retrySection(
+ eq(7L),
+ eq(SyncRepairSection.MOVIES),
+ isNull(),
+ eq(XtreamLiveSyncReason.MANUAL_SETTINGS),
+ any()
+ )
+ }
+
+ @Test
+ fun `rebuild index preserves progress callback`() = runTest {
+ whenever(syncCommands.rebuildXtreamIndex(eq(7L), any())).thenAnswer { invocation ->
+ invocation.getArgument<((String) -> Unit)?>(1)?.invoke("Indexing")
+ Result.success(Unit)
+ }
+ var progress: String? = null
+
+ assertThat(operations.rebuildXtreamIndex(7L) { progress = it }).isEqualTo(Result.success(Unit))
+ assertThat(progress).isEqualTo("Indexing")
+ }
+
+ @Test
+ fun `schedule background epg forwards provider id`() {
+ operations.scheduleBackgroundEpgSync(7L)
+
+ verify(syncCommands).scheduleBackgroundEpgSync(7L)
+ }
+}
diff --git a/domain/src/main/java/com/streamvault/domain/settings/SettingsOperations.kt b/domain/src/main/java/com/streamvault/domain/settings/SettingsOperations.kt
new file mode 100644
index 00000000..160e9be8
--- /dev/null
+++ b/domain/src/main/java/com/streamvault/domain/settings/SettingsOperations.kt
@@ -0,0 +1,52 @@
+package com.streamvault.domain.settings
+
+import com.streamvault.domain.model.Result
+import kotlinx.coroutines.flow.Flow
+
+interface SettingsOperations {
+ fun observeProgramCount(providerId: Long): Flow<Int>
+ fun observeXtreamIndexJobs(): Flow<List<SettingsXtreamIndexJob>>
+ fun observeIncompleteXtreamLiveOnboarding(): Flow<List<SettingsXtreamLiveOnboarding>>
+ suspend fun syncProvider(providerId: Long, force: Boolean): Result<Unit>
+ suspend fun retryProviderSection(
+ providerId: Long,
+ section: SettingsSyncSection,
+ onProgress: ((String) -> Unit)? = null
+ ): Result<Unit>
+ suspend fun rebuildXtreamIndex(
+ providerId: Long,
+ onProgress: ((String) -> Unit)? = null
+ ): Result<Unit>
+ fun scheduleBackgroundEpgSync(providerId: Long)
+}
+
+enum class SettingsSyncSection {
+ LIVE,
+ MOVIES,
+ SERIES,
+ EPG
+}
+
+data class SettingsXtreamIndexJob(
+ val providerId: Long,
+ val section: String,
+ val state: String,
+ val indexedRows: Int,
+ val lastError: String?
+)
+
+data class SettingsXtreamLiveOnboarding(
+ val providerId: Long,
+ val phase: String,
+ val importStrategy: String?,
+ val acceptedRowCount: Int,
+ val stagedFlushCount: Int,
+ val syncProfileTier: String?,
+ val syncProfileBatchSize: Int,
+ val syncProfileStrategy: String?,
+ val syncProfileLowMemory: Boolean,
+ val syncProfileMemoryClassMb: Int,
+ val syncProfileAvailableMemMb: Long,
+ val lastError: String?,
+ val updatedAt: Long
+)
diff --git a/domain/src/test/java/com/streamvault/domain/settings/SettingsOperationsContractTest.kt b/domain/src/test/java/com/streamvault/domain/settings/SettingsOperationsContractTest.kt
new file mode 100644
index 00000000..9bea4132
--- /dev/null
+++ b/domain/src/test/java/com/streamvault/domain/settings/SettingsOperationsContractTest.kt
@@ -0,0 +1,43 @@
+package com.streamvault.domain.settings
+
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+
+class SettingsOperationsContractTest {
+ @Test
+ fun `operational snapshots retain only settings-facing fields`() {
+ val indexJob = SettingsXtreamIndexJob(
+ providerId = 7L,
+ section = "MOVIE",
+ state = "PARTIAL",
+ indexedRows = 42,
+ lastError = "bad row"
+ )
+ val onboarding = SettingsXtreamLiveOnboarding(
+ providerId = 7L,
+ phase = "INDEXING",
+ importStrategy = "STREAMING",
+ acceptedRowCount = 12,
+ stagedFlushCount = 3,
+ syncProfileTier = "LOW",
+ syncProfileBatchSize = 20,
+ syncProfileStrategy = "SEQUENTIAL",
+ syncProfileLowMemory = true,
+ syncProfileMemoryClassMb = 256,
+ syncProfileAvailableMemMb = 128L,
+ lastError = "retry",
+ updatedAt = 99L
+ )
+
+ assertThat(indexJob).isEqualTo(
+ SettingsXtreamIndexJob(7L, "MOVIE", "PARTIAL", 42, "bad row")
+ )
+ assertThat(onboarding.updatedAt).isEqualTo(99L)
+ assertThat(SettingsSyncSection.entries).containsExactly(
+ SettingsSyncSection.LIVE,
+ SettingsSyncSection.MOVIES,
+ SettingsSyncSection.SERIES,
+ SettingsSyncSection.EPG
+ )
+ }
+}
diff --git a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObservers.kt b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObservers.kt
index e59ed4d1..97a8cd7f 100644
--- a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObservers.kt
+++ b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObservers.kt
@@ -6,7 +6,7 @@ import com.streamvault.feature.settings.presentation.*
import android.content.Context
import com.streamvault.feature.settings.R
-import com.streamvault.data.local.dao.ProgramDao
+import com.streamvault.domain.settings.SettingsOperations
import com.streamvault.domain.model.Category
import com.streamvault.domain.model.CategorySortMode
import com.streamvault.domain.model.ContentType
@@ -33,7 +33,7 @@ internal fun observeProviderDiagnostics(
syncMetadataRepository: SyncMetadataRepository,
movieRepository: MovieRepository,
seriesRepository: SeriesRepository,
- programDao: ProgramDao,
+ settingsOperations: SettingsOperations,
application: Context
): Flow<Map<Long, ProviderDiagnosticsUiModel>> {
return providerRepository.getProviders()
@@ -47,7 +47,7 @@ internal fun observeProviderDiagnostics(
syncMetadataRepository.observeMetadata(provider.id),
movieRepository.getLibraryCount(provider.id),
seriesRepository.getLibraryCount(provider.id),
- programDao.observeCountByProvider(provider.id)
+ settingsOperations.observeProgramCount(provider.id)
) { metadata, movieCount, seriesCount, epgCount ->
provider.id to ProviderDiagnosticsUiModel(
lastSyncStatus = metadata?.lastSyncStatus ?: "NONE",
diff --git a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsObserverRegistrations.kt b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsObserverRegistrations.kt
index 04d75db0..54743e66 100644
--- a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsObserverRegistrations.kt
+++ b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsObserverRegistrations.kt
@@ -2,7 +2,7 @@ package com.streamvault.feature.settings.presentation
import android.content.Context
import com.streamvault.feature.settings.api.SettingsAppUpdatePort
-import com.streamvault.data.local.dao.ProgramDao
+import com.streamvault.domain.settings.SettingsOperations
import com.streamvault.domain.settings.SettingsPreferences
import com.streamvault.domain.manager.RecordingManager
import com.streamvault.domain.model.RecordingItem
@@ -158,7 +158,7 @@ internal fun registerDerivedStateObservers(
syncMetadataRepository: SyncMetadataRepository,
movieRepository: MovieRepository,
seriesRepository: SeriesRepository,
- programDao: ProgramDao,
+ settingsOperations: SettingsOperations,
application: Context,
preferencesRepository: SettingsPreferences,
activeProviderIdFlow: Flow<Long?>,
@@ -174,7 +174,7 @@ internal fun registerDerivedStateObservers(
syncMetadataRepository = syncMetadataRepository,
movieRepository = movieRepository,
seriesRepository = seriesRepository,
- programDao = programDao,
+ settingsOperations = settingsOperations,
application = application
).collect { diagnosticsByProvider ->
uiState.update { it.copy(diagnosticsByProvider = diagnosticsByProvider) }
diff --git a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsOperationalModels.kt b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsOperationalModels.kt
index 47af2797..da0c3e6a 100644
--- a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsOperationalModels.kt
+++ b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsOperationalModels.kt
@@ -1,6 +1,6 @@
package com.streamvault.feature.settings.presentation
-import com.streamvault.data.local.entity.XtreamLiveOnboardingStateEntity
+import com.streamvault.domain.settings.SettingsXtreamLiveOnboarding
import com.streamvault.domain.settings.DatabaseMaintenanceSnapshot
import com.streamvault.domain.model.Category
import com.streamvault.domain.model.CategorySortMode
@@ -89,7 +89,7 @@ data class XtreamLiveOnboardingUiModel(
}.joinToString(" • ")
}
-fun XtreamLiveOnboardingStateEntity.toUiModel(): XtreamLiveOnboardingUiModel =
+fun SettingsXtreamLiveOnboarding.toUiModel(): XtreamLiveOnboardingUiModel =
XtreamLiveOnboardingUiModel(
phase = phase,
importStrategy = importStrategy.orEmpty(),
diff --git a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsProviderActions.kt b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsProviderActions.kt
index 4c56b5ea..db3ee8e2 100644
--- a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsProviderActions.kt
+++ b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsProviderActions.kt
@@ -15,7 +15,7 @@ import com.streamvault.domain.usecase.SyncProvider
import com.streamvault.domain.usecase.SyncProviderCommand
import com.streamvault.domain.usecase.SyncProviderResult
import com.streamvault.domain.util.PersistedTimestampPolicy
-import com.streamvault.data.sync.ProviderSyncCommands
+import com.streamvault.domain.settings.SettingsOperations
import com.streamvault.domain.settings.SettingsPreferences
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
@@ -36,7 +36,7 @@ internal class SettingsProviderActions(
private val combinedM3uRepository: CombinedM3uRepository,
private val preferencesRepository: SettingsPreferences,
private val syncProvider: SyncProvider,
- private val syncManager: ProviderSyncCommands,
+ private val settingsOperations: SettingsOperations,
private val syncMetadataRepository: SyncMetadataRepository,
private val surfaceRefreshPort: SettingsSurfaceRefreshPort,
private val uiState: MutableStateFlow<SettingsUiState>
@@ -385,7 +385,7 @@ internal class SettingsProviderActions(
syncingProviderName = providerName
)
}
- syncManager.scheduleBackgroundEpgSync(providerId)
+ settingsOperations.scheduleBackgroundEpgSync(providerId)
}
uiState.update { state ->
@@ -429,7 +429,7 @@ internal class SettingsProviderActions(
currentGeneration.takeIf { it > appliedGeneration }
}
val result = if (provider?.type == ProviderType.XTREAM_CODES) {
- syncManager.rebuildXtreamIndex(providerId) { message ->
+ settingsOperations.rebuildXtreamIndex(providerId) { message ->
uiState.update { state ->
state.copy(syncProgress = message, syncingProviderName = providerName)
}
diff --git a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsSyncActions.kt b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsSyncActions.kt
index b72c85a3..48153914 100644
--- a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsSyncActions.kt
+++ b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsSyncActions.kt
@@ -3,8 +3,8 @@ package com.streamvault.feature.settings.presentation
import android.content.Context
import com.streamvault.feature.settings.R
import com.streamvault.feature.settings.api.SettingsSurfaceRefreshPort
-import com.streamvault.data.sync.ProviderSyncCommands
-import com.streamvault.data.sync.SyncRepairSection
+import com.streamvault.domain.settings.SettingsOperations
+import com.streamvault.domain.settings.SettingsSyncSection
import com.streamvault.domain.model.ProviderType
import com.streamvault.domain.model.Result
import kotlinx.coroutines.CoroutineScope
@@ -16,7 +16,7 @@ import kotlinx.coroutines.launch
internal class SettingsSyncActions(
private val appContext: Context,
- private val syncManager: ProviderSyncCommands,
+ private val settingsOperations: SettingsOperations,
private val surfaceRefreshPort: SettingsSurfaceRefreshPort,
private val uiState: MutableStateFlow<SettingsUiState>,
private val refreshProvider: (CoroutineScope, Long, SettingsProviderSyncMode, String?, Long, String?, Boolean) -> Job
@@ -109,11 +109,11 @@ internal class SettingsSyncActions(
)
}
val section = when (action) {
- ProviderWarningAction.EPG -> SyncRepairSection.EPG
- ProviderWarningAction.MOVIES -> SyncRepairSection.MOVIES
- ProviderWarningAction.SERIES -> SyncRepairSection.SERIES
+ ProviderWarningAction.EPG -> SettingsSyncSection.EPG
+ ProviderWarningAction.MOVIES -> SettingsSyncSection.MOVIES
+ ProviderWarningAction.SERIES -> SettingsSyncSection.SERIES
}
- val result = syncManager.retrySection(providerId, section) { progress ->
+ val result = settingsOperations.retryProviderSection(providerId, section) { progress ->
uiState.update { state ->
state.copy(
syncProgress = progress,
@@ -194,10 +194,10 @@ internal class SettingsSyncActions(
selections.forEach { selection ->
val sectionLabel = selection.label(appContext)
val section = when (selection) {
- ProviderSyncSelection.TV -> SyncRepairSection.LIVE
- ProviderSyncSelection.MOVIES -> SyncRepairSection.MOVIES
- ProviderSyncSelection.SERIES -> SyncRepairSection.SERIES
- ProviderSyncSelection.EPG -> SyncRepairSection.EPG
+ ProviderSyncSelection.TV -> SettingsSyncSection.LIVE
+ ProviderSyncSelection.MOVIES -> SettingsSyncSection.MOVIES
+ ProviderSyncSelection.SERIES -> SettingsSyncSection.SERIES
+ ProviderSyncSelection.EPG -> SettingsSyncSection.EPG
ProviderSyncSelection.SYNC_NOW, ProviderSyncSelection.REBUILD_INDEX -> null
} ?: return@forEach
@@ -212,7 +212,7 @@ internal class SettingsSyncActions(
)
}
- when (val result = syncManager.retrySection(providerId, section) { progress ->
+ when (val result = settingsOperations.retryProviderSection(providerId, section) { progress ->
uiState.update { state ->
state.copy(
syncProgress = progress,
diff --git a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsViewModel.kt b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsViewModel.kt
index dc5121a2..eacdcd87 100644
--- a/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsViewModel.kt
+++ b/feature/settings/src/main/java/com/streamvault/feature/settings/presentation/SettingsViewModel.kt
@@ -13,13 +13,9 @@ import com.streamvault.feature.settings.api.SettingsSurfaceRefreshPort
import com.streamvault.domain.model.LiveTvChannelMode
import com.streamvault.domain.model.LiveTvQuickFilterVisibilityMode
import com.streamvault.domain.model.VodViewMode
-import com.streamvault.data.local.dao.ProgramDao
-import com.streamvault.data.local.dao.XtreamIndexJobDao
-import com.streamvault.data.local.dao.XtreamLiveOnboardingDao
-import com.streamvault.data.local.entity.XtreamIndexJobEntity
import com.streamvault.domain.settings.SettingsPreferences
-import com.streamvault.data.sync.ProviderSyncCommands
-import com.streamvault.data.sync.SyncRepairSection
+import com.streamvault.domain.settings.SettingsOperations
+import com.streamvault.domain.settings.SettingsXtreamIndexJob
import com.streamvault.domain.model.VodCategoryLoadMode
import com.streamvault.domain.manager.BackupConflictStrategy
import com.streamvault.domain.manager.BackupImportPlan
@@ -103,7 +99,7 @@ class SettingsViewModel @Inject constructor(
private val channelRepository: ChannelRepository,
private val movieRepository: MovieRepository,
private val seriesRepository: SeriesRepository,
- private val programDao: ProgramDao,
+ private val settingsOperations: SettingsOperations,
private val preferencesRepository: SettingsPreferences,
private val internetSpeedTestRunner: InternetSpeedTestRunner,
private val backupManager: BackupManager,
@@ -111,9 +107,6 @@ class SettingsViewModel @Inject constructor(
private val driveBackupSyncManager: DriveBackupSyncManager,
private val recordingManager: RecordingManager,
private val parentalControlManager: ParentalControlManager,
- private val syncManager: ProviderSyncCommands,
- private val xtreamIndexJobDao: XtreamIndexJobDao,
- private val xtreamLiveOnboardingDao: XtreamLiveOnboardingDao,
private val syncMetadataRepository: SyncMetadataRepository,
private val playbackHistoryRepository: com.streamvault.domain.repository.PlaybackHistoryRepository,
private val surfaceRefreshPort: SettingsSurfaceRefreshPort,
@@ -164,14 +157,14 @@ class SettingsViewModel @Inject constructor(
combinedM3uRepository = combinedM3uRepository,
preferencesRepository = preferencesRepository,
syncProvider = syncProvider,
- syncManager = syncManager,
+ settingsOperations = settingsOperations,
syncMetadataRepository = syncMetadataRepository,
surfaceRefreshPort = surfaceRefreshPort,
uiState = _uiState
)
private val syncActions = SettingsSyncActions(
appContext = application,
- syncManager = syncManager,
+ settingsOperations = settingsOperations,
surfaceRefreshPort = surfaceRefreshPort,
uiState = _uiState,
refreshProvider = { scope, providerId, syncMode, progressPrefix, startedAt, sectionLabel, isCancelable ->
@@ -214,7 +207,7 @@ class SettingsViewModel @Inject constructor(
syncMetadataRepository = syncMetadataRepository,
movieRepository = movieRepository,
seriesRepository = seriesRepository,
- programDao = programDao,
+ settingsOperations = settingsOperations,
application = appContext,
preferencesRepository = preferencesRepository,
activeProviderIdFlow = activeProviderIdFlow,
@@ -313,7 +306,7 @@ class SettingsViewModel @Inject constructor(
private fun registerXtreamIndexJobObserver() {
viewModelScope.launch {
- xtreamIndexJobDao.observeAll().collect { jobs ->
+ settingsOperations.observeXtreamIndexJobs().collect { jobs ->
val jobWarningsByProvider = jobs
.groupBy { it.providerId }
.mapValues { (_, providerJobs) ->
@@ -364,7 +357,7 @@ class SettingsViewModel @Inject constructor(
private fun registerXtreamLiveOnboardingObserver() {
viewModelScope.launch {
- xtreamLiveOnboardingDao.observeIncomplete().collect { states ->
+ settingsOperations.observeIncompleteXtreamLiveOnboarding().collect { states ->
_uiState.update { state ->
val providerIds = state.providers.map { it.id }.toSet()
state.copy(
@@ -380,7 +373,7 @@ class SettingsViewModel @Inject constructor(
}
}
- private fun XtreamIndexJobEntity.toSettingsWarningMessage(): String? {
+ private fun SettingsXtreamIndexJob.toSettingsWarningMessage(): String? {
val label = when (section) {
"LIVE" -> "Live TV"
"MOVIE" -> "Movies"
@@ -1234,7 +1227,7 @@ class SettingsViewModel @Inject constructor(
}
if (provider == null) {
failures += reference.serverUrl
- } else if (syncManager.sync(provider.id, force = true) is Result.Error) {
+ } else if (settingsOperations.syncProvider(provider.id, force = true) is Result.Error) {
failures += provider.name
}
}
diff --git a/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObserversTest.kt b/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObserversTest.kt
index 220e3518..d54633b5 100644
--- a/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObserversTest.kt
+++ b/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsDerivedStateObserversTest.kt
@@ -3,7 +3,7 @@ package com.streamvault.feature.settings.presentation
import android.content.Context
import com.google.common.truth.Truth.assertThat
import com.streamvault.feature.settings.R
-import com.streamvault.data.local.dao.ProgramDao
+import com.streamvault.domain.settings.SettingsOperations
import com.streamvault.domain.model.LegacyProvider as Provider
import com.streamvault.domain.model.ProviderType
import com.streamvault.domain.model.SyncMetadata
@@ -23,7 +23,7 @@ class SettingsDerivedStateObserversTest {
private val syncMetadataRepository: SyncMetadataRepository = mock()
private val movieRepository: MovieRepository = mock()
private val seriesRepository: SeriesRepository = mock()
- private val programDao: ProgramDao = mock()
+ private val settingsOperations: SettingsOperations = mock()
private val application: Context = mock()
@Test
@@ -47,7 +47,7 @@ class SettingsDerivedStateObserversTest {
)
whenever(movieRepository.getLibraryCount(7L)).thenReturn(flowOf(140_484))
whenever(seriesRepository.getLibraryCount(7L)).thenReturn(flowOf(32_037))
- whenever(programDao.observeCountByProvider(7L)).thenReturn(flowOf(18_422))
+ whenever(settingsOperations.observeProgramCount(7L)).thenReturn(flowOf(18_422))
whenever(application.getString(R.string.settings_capability_xtream_without_epg))
.thenReturn("Xtream without EPG")
@@ -56,7 +56,7 @@ class SettingsDerivedStateObserversTest {
syncMetadataRepository = syncMetadataRepository,
movieRepository = movieRepository,
seriesRepository = seriesRepository,
- programDao = programDao,
+ settingsOperations = settingsOperations,
application = application
).first()
diff --git a/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsOperationalModelsTest.kt b/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsOperationalModelsTest.kt
new file mode 100644
index 00000000..80e4456a
--- /dev/null
+++ b/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsOperationalModelsTest.kt
@@ -0,0 +1,43 @@
+package com.streamvault.feature.settings.presentation
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.settings.SettingsXtreamLiveOnboarding
+import org.junit.Test
+
+class SettingsOperationalModelsTest {
+ @Test
+ fun `onboarding snapshot maps every settings-facing field to ui model`() {
+ val snapshot = SettingsXtreamLiveOnboarding(
+ providerId = 12L,
+ phase = "INDEXING",
+ importStrategy = "STREAMING",
+ acceptedRowCount = 72,
+ stagedFlushCount = 4,
+ syncProfileTier = "LOW",
+ syncProfileBatchSize = 16,
+ syncProfileStrategy = "SEQUENTIAL",
+ syncProfileLowMemory = true,
+ syncProfileMemoryClassMb = 384,
+ syncProfileAvailableMemMb = 192L,
+ lastError = "malformed row",
+ updatedAt = 456L
+ )
+
+ assertThat(snapshot.toUiModel()).isEqualTo(
+ XtreamLiveOnboardingUiModel(
+ phase = "INDEXING",
+ importStrategy = "STREAMING",
+ acceptedRowCount = 72,
+ stagedFlushCount = 4,
+ profileTier = "LOW",
+ profileBatchSize = 16,
+ profileStrategy = "SEQUENTIAL",
+ lowMemory = true,
+ memoryClassMb = 384,
+ availableMemMb = 192L,
+ lastError = "malformed row",
+ updatedAt = 456L
+ )
+ )
+ }
+}
diff --git a/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsProviderActionsTest.kt b/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsProviderActionsTest.kt
index c2acdc74..5387796b 100644
--- a/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsProviderActionsTest.kt
+++ b/feature/settings/src/test/java/com/streamvault/feature/settings/presentation/SettingsProviderActionsTest.kt
@@ -2,7 +2,7 @@ package com.streamvault.feature.settings.presentation
import com.google.common.truth.Truth.assertThat
import com.streamvault.domain.settings.SettingsPreferences
-import com.streamvault.data.sync.SyncManager
+import com.streamvault.domain.settings.SettingsOperations
import com.streamvault.domain.model.ActiveLiveSource
import com.streamvault.domain.model.LegacyProvider as Provider
import com.streamvault.domain.model.ProviderType
@@ -33,7 +33,7 @@ class SettingsProviderActionsTest {
private val combinedM3uRepository: CombinedM3uRepository = mock()
private val preferencesRepository: SettingsPreferences = mock()
private val syncProvider: SyncProvider = mock()
- private val syncManager: SyncManager = mock()
+ private val settingsOperations: SettingsOperations = mock()
private val syncMetadataRepository: SyncMetadataRepository = mock()
private val surfaceRefreshPort: SettingsSurfaceRefreshPort = mock()
private val uiState = MutableStateFlow(SettingsUiState())
@@ -43,7 +43,7 @@ class SettingsProviderActionsTest {
combinedM3uRepository = combinedM3uRepository,
preferencesRepository = preferencesRepository,
syncProvider = syncProvider,
- syncManager = syncManager,
+ settingsOperations = settingsOperations,
syncMetadataRepository = syncMetadataRepository,
surfaceRefreshPort = surfaceRefreshPort,
uiState = uiState