StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
feat(phase-6): implement final polish, performance optimizations, and ci pipeline
Davidona99744adbaff6
diff --git a/.github/workflows/android.yml b/.github/workflows/android.ymlnew file mode 100644index 00000000..0865883f--- /dev/null+++ b/.github/workflows/android.yml@@ -0,0 +1,42 @@+name: Android CI++on:+ push:+ branches: [ "main" ]+ pull_request:+ branches: [ "main" ]++jobs:+ build:++ runs-on: ubuntu-latest++ steps:+ - uses: actions/checkout@v4++ - name: set up JDK 17+ uses: actions/setup-java@v3+ with:+ java-version: '17'+ distribution: 'temurin'+ cache: gradle++ - name: Grant execute permission for gradlew+ run: chmod +x gradlew++ - name: Compile Code+ run: ./gradlew assembleDebug++ - name: Run Unit Tests+ run: ./gradlew testDebugUnitTest --continue++ - name: Upload Test Reports+ if: always()+ uses: actions/upload-artifact@v3+ with:+ name: test-reports+ path: |+ app/build/reports/tests/+ data/build/reports/tests/+ domain/build/reports/tests/+ player/build/reports/tests/diff --git a/app/build.gradle.kts b/app/build.gradle.ktsindex 94b25f3e..90d84bb8 100644--- a/app/build.gradle.kts+++ b/app/build.gradle.kts@@ -100,4 +100,10 @@ dependencies {// Coreimplementation(libs.core.ktx)implementation(libs.coroutines.android)++ // Test+ testImplementation(libs.junit)+ testImplementation(libs.truth)+ testImplementation(libs.coroutines.test)+ testImplementation(libs.mockito.kotlin)}diff --git a/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt b/app/src/main/java/com/streamvault/app/di/DatabaseModule.ktindex 9b7b7eee..a3178681 100644--- a/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt+++ b/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt@@ -25,7 +25,8 @@ object DatabaseModule {).addMigrations(StreamVaultDatabase.MIGRATION_2_3,- StreamVaultDatabase.MIGRATION_3_4+ StreamVaultDatabase.MIGRATION_3_4,+ StreamVaultDatabase.MIGRATION_4_5)// NOTE: fallbackToDestructiveMigration() intentionally removed.// All future schema changes MUST add a corresponding Migration in StreamVaultDatabase.diff --git a/app/src/test/java/com/streamvault/app/ui/screens/home/HomeViewModelTest.kt b/app/src/test/java/com/streamvault/app/ui/screens/home/HomeViewModelTest.ktnew file mode 100644index 00000000..69b9965e--- /dev/null+++ b/app/src/test/java/com/streamvault/app/ui/screens/home/HomeViewModelTest.kt@@ -0,0 +1,106 @@+package com.streamvault.app.ui.screens.home++import com.streamvault.data.preferences.PreferencesRepository+import com.streamvault.domain.manager.ParentalControlManager+import com.streamvault.domain.model.Category+import com.streamvault.domain.model.Channel+import com.streamvault.domain.model.Provider+import com.streamvault.domain.repository.*+import com.streamvault.domain.usecase.GetCustomCategories+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.flow.flowOf+import kotlinx.coroutines.test.*+import org.junit.After+import org.junit.Before+import org.junit.Test+import org.mockito.kotlin.*+import com.google.common.truth.Truth.assertThat++@OptIn(ExperimentalCoroutinesApi::class)+class HomeViewModelTest {++ private val providerRepository: ProviderRepository = mock()+ private val channelRepository: ChannelRepository = mock()+ private val categoryRepository: CategoryRepository = mock()+ private val favoriteRepository: FavoriteRepository = mock()+ private val preferencesRepository: PreferencesRepository = mock()+ private val epgRepository: EpgRepository = mock()+ private val getCustomCategories: GetCustomCategories = mock()+ private val parentalControlManager: ParentalControlManager = mock()++ private lateinit var viewModel: HomeViewModel++ private val testDispatcher = StandardTestDispatcher()++ @Before+ fun setup() {+ Dispatchers.setMain(testDispatcher)++ // Mock default flows to prevent exceptions during init+ whenever(providerRepository.getProviders()).thenReturn(flowOf(emptyList()))+ whenever(providerRepository.getActiveProvider()).thenReturn(flowOf(null))+ whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))+ whenever(favoriteRepository.getFavorites(any())).thenReturn(flowOf(emptyList()))+ whenever(preferencesRepository.defaultCategoryId).thenReturn(flowOf(null))++ viewModel = HomeViewModel(+ providerRepository,+ channelRepository,+ categoryRepository,+ favoriteRepository,+ preferencesRepository,+ epgRepository,+ getCustomCategories,+ parentalControlManager+ )+ }++ @After+ fun tearDown() {+ Dispatchers.resetMain()+ }++ @Test+ fun `when switchProvider is called, it delegates to repository`() = runTest {+ viewModel.switchProvider(1L)+ runCurrent()+ verify(providerRepository).setActiveProvider(1L)+ }++ @Test+ fun `initial state has empty categories and is loading`() = runTest {+ val state = viewModel.uiState.value+ assertThat(state.isLoading).isTrue()+ assertThat(state.categories).isEmpty()+ assertThat(state.filteredChannels).isEmpty()+ }++ @Test+ fun `updateCategorySearchQuery updates state`() = runTest {+ viewModel.updateCategorySearchQuery("News")+ assertThat(viewModel.uiState.value.categorySearchQuery).isEqualTo("News")+ }++ @Test+ fun `updateChannelSearchQuery updates state and triggers filtering`() = runTest {+ viewModel.updateChannelSearchQuery("CNN")+ assertThat(viewModel.uiState.value.channelSearchQuery).isEqualTo("CNN")+ }++ @Test+ fun `selectCategory sets selected category and triggers loading`() = runTest {+ val category = Category(id = 1L, name = "Sports", parentId = null)++ // Mock the repositories needed for loading channels+ whenever(channelRepository.getChannelsByCategory(any(), any())).thenReturn(flowOf(emptyList()))+ val provider = Provider(id = 1L, name = "Provider", type = com.streamvault.domain.model.ProviderType.M3U, serverUrl = "http://test")+ whenever(providerRepository.getActiveProvider()).thenReturn(flowOf(provider))++ viewModel.selectCategory(category)++ val state = viewModel.uiState.value+ assertThat(state.selectedCategory).isEqualTo(category)+ verify(parentalControlManager).clearUnlockedCategories()+ }+}diff --git a/data/schemas/com.streamvault.data.local.StreamVaultDatabase/5.json b/data/schemas/com.streamvault.data.local.StreamVaultDatabase/5.jsonnew file mode 100644index 00000000..cf9f34ea--- /dev/null+++ b/data/schemas/com.streamvault.data.local.StreamVaultDatabase/5.json@@ -0,0 +1,1290 @@+{+ "formatVersion": 1,+ "database": {+ "version": 5,+ "identityHash": "739618369fdcb6f821372ca1bb9f84ae",+ "entities": [+ {+ "tableName": "providers",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `type` TEXT NOT NULL, `server_url` TEXT NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, `m3u_url` TEXT NOT NULL, `epg_url` TEXT NOT NULL, `is_active` INTEGER NOT NULL, `max_connections` INTEGER NOT NULL, `expiration_date` INTEGER, `status` TEXT NOT NULL, `last_synced_at` INTEGER NOT NULL, `created_at` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "name",+ "columnName": "name",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "type",+ "columnName": "type",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "serverUrl",+ "columnName": "server_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "username",+ "columnName": "username",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "password",+ "columnName": "password",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "m3uUrl",+ "columnName": "m3u_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "epgUrl",+ "columnName": "epg_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "isActive",+ "columnName": "is_active",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "maxConnections",+ "columnName": "max_connections",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "expirationDate",+ "columnName": "expiration_date",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "status",+ "columnName": "status",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "lastSyncedAt",+ "columnName": "last_synced_at",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "createdAt",+ "columnName": "created_at",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_providers_server_url_username",+ "unique": true,+ "columnNames": [+ "server_url",+ "username"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_providers_server_url_username` ON `${TABLE_NAME}` (`server_url`, `username`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "channels",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `stream_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `logo_url` TEXT, `group_title` TEXT, `category_id` INTEGER, `category_name` TEXT, `stream_url` TEXT NOT NULL, `epg_channel_id` TEXT, `number` INTEGER NOT NULL, `catch_up_supported` INTEGER NOT NULL, `catch_up_days` INTEGER NOT NULL, `catchUpSource` TEXT, `provider_id` INTEGER NOT NULL, `is_adult` INTEGER NOT NULL, `is_user_protected` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "streamId",+ "columnName": "stream_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "name",+ "columnName": "name",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "logoUrl",+ "columnName": "logo_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "groupTitle",+ "columnName": "group_title",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "categoryId",+ "columnName": "category_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "categoryName",+ "columnName": "category_name",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "streamUrl",+ "columnName": "stream_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "epgChannelId",+ "columnName": "epg_channel_id",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "number",+ "columnName": "number",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "catchUpSupported",+ "columnName": "catch_up_supported",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "catchUpDays",+ "columnName": "catch_up_days",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "catchUpSource",+ "columnName": "catchUpSource",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isAdult",+ "columnName": "is_adult",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isUserProtected",+ "columnName": "is_user_protected",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_channels_provider_id",+ "unique": false,+ "columnNames": [+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_channels_provider_id` ON `${TABLE_NAME}` (`provider_id`)"+ },+ {+ "name": "index_channels_provider_id_category_id",+ "unique": false,+ "columnNames": [+ "provider_id",+ "category_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_channels_provider_id_category_id` ON `${TABLE_NAME}` (`provider_id`, `category_id`)"+ },+ {+ "name": "index_channels_provider_id_stream_id",+ "unique": true,+ "columnNames": [+ "provider_id",+ "stream_id"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_channels_provider_id_stream_id` ON `${TABLE_NAME}` (`provider_id`, `stream_id`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "movies",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `stream_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `poster_url` TEXT, `backdrop_url` TEXT, `category_id` INTEGER, `category_name` TEXT, `stream_url` TEXT NOT NULL, `container_extension` TEXT, `plot` TEXT, `cast` TEXT, `director` TEXT, `genre` TEXT, `release_date` TEXT, `duration` TEXT, `duration_seconds` INTEGER NOT NULL, `rating` REAL NOT NULL, `year` TEXT, `tmdb_id` INTEGER, `youtube_trailer` TEXT, `provider_id` INTEGER NOT NULL, `watch_progress` INTEGER NOT NULL, `last_watched_at` INTEGER NOT NULL, `is_adult` INTEGER NOT NULL, `is_user_protected` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "streamId",+ "columnName": "stream_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "name",+ "columnName": "name",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "posterUrl",+ "columnName": "poster_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "backdropUrl",+ "columnName": "backdrop_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "categoryId",+ "columnName": "category_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "categoryName",+ "columnName": "category_name",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "streamUrl",+ "columnName": "stream_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "containerExtension",+ "columnName": "container_extension",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "plot",+ "columnName": "plot",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "cast",+ "columnName": "cast",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "director",+ "columnName": "director",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "genre",+ "columnName": "genre",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "releaseDate",+ "columnName": "release_date",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "duration",+ "columnName": "duration",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "durationSeconds",+ "columnName": "duration_seconds",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "rating",+ "columnName": "rating",+ "affinity": "REAL",+ "notNull": true+ },+ {+ "fieldPath": "year",+ "columnName": "year",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "tmdbId",+ "columnName": "tmdb_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "youtubeTrailer",+ "columnName": "youtube_trailer",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "watchProgress",+ "columnName": "watch_progress",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastWatchedAt",+ "columnName": "last_watched_at",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isAdult",+ "columnName": "is_adult",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isUserProtected",+ "columnName": "is_user_protected",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_movies_provider_id",+ "unique": false,+ "columnNames": [+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_movies_provider_id` ON `${TABLE_NAME}` (`provider_id`)"+ },+ {+ "name": "index_movies_provider_id_category_id",+ "unique": false,+ "columnNames": [+ "provider_id",+ "category_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_movies_provider_id_category_id` ON `${TABLE_NAME}` (`provider_id`, `category_id`)"+ },+ {+ "name": "index_movies_provider_id_stream_id",+ "unique": true,+ "columnNames": [+ "provider_id",+ "stream_id"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_movies_provider_id_stream_id` ON `${TABLE_NAME}` (`provider_id`, `stream_id`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "series",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `series_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `poster_url` TEXT, `backdrop_url` TEXT, `category_id` INTEGER, `category_name` TEXT, `plot` TEXT, `cast` TEXT, `director` TEXT, `genre` TEXT, `release_date` TEXT, `rating` REAL NOT NULL, `tmdb_id` INTEGER, `youtube_trailer` TEXT, `episode_run_time` TEXT, `last_modified` INTEGER NOT NULL, `provider_id` INTEGER NOT NULL, `is_adult` INTEGER NOT NULL, `is_user_protected` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "seriesId",+ "columnName": "series_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "name",+ "columnName": "name",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "posterUrl",+ "columnName": "poster_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "backdropUrl",+ "columnName": "backdrop_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "categoryId",+ "columnName": "category_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "categoryName",+ "columnName": "category_name",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "plot",+ "columnName": "plot",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "cast",+ "columnName": "cast",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "director",+ "columnName": "director",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "genre",+ "columnName": "genre",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "releaseDate",+ "columnName": "release_date",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "rating",+ "columnName": "rating",+ "affinity": "REAL",+ "notNull": true+ },+ {+ "fieldPath": "tmdbId",+ "columnName": "tmdb_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "youtubeTrailer",+ "columnName": "youtube_trailer",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "episodeRunTime",+ "columnName": "episode_run_time",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "lastModified",+ "columnName": "last_modified",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isAdult",+ "columnName": "is_adult",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isUserProtected",+ "columnName": "is_user_protected",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_series_provider_id",+ "unique": false,+ "columnNames": [+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_series_provider_id` ON `${TABLE_NAME}` (`provider_id`)"+ },+ {+ "name": "index_series_provider_id_category_id",+ "unique": false,+ "columnNames": [+ "provider_id",+ "category_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_series_provider_id_category_id` ON `${TABLE_NAME}` (`provider_id`, `category_id`)"+ },+ {+ "name": "index_series_provider_id_series_id",+ "unique": true,+ "columnNames": [+ "provider_id",+ "series_id"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_series_provider_id_series_id` ON `${TABLE_NAME}` (`provider_id`, `series_id`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "episodes",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `episode_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `episode_number` INTEGER NOT NULL, `season_number` INTEGER NOT NULL, `stream_url` TEXT NOT NULL, `container_extension` TEXT, `cover_url` TEXT, `plot` TEXT, `duration` TEXT, `duration_seconds` INTEGER NOT NULL, `rating` REAL NOT NULL, `release_date` TEXT, `series_id` INTEGER NOT NULL, `provider_id` INTEGER NOT NULL, `watch_progress` INTEGER NOT NULL, `last_watched_at` INTEGER NOT NULL, `is_adult` INTEGER NOT NULL, `is_user_protected` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "episodeId",+ "columnName": "episode_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "title",+ "columnName": "title",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "episodeNumber",+ "columnName": "episode_number",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "seasonNumber",+ "columnName": "season_number",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "streamUrl",+ "columnName": "stream_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "containerExtension",+ "columnName": "container_extension",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "coverUrl",+ "columnName": "cover_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "plot",+ "columnName": "plot",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "duration",+ "columnName": "duration",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "durationSeconds",+ "columnName": "duration_seconds",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "rating",+ "columnName": "rating",+ "affinity": "REAL",+ "notNull": true+ },+ {+ "fieldPath": "releaseDate",+ "columnName": "release_date",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "seriesId",+ "columnName": "series_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "watchProgress",+ "columnName": "watch_progress",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastWatchedAt",+ "columnName": "last_watched_at",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isAdult",+ "columnName": "is_adult",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isUserProtected",+ "columnName": "is_user_protected",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_episodes_series_id",+ "unique": false,+ "columnNames": [+ "series_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_episodes_series_id` ON `${TABLE_NAME}` (`series_id`)"+ },+ {+ "name": "index_episodes_provider_id",+ "unique": false,+ "columnNames": [+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_episodes_provider_id` ON `${TABLE_NAME}` (`provider_id`)"+ },+ {+ "name": "index_episodes_provider_id_episode_id",+ "unique": true,+ "columnNames": [+ "provider_id",+ "episode_id"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_episodes_provider_id_episode_id` ON `${TABLE_NAME}` (`provider_id`, `episode_id`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "categories",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `category_id` INTEGER NOT NULL, `name` TEXT NOT NULL, `parent_id` INTEGER, `type` TEXT NOT NULL, `provider_id` INTEGER NOT NULL, `is_adult` INTEGER NOT NULL, `is_user_protected` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "categoryId",+ "columnName": "category_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "name",+ "columnName": "name",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "parentId",+ "columnName": "parent_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "type",+ "columnName": "type",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isAdult",+ "columnName": "is_adult",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "isUserProtected",+ "columnName": "is_user_protected",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_categories_provider_id",+ "unique": false,+ "columnNames": [+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_categories_provider_id` ON `${TABLE_NAME}` (`provider_id`)"+ },+ {+ "name": "index_categories_provider_id_category_id_type",+ "unique": true,+ "columnNames": [+ "provider_id",+ "category_id",+ "type"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_categories_provider_id_category_id_type` ON `${TABLE_NAME}` (`provider_id`, `category_id`, `type`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "programs",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `channel_id` TEXT NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, `start_time` INTEGER NOT NULL, `end_time` INTEGER NOT NULL, `lang` TEXT NOT NULL, `has_archive` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "channelId",+ "columnName": "channel_id",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "title",+ "columnName": "title",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "description",+ "columnName": "description",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "startTime",+ "columnName": "start_time",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "endTime",+ "columnName": "end_time",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lang",+ "columnName": "lang",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "hasArchive",+ "columnName": "has_archive",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_programs_channel_id",+ "unique": false,+ "columnNames": [+ "channel_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_programs_channel_id` ON `${TABLE_NAME}` (`channel_id`)"+ },+ {+ "name": "index_programs_start_time",+ "unique": false,+ "columnNames": [+ "start_time"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_programs_start_time` ON `${TABLE_NAME}` (`start_time`)"+ },+ {+ "name": "index_programs_channel_id_start_time",+ "unique": false,+ "columnNames": [+ "channel_id",+ "start_time"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_programs_channel_id_start_time` ON `${TABLE_NAME}` (`channel_id`, `start_time`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "favorites",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `content_id` INTEGER NOT NULL, `content_type` TEXT NOT NULL, `position` INTEGER NOT NULL, `group_id` INTEGER, `added_at` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "contentId",+ "columnName": "content_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "contentType",+ "columnName": "content_type",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "position",+ "columnName": "position",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "groupId",+ "columnName": "group_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "addedAt",+ "columnName": "added_at",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_favorites_content_id_content_type_group_id",+ "unique": true,+ "columnNames": [+ "content_id",+ "content_type",+ "group_id"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_favorites_content_id_content_type_group_id` ON `${TABLE_NAME}` (`content_id`, `content_type`, `group_id`)"+ },+ {+ "name": "index_favorites_content_type_group_id",+ "unique": false,+ "columnNames": [+ "content_type",+ "group_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_favorites_content_type_group_id` ON `${TABLE_NAME}` (`content_type`, `group_id`)"+ },+ {+ "name": "index_favorites_group_id_position",+ "unique": false,+ "columnNames": [+ "group_id",+ "position"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_favorites_group_id_position` ON `${TABLE_NAME}` (`group_id`, `position`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "virtual_groups",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `icon_emoji` TEXT, `position` INTEGER NOT NULL, `created_at` INTEGER NOT NULL)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "name",+ "columnName": "name",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "iconEmoji",+ "columnName": "icon_emoji",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "position",+ "columnName": "position",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "createdAt",+ "columnName": "created_at",+ "affinity": "INTEGER",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_virtual_groups_position",+ "unique": false,+ "columnNames": [+ "position"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_virtual_groups_position` ON `${TABLE_NAME}` (`position`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "playback_history",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `content_id` INTEGER NOT NULL, `content_type` TEXT NOT NULL, `provider_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `poster_url` TEXT, `stream_url` TEXT NOT NULL, `resume_position_ms` INTEGER NOT NULL, `total_duration_ms` INTEGER NOT NULL, `last_watched_at` INTEGER NOT NULL, `watch_count` INTEGER NOT NULL, `series_id` INTEGER, `season_number` INTEGER, `episode_number` INTEGER)",+ "fields": [+ {+ "fieldPath": "id",+ "columnName": "id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "contentId",+ "columnName": "content_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "contentType",+ "columnName": "content_type",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "title",+ "columnName": "title",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "posterUrl",+ "columnName": "poster_url",+ "affinity": "TEXT",+ "notNull": false+ },+ {+ "fieldPath": "streamUrl",+ "columnName": "stream_url",+ "affinity": "TEXT",+ "notNull": true+ },+ {+ "fieldPath": "resumePositionMs",+ "columnName": "resume_position_ms",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "totalDurationMs",+ "columnName": "total_duration_ms",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastWatchedAt",+ "columnName": "last_watched_at",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "watchCount",+ "columnName": "watch_count",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "seriesId",+ "columnName": "series_id",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "seasonNumber",+ "columnName": "season_number",+ "affinity": "INTEGER",+ "notNull": false+ },+ {+ "fieldPath": "episodeNumber",+ "columnName": "episode_number",+ "affinity": "INTEGER",+ "notNull": false+ }+ ],+ "primaryKey": {+ "autoGenerate": true,+ "columnNames": [+ "id"+ ]+ },+ "indices": [+ {+ "name": "index_playback_history_content_id_content_type_provider_id",+ "unique": true,+ "columnNames": [+ "content_id",+ "content_type",+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_playback_history_content_id_content_type_provider_id` ON `${TABLE_NAME}` (`content_id`, `content_type`, `provider_id`)"+ },+ {+ "name": "index_playback_history_last_watched_at",+ "unique": false,+ "columnNames": [+ "last_watched_at"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_playback_history_last_watched_at` ON `${TABLE_NAME}` (`last_watched_at`)"+ },+ {+ "name": "index_playback_history_provider_id",+ "unique": false,+ "columnNames": [+ "provider_id"+ ],+ "orders": [],+ "createSql": "CREATE INDEX IF NOT EXISTS `index_playback_history_provider_id` ON `${TABLE_NAME}` (`provider_id`)"+ }+ ],+ "foreignKeys": []+ },+ {+ "tableName": "sync_metadata",+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`provider_id` INTEGER NOT NULL, `last_live_sync` INTEGER NOT NULL, `last_movie_sync` INTEGER NOT NULL, `last_series_sync` INTEGER NOT NULL, `last_epg_sync` INTEGER NOT NULL, `live_count` INTEGER NOT NULL, `movie_count` INTEGER NOT NULL, `series_count` INTEGER NOT NULL, `epg_count` INTEGER NOT NULL, `last_sync_status` TEXT NOT NULL, PRIMARY KEY(`provider_id`))",+ "fields": [+ {+ "fieldPath": "providerId",+ "columnName": "provider_id",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastLiveSync",+ "columnName": "last_live_sync",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastMovieSync",+ "columnName": "last_movie_sync",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastSeriesSync",+ "columnName": "last_series_sync",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastEpgSync",+ "columnName": "last_epg_sync",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "liveCount",+ "columnName": "live_count",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "movieCount",+ "columnName": "movie_count",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "seriesCount",+ "columnName": "series_count",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "epgCount",+ "columnName": "epg_count",+ "affinity": "INTEGER",+ "notNull": true+ },+ {+ "fieldPath": "lastSyncStatus",+ "columnName": "last_sync_status",+ "affinity": "TEXT",+ "notNull": true+ }+ ],+ "primaryKey": {+ "autoGenerate": false,+ "columnNames": [+ "provider_id"+ ]+ },+ "indices": [],+ "foreignKeys": []+ }+ ],+ "views": [],+ "setupQueries": [+ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '739618369fdcb6f821372ca1bb9f84ae')"+ ]+ }+}\ No newline at end of filediff --git a/data/src/androidTest/java/com/streamvault/data/local/MovieDaoTest.kt b/data/src/androidTest/java/com/streamvault/data/local/MovieDaoTest.ktnew file mode 100644index 00000000..73a0fd05--- /dev/null+++ b/data/src/androidTest/java/com/streamvault/data/local/MovieDaoTest.kt@@ -0,0 +1,67 @@+package com.streamvault.data.local++import android.content.Context+import androidx.room.Room+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.streamvault.data.local.dao.MovieDao+import com.streamvault.data.local.dao.PlaybackHistoryDao+import com.streamvault.data.local.entity.MovieEntity+import com.streamvault.data.local.entity.PlaybackHistoryEntity+import kotlinx.coroutines.test.runTest+import org.junit.After+import org.junit.Before+import org.junit.Test+import org.junit.runner.RunWith+import com.google.common.truth.Truth.assertThat+import java.io.IOException++@RunWith(AndroidJUnit4::class)+class MovieDaoTest {+ private lateinit var db: StreamVaultDatabase+ private lateinit var movieDao: MovieDao+ private lateinit var historyDao: PlaybackHistoryDao++ @Before+ fun createDb() {+ val context = ApplicationProvider.getApplicationContext<Context>()+ db = Room.inMemoryDatabaseBuilder(+ context, StreamVaultDatabase::class.java+ ).build()+ movieDao = db.movieDao()+ historyDao = db.playbackHistoryDao()+ }++ @After+ @Throws(IOException::class)+ fun closeDb() {+ db.close()+ }++ @Test+ fun testRestoreWatchProgress() = runTest {+ // 1. Insert history for a movie. Use contentId = 1L+ val history = PlaybackHistoryEntity(+ contentId = 1L,+ contentType = "MOVIE",+ providerId = 1L,+ resumePositionMs = 5000L,+ lastWatchedAt = 10000L+ )+ historyDao.insertOrUpdate(history)++ // 2. Replace movies in provider 1. Give it ID 1L+ val movie = MovieEntity(+ id = 1L, // MUST MATCH contentId in history+ name = "Test Movie",+ providerId = 1L,+ watchProgress = 0L // default+ )+ movieDao.replaceAll(1L, listOf(movie))++ // 3. Verify watch progress was restored from history during replaceAll+ val restoredMovie = movieDao.getById(1L)+ assertThat(restoredMovie).isNotNull()+ assertThat(restoredMovie?.watchProgress).isEqualTo(5000L)+ }+}diff --git a/data/src/androidTest/java/com/streamvault/data/local/ProgramDaoTest.kt b/data/src/androidTest/java/com/streamvault/data/local/ProgramDaoTest.ktnew file mode 100644index 00000000..542656a1--- /dev/null+++ b/data/src/androidTest/java/com/streamvault/data/local/ProgramDaoTest.kt@@ -0,0 +1,111 @@+package com.streamvault.data.local++import android.content.Context+import androidx.room.Room+import androidx.test.core.app.ApplicationProvider+import androidx.test.ext.junit.runners.AndroidJUnit4+import com.streamvault.data.local.dao.ProgramDao+import com.streamvault.data.local.entity.ProgramEntity+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.test.runTest+import org.junit.After+import org.junit.Before+import org.junit.Test+import org.junit.runner.RunWith+import com.google.common.truth.Truth.assertThat+import java.io.IOException++@RunWith(AndroidJUnit4::class)+class ProgramDaoTest {+ private lateinit var db: StreamVaultDatabase+ private lateinit var programDao: ProgramDao++ @Before+ fun createDb() {+ val context = ApplicationProvider.getApplicationContext<Context>()+ db = Room.inMemoryDatabaseBuilder(+ context, StreamVaultDatabase::class.java+ ).build()+ programDao = db.programDao()+ }++ @After+ @Throws(IOException::class)+ fun closeDb() {+ db.close()+ }++ @Test+ fun writeProgramsAndReadInList() = runTest {+ val program = ProgramEntity(+ channelId = "channel1",+ title = "Test Program",+ description = "Test Desc",+ startTime = 1000L,+ endTime = 2000L,+ lang = "en",+ hasArchive = false+ )+ programDao.insertAll(listOf(program))+ val byChannel = programDao.getForChannel("channel1", 500L, 2500L).first()+ assertThat(byChannel).hasSize(1)+ assertThat(byChannel[0].title).isEqualTo("Test Program")+ }++ @Test+ fun deleteOldPrograms() = runTest {+ val program1 = ProgramEntity(+ channelId = "channel1",+ title = "Old Program",+ startTime = 100L,+ endTime = 500L+ )+ val program2 = ProgramEntity(+ channelId = "channel1",+ title = "New Program",+ startTime = 1000L,+ endTime = 1500L+ )+ programDao.insertAll(listOf(program1, program2))++ // Delete older than 800L+ programDao.deleteOld(800L)++ val all = programDao.getForChannel("channel1", 0L, 2000L).first()+ assertThat(all).hasSize(1)+ assertThat(all[0].title).isEqualTo("New Program")+ }++ @Test+ fun getNowPlayingForChannels() = runTest {+ val program1 = ProgramEntity(+ channelId = "channel1",+ title = "Now Playing 1",+ startTime = 1000L,+ endTime = 2000L+ )+ val program2 = ProgramEntity(+ channelId = "channel2",+ title = "Now Playing 2",+ startTime = 1500L,+ endTime = 2500L+ )+ val program3 = ProgramEntity(+ channelId = "channel2",+ title = "Next Playing 2",+ startTime = 2500L,+ endTime = 3500L+ )+ programDao.insertAll(listOf(program1, program2, program3))++ // Check around time 1600L+ val nowPlaying = programDao.getNowPlayingForChannels(listOf("channel1", "channel2"), 1600L).first()+ assertThat(nowPlaying).hasSize(2)+ assertThat(nowPlaying.map { it.title }).containsExactly("Now Playing 1", "Now Playing 2")++ // Check around time 2200L+ val laterPlaying = programDao.getNowPlayingForChannels(listOf("channel1", "channel2"), 2200L).first()+ assertThat(laterPlaying).hasSize(1)+ assertThat(laterPlaying[0].title).isEqualTo("Now Playing 2")+ }+}diff --git a/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt b/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.ktindex 2355e342..98ad7408 100644--- a/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt+++ b/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt@@ -21,7 +21,7 @@ import com.streamvault.data.local.entity.*PlaybackHistoryEntity::class,SyncMetadataEntity::class],- version = 4,+ version = 5,exportSchema = true // ← was false; schema JSON now tracked in version control)abstract class StreamVaultDatabase : RoomDatabase() {@@ -108,5 +108,28 @@ abstract class StreamVaultDatabase : RoomDatabase() {""")}}++ val MIGRATION_4_5 = object : Migration(4, 5) {+ override fun migrate(database: SupportSQLiteDatabase) {+ // Note: Room auto-generates index names as 'index_tableName_columnNames'+ // Channels+ database.execSQL("DROP INDEX IF EXISTS index_channels_category_id")+ database.execSQL("CREATE INDEX IF NOT EXISTS index_channels_provider_id_category_id ON channels(provider_id, category_id)")++ // Movies+ database.execSQL("DROP INDEX IF EXISTS index_movies_category_id")+ database.execSQL("CREATE INDEX IF NOT EXISTS index_movies_provider_id_category_id ON movies(provider_id, category_id)")++ // Series+ database.execSQL("DROP INDEX IF EXISTS index_series_category_id")+ database.execSQL("CREATE INDEX IF NOT EXISTS index_series_provider_id_category_id ON series(provider_id, category_id)")++ // Favorites+ database.execSQL("DROP INDEX IF EXISTS index_favorites_group_id")+ database.execSQL("DROP INDEX IF EXISTS index_favorites_position")+ database.execSQL("CREATE INDEX IF NOT EXISTS index_favorites_content_type_group_id ON favorites(content_type, group_id)")+ database.execSQL("CREATE INDEX IF NOT EXISTS index_favorites_group_id_position ON favorites(group_id, position)")+ }+ }}}diff --git a/data/src/main/java/com/streamvault/data/local/entity/Entities.kt b/data/src/main/java/com/streamvault/data/local/entity/Entities.ktindex 440cd3a8..dc25b976 100644--- a/data/src/main/java/com/streamvault/data/local/entity/Entities.kt+++ b/data/src/main/java/com/streamvault/data/local/entity/Entities.kt@@ -31,7 +31,7 @@ data class ProviderEntity(tableName = "channels",indices = [Index(value = ["provider_id"]),- Index(value = ["category_id"]),+ Index(value = ["provider_id", "category_id"]),Index(value = ["provider_id", "stream_id"], unique = true)])@@ -59,7 +59,7 @@ data class ChannelEntity(tableName = "movies",indices = [Index(value = ["provider_id"]),- Index(value = ["category_id"]),+ Index(value = ["provider_id", "category_id"]),Index(value = ["provider_id", "stream_id"], unique = true)])@@ -96,7 +96,7 @@ data class MovieEntity(tableName = "series",indices = [Index(value = ["provider_id"]),- Index(value = ["category_id"]),+ Index(value = ["provider_id", "category_id"]),Index(value = ["provider_id", "series_id"], unique = true)])@@ -198,8 +198,8 @@ data class ProgramEntity(tableName = "favorites",indices = [Index(value = ["content_id", "content_type", "group_id"], unique = true),- Index(value = ["group_id"]),- Index(value = ["position"])+ Index(value = ["content_type", "group_id"]),+ Index(value = ["group_id", "position"])])data class FavoriteEntity(diff --git a/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt b/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.ktindex 6388d187..dbbd18b0 100644--- a/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt+++ b/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt@@ -265,6 +265,6 @@ class SyncManagerTest {) = M3uParser.M3uEntry(name = "Test", groupTitle = group,tvgId = null, tvgName = null, tvgLogo = null, tvgChno = null,- catchUp = null, catchUpSource = null, url = url+ catchUp = null, catchUpDays = null, catchUpSource = null, url = url)}