Skip to content

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

refactor(live): move Home UI state

David Nashashe38b07a607f5
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreenDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreenDialogs.kt
index 40c73919..ff98d248 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreenDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreenDialogs.kt
@@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.streamvault.app.R
+import com.streamvault.feature.live.presentation.home.HomeUiState
import com.streamvault.app.navigation.Routes
import com.streamvault.core.ui.components.SearchInput
import com.streamvault.app.ui.components.dialogs.AddToGroupDialog
@@ -133,8 +134,9 @@ internal fun HomeDialogsHost(
)
}
- if (uiState.selectedCategoryForOptions != null) {
- val category = uiState.selectedCategoryForOptions
+ val selectedCategoryForOptions = uiState.selectedCategoryForOptions
+ if (selectedCategoryForOptions != null) {
+ val category = selectedCategoryForOptions
val isCategoryLocked =
(category.isAdult || category.isUserProtected) &&
uiState.parentalControlLevel in 1..2 &&
@@ -252,8 +254,9 @@ internal fun HomeDialogsHost(
)
}
- if (uiState.showDialog && uiState.selectedChannelForDialog != null && pendingSplitPlannerChannel == null) {
- val channel = uiState.selectedChannelForDialog
+ val selectedChannelForDialog = uiState.selectedChannelForDialog
+ if (uiState.showDialog && selectedChannelForDialog != null && pendingSplitPlannerChannel == null) {
+ val channel = selectedChannelForDialog
AddToGroupDialog(
contentTitle = channel.name,
channel = channel,
@@ -345,9 +348,10 @@ internal fun HomeDialogsHost(
)
}
- if (uiState.showRenameGroupDialog && uiState.groupToRename != null) {
+ val groupToRename = uiState.groupToRename
+ if (uiState.showRenameGroupDialog && groupToRename != null) {
RenameGroupDialog(
- initialName = uiState.groupToRename.name,
+ initialName = groupToRename.name,
errorMessage = uiState.renameGroupError,
onDismissRequest = { viewModel.cancelRenameGroup() },
onConfirm = { name -> viewModel.confirmRenameGroup(name) }
@@ -367,8 +371,9 @@ internal fun HomeDialogsHost(
)
}
- if (uiState.showDeleteGroupDialog && uiState.groupToDelete != null) {
- val group = uiState.groupToDelete
+ val groupToDelete = uiState.groupToDelete
+ if (uiState.showDeleteGroupDialog && groupToDelete != null) {
+ val group = groupToDelete
var canInteract by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
delay(500)
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
index 4ae84b82..b101998b 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
@@ -54,6 +54,7 @@ import com.streamvault.domain.usecase.UnlockParentalCategoryCommand
import com.streamvault.player.PlaybackState
import com.streamvault.player.PlayerEngine
import com.streamvault.feature.live.presentation.home.HomePreviewUiState
+import com.streamvault.feature.live.presentation.home.HomeUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import com.streamvault.app.R
import java.util.concurrent.CancellationException
@@ -2072,55 +2073,6 @@ class HomeViewModel @Inject constructor(
}
}
-data class HomeUiState(
- val provider: Provider? = null,
- val activeLiveSource: ActiveLiveSource? = null,
- val activeLiveSourceTitle: String = "",
- val isCombinedLiveSource: Boolean = false,
- val liveSourceOptions: List<ActiveLiveSourceOption> = emptyList(),
- val currentCombinedProfileMembers: List<CombinedM3uProfileMember> = emptyList(),
- val selectedCombinedSourceProviderId: Long? = null,
- val showLiveSourceSwitcher: Boolean = false,
- val allProviders: List<Provider> = emptyList(),
- val categories: List<Category> = emptyList(),
- val recentChannels: List<Channel> = emptyList(),
- val lastVisitedCategory: Category? = null,
- val selectedCategory: Category? = null,
- val filteredChannels: List<Channel> = emptyList(),
- val hasChannels: Boolean = false,
- val hasMoreChannels: Boolean = false,
- val isLoading: Boolean = true,
- val isCategoriesLoading: Boolean = true,
- val isSyncing: Boolean = false,
- val categorySearchQuery: String = "",
- val savedCategoryFilters: List<String> = emptyList(),
- val activeCategoryFilter: String? = null,
- val liveTvQuickFilterVisibilityMode: LiveTvQuickFilterVisibilityMode = LiveTvQuickFilterVisibilityMode.ALWAYS_VISIBLE,
- val channelSearchQuery: String = "",
- val showDialog: Boolean = false,
- val selectedChannelForDialog: Channel? = null,
- val dialogGroupMemberships: List<Long> = emptyList(),
- val showHiddenChannelsDialog: Boolean = false,
- val userMessage: String? = null,
- val showRenameGroupDialog: Boolean = false,
- val groupToRename: Category? = null,
- val renameGroupError: String? = null,
- val showDeleteGroupDialog: Boolean = false,
- val groupToDelete: Category? = null,
- val parentalControlLevel: Int = 0,
- val unlockedCategoryIds: Set<Long> = emptySet(),
- val pinnedCategoryIds: Set<Long> = emptySet(),
- val hiddenLiveCategories: List<Category> = emptyList(),
- val shouldAutoFocusFirstChannelOnEntry: Boolean = false,
- val selectedCategoryForOptions: Category? = null,
- val isChannelReorderMode: Boolean = false,
- val reorderCategory: Category? = null,
- val liveTvChannelMode: LiveTvChannelMode = LiveTvChannelMode.PRO,
- val errorMessage: String? = null,
- val multiviewChannelCount: Int = 0,
- val multiviewSlotCapacity: Int = 4
-)
-
private data class CategorySelectionContext(
val categories: List<Category>,
val defaultCategoryId: Long?,
diff --git a/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/HomeUiState.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/HomeUiState.kt
new file mode 100644
index 00000000..12b9260b
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/HomeUiState.kt
@@ -0,0 +1,60 @@
+package com.streamvault.feature.live.presentation.home
+
+import com.streamvault.domain.model.ActiveLiveSource
+import com.streamvault.domain.model.ActiveLiveSourceOption
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.model.CombinedM3uProfileMember
+import com.streamvault.domain.model.LiveTvChannelMode
+import com.streamvault.domain.model.LiveTvQuickFilterVisibilityMode
+import com.streamvault.domain.model.LegacyProvider as Provider
+import com.streamvault.domain.model.Channel
+
+/** State rendered by the Home Live TV surface. Kept in the Live feature with its presentation state. */
+data class HomeUiState(
+ val provider: Provider? = null,
+ val activeLiveSource: ActiveLiveSource? = null,
+ val activeLiveSourceTitle: String = "",
+ val isCombinedLiveSource: Boolean = false,
+ val liveSourceOptions: List<ActiveLiveSourceOption> = emptyList(),
+ val currentCombinedProfileMembers: List<CombinedM3uProfileMember> = emptyList(),
+ val selectedCombinedSourceProviderId: Long? = null,
+ val showLiveSourceSwitcher: Boolean = false,
+ val allProviders: List<Provider> = emptyList(),
+ val categories: List<Category> = emptyList(),
+ val recentChannels: List<Channel> = emptyList(),
+ val lastVisitedCategory: Category? = null,
+ val selectedCategory: Category? = null,
+ val filteredChannels: List<Channel> = emptyList(),
+ val hasChannels: Boolean = false,
+ val hasMoreChannels: Boolean = false,
+ val isLoading: Boolean = true,
+ val isCategoriesLoading: Boolean = true,
+ val isSyncing: Boolean = false,
+ val categorySearchQuery: String = "",
+ val savedCategoryFilters: List<String> = emptyList(),
+ val activeCategoryFilter: String? = null,
+ val liveTvQuickFilterVisibilityMode: LiveTvQuickFilterVisibilityMode = LiveTvQuickFilterVisibilityMode.ALWAYS_VISIBLE,
+ val channelSearchQuery: String = "",
+ val showDialog: Boolean = false,
+ val selectedChannelForDialog: Channel? = null,
+ val dialogGroupMemberships: List<Long> = emptyList(),
+ val showHiddenChannelsDialog: Boolean = false,
+ val userMessage: String? = null,
+ val showRenameGroupDialog: Boolean = false,
+ val groupToRename: Category? = null,
+ val renameGroupError: String? = null,
+ val showDeleteGroupDialog: Boolean = false,
+ val groupToDelete: Category? = null,
+ val parentalControlLevel: Int = 0,
+ val unlockedCategoryIds: Set<Long> = emptySet(),
+ val pinnedCategoryIds: Set<Long> = emptySet(),
+ val hiddenLiveCategories: List<Category> = emptyList(),
+ val shouldAutoFocusFirstChannelOnEntry: Boolean = false,
+ val selectedCategoryForOptions: Category? = null,
+ val isChannelReorderMode: Boolean = false,
+ val reorderCategory: Category? = null,
+ val liveTvChannelMode: LiveTvChannelMode = LiveTvChannelMode.PRO,
+ val errorMessage: String? = null,
+ val multiviewChannelCount: Int = 0,
+ val multiviewSlotCapacity: Int = 4
+)