Skip to content

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

feat: Category Options dialog (Set Default, Lock/Unlock, Delete) + fix playlist edit saving + fix ghost clicks

Davidona6dea5ff8d1d8
diff --git a/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt b/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt
index 0ef4a266..5956c83f 100644
--- a/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt
+++ b/app/src/main/java/com/streamvault/app/di/DatabaseModule.kt
@@ -23,6 +23,7 @@ object DatabaseModule {
StreamVaultDatabase::class.java,
"streamvault.db"
)
+ .addMigrations(StreamVaultDatabase.MIGRATION_2_3)
.fallbackToDestructiveMigration()
.build()
diff --git a/app/src/main/java/com/streamvault/app/di/RepositoryModule.kt b/app/src/main/java/com/streamvault/app/di/RepositoryModule.kt
index f2bfde94..f0fa506c 100644
--- a/app/src/main/java/com/streamvault/app/di/RepositoryModule.kt
+++ b/app/src/main/java/com/streamvault/app/di/RepositoryModule.kt
@@ -36,6 +36,9 @@ abstract class RepositoryModule {
@Binds @Singleton
abstract fun bindFavoriteRepository(impl: FavoriteRepositoryImpl): FavoriteRepository
+ @Binds @Singleton
+ abstract fun bindCategoryRepository(impl: CategoryRepositoryImpl): CategoryRepository
+
@Binds @Singleton
abstract fun bindPlayerEngine(impl: Media3PlayerEngine): PlayerEngine
diff --git a/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt b/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt
index a2909374..17b9c499 100644
--- a/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt
+++ b/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt
@@ -27,6 +27,7 @@ object Routes {
const val SEARCH = "search"
const val SERIES_DETAIL = "series_detail/{seriesId}"
const val WELCOME = "welcome"
+ const val PARENTAL_CONTROL_GROUPS = "parental_control_groups/{providerId}"
fun providerSetup(providerId: Long? = null) = "provider_setup?providerId=${providerId ?: -1L}"
@@ -46,6 +47,7 @@ object Routes {
}
fun seriesDetail(seriesId: Long) = "series_detail/$seriesId"
+ fun parentalControlGroups(providerId: Long) = "parental_control_groups/$providerId"
}
@Composable
@@ -187,10 +189,32 @@ fun AppNavigation() {
onEditProvider = { provider ->
navController.navigate(Routes.providerSetup(provider.id))
},
+ onNavigateToParentalControl = { providerId ->
+ navController.navigate(Routes.parentalControlGroups(providerId))
+ },
currentRoute = Routes.SETTINGS
)
}
+ composable(
+ route = Routes.PARENTAL_CONTROL_GROUPS,
+ arguments = listOf(
+ navArgument("providerId") { type = NavType.LongType }
+ )
+ ) {
+ com.streamvault.app.ui.screens.settings.parental.ParentalControlGroupScreen(
+ currentRoute = Routes.SETTINGS,
+ onNavigate = { route ->
+ navController.navigate(route) {
+ popUpTo(Routes.HOME) { saveState = true }
+ launchSingleTop = true
+ restoreState = true
+ }
+ },
+ onBack = { navController.popBackStack() }
+ )
+ }
+
composable(Routes.SEARCH) {
com.streamvault.app.ui.screens.search.SearchScreen(
onChannelClick = { channel ->
diff --git a/app/src/main/java/com/streamvault/app/ui/components/Cards.kt b/app/src/main/java/com/streamvault/app/ui/components/Cards.kt
index b0c54d38..bdf07175 100644
--- a/app/src/main/java/com/streamvault/app/ui/components/Cards.kt
+++ b/app/src/main/java/com/streamvault/app/ui/components/Cards.kt
@@ -222,7 +222,8 @@ fun MovieCard(
movie: Movie,
onClick: () -> Unit,
modifier: Modifier = Modifier,
- onLongClick: (() -> Unit)? = null
+ onLongClick: (() -> Unit)? = null,
+ isLocked: Boolean = false
) {
FocusableCard(
onClick = onClick,
@@ -231,7 +232,7 @@ fun MovieCard(
width = 160.dp,
height = 240.dp
) { isFocused ->
- if (!movie.posterUrl.isNullOrBlank()) {
+ if (!movie.posterUrl.isNullOrBlank() && !isLocked) {
AsyncImage(
model = movie.posterUrl,
contentDescription = movie.name,
@@ -248,7 +249,7 @@ fun MovieCard(
.padding(LocalSpacing.current.sm)
) {
Text(
- text = movie.name,
+ text = if (isLocked) "Locked Movie" else movie.name,
style = MaterialTheme.typography.bodySmall,
color = if (isFocused) OnBackground else OnSurface,
maxLines = 2,
@@ -257,7 +258,7 @@ fun MovieCard(
}
// Rating badge
- if (movie.rating > 0f) {
+ if (movie.rating > 0f && !isLocked) {
Box(
modifier = Modifier
.align(Alignment.TopEnd)
@@ -281,6 +282,19 @@ fun MovieCard(
}
}
}
+
+ // Lock Overlay
+ if (isLocked) {
+ Box(
+ modifier = Modifier.fillMaxSize(),
+ contentAlignment = Alignment.Center
+ ) {
+ Text(
+ text = "πŸ”’",
+ style = MaterialTheme.typography.displayMedium
+ )
+ }
+ }
}
}
@@ -291,7 +305,8 @@ fun SeriesCard(
series: Series,
onClick: () -> Unit,
modifier: Modifier = Modifier,
- onLongClick: (() -> Unit)? = null
+ onLongClick: (() -> Unit)? = null,
+ isLocked: Boolean = false
) {
FocusableCard(
onClick = onClick,
@@ -300,7 +315,7 @@ fun SeriesCard(
width = 160.dp,
height = 240.dp
) { isFocused ->
- if (!series.posterUrl.isNullOrBlank()) {
+ if (!series.posterUrl.isNullOrBlank() && !isLocked) {
AsyncImage(
model = series.posterUrl,
contentDescription = series.name,
@@ -316,12 +331,25 @@ fun SeriesCard(
.padding(LocalSpacing.current.sm)
) {
Text(
- text = series.name,
+ text = if (isLocked) "Locked Series" else series.name,
style = MaterialTheme.typography.bodySmall,
color = if (isFocused) OnBackground else OnSurface,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
}
+
+ // Lock Overlay
+ if (isLocked) {
+ Box(
+ modifier = Modifier.fillMaxSize(),
+ contentAlignment = Alignment.Center
+ ) {
+ Text(
+ text = "πŸ”’",
+ style = MaterialTheme.typography.displayMedium
+ )
+ }
+ }
}
}
diff --git a/app/src/main/java/com/streamvault/app/ui/components/dialogs/CategoryOptionsDialog.kt b/app/src/main/java/com/streamvault/app/ui/components/dialogs/CategoryOptionsDialog.kt
new file mode 100644
index 00000000..1a2e394c
--- /dev/null
+++ b/app/src/main/java/com/streamvault/app/ui/components/dialogs/CategoryOptionsDialog.kt
@@ -0,0 +1,89 @@
+package com.streamvault.app.ui.components.dialogs
+
+import androidx.compose.foundation.layout.*
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.TextButton
+import androidx.tv.material3.Text
+import androidx.tv.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import com.streamvault.domain.model.Category
+
+
+import androidx.compose.runtime.*
+import kotlinx.coroutines.delay
+
+@Composable
+fun CategoryOptionsDialog(
+ category: Category,
+ onDismissRequest: () -> Unit,
+ onSetAsDefault: () -> Unit,
+ onToggleLock: () -> Unit,
+ onDelete: (() -> Unit)? = null
+) {
+ // Fix for ghost clicks: Debounce interaction for 500ms to ignore long-press release
+ var canInteract by remember { mutableStateOf(false) }
+ LaunchedEffect(Unit) {
+ delay(500)
+ canInteract = true
+ }
+
+ val safeDismiss = {
+ if (canInteract) onDismissRequest()
+ }
+
+ AlertDialog(
+ onDismissRequest = safeDismiss,
+ title = { Text(text = category.name, style = MaterialTheme.typography.titleLarge) },
+ text = {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+
+ // Option 1: Set as Default
+ androidx.compose.material3.Button(
+ onClick = { if (canInteract) onSetAsDefault() },
+ modifier = Modifier.fillMaxWidth(),
+ colors = androidx.compose.material3.ButtonDefaults.buttonColors(
+ containerColor = MaterialTheme.colorScheme.surfaceVariant,
+ contentColor = MaterialTheme.colorScheme.onSurface
+ )
+ ) {
+ Text("Set as Default Group")
+ }
+
+ // Option 2: Lock/Unlock
+ val lockText = if (category.isUserProtected) "Unlock Group" else "Lock Group"
+ androidx.compose.material3.Button(
+ onClick = { if (canInteract) onToggleLock() },
+ modifier = Modifier.fillMaxWidth(),
+ colors = androidx.compose.material3.ButtonDefaults.buttonColors(
+ containerColor = MaterialTheme.colorScheme.surfaceVariant,
+ contentColor = MaterialTheme.colorScheme.onSurface
+ )
+ ) {
+ Text(lockText)
+ }
+
+ // Option 3: Delete (Optional)
+ if (onDelete != null) {
+ androidx.compose.material3.Button(
+ onClick = { if (canInteract) onDelete() },
+ modifier = Modifier.fillMaxWidth(),
+ colors = androidx.compose.material3.ButtonDefaults.buttonColors(
+ containerColor = MaterialTheme.colorScheme.errorContainer,
+ contentColor = MaterialTheme.colorScheme.onErrorContainer
+ )
+ ) {
+ Text("Delete Group")
+ }
+ }
+ }
+ },
+ confirmButton = {},
+ dismissButton = {
+ TextButton(onClick = safeDismiss) {
+ Text("Cancel")
+ }
+ }
+ )
+}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
index 082f3c07..e2878e40 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
@@ -20,6 +20,8 @@ import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.input.key.onPreviewKeyEvent
+import androidx.compose.material.icons.filled.Lock
+import androidx.compose.material.icons.Icons
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
@@ -31,6 +33,7 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.TextButton
import com.streamvault.app.ui.components.CategoryRow
import com.streamvault.app.ui.components.ChannelCard
+import com.streamvault.app.ui.components.dialogs.CategoryOptionsDialog
import com.streamvault.app.ui.components.dialogs.PinDialog
import com.streamvault.app.ui.components.TopNavBar
import com.streamvault.app.ui.theme.*
@@ -50,16 +53,18 @@ import kotlinx.coroutines.launch
import javax.inject.Inject
import com.streamvault.domain.usecase.GetCustomCategories
-// ── ViewModel ──────────────────────────────────────────────────────
+
@HiltViewModel
class HomeViewModel @Inject constructor(
private val providerRepository: ProviderRepository,
private val channelRepository: ChannelRepository,
+ private val categoryRepository: com.streamvault.domain.repository.CategoryRepository,
private val favoriteRepository: com.streamvault.domain.repository.FavoriteRepository,
private val preferencesRepository: PreferencesRepository,
private val epgRepository: EpgRepository,
- private val getCustomCategories: com.streamvault.domain.usecase.GetCustomCategories
+ private val getCustomCategories: com.streamvault.domain.usecase.GetCustomCategories,
+ private val parentalControlManager: com.streamvault.domain.manager.ParentalControlManager
) : ViewModel() {
private val _uiState = MutableStateFlow(HomeUiState())
@@ -143,21 +148,29 @@ class HomeViewModel @Inject constructor(
private fun loadCategoriesAndChannels(providerId: Long) {
categoriesJob?.cancel()
categoriesJob = viewModelScope.launch {
- // Combine provider categories with custom categories
+ // Combine provider categories, custom categories, and default category preference
combine(
channelRepository.getCategories(providerId),
- getCustomCategories()
- ) { providerCats, customCats ->
- customCats + providerCats
- }.collect { categories ->
+ getCustomCategories(),
+ preferencesRepository.defaultCategoryId
+ ) { providerCats, customCats, defaultId ->
+ Triple(customCats + providerCats, defaultId, Unit)
+ }.collect { (categories, defaultId, _) ->
_uiState.update { it.copy(categories = categories) }
val currentSelected = _uiState.value.selectedCategory
if (currentSelected == null && categories.isNotEmpty()) {
- // Initial selection
+ // Initial selection logic:
+ // 1. Default Category (if set and exists)
+ // 2. Favorites (id -999, if exists)
+ // 3. First available category
+ val defaultCat = defaultId?.let { id -> categories.find { it.id == id } }
val favoritesCat = categories.find { it.id == -999L }
- if (favoritesCat != null) {
+
+ if (defaultCat != null) {
+ selectCategory(defaultCat)
+ } else if (favoritesCat != null) {
selectCategory(favoritesCat)
} else {
selectCategory(categories.first())
@@ -174,10 +187,14 @@ class HomeViewModel @Inject constructor(
// Refresh content. Do NOT set isLoading=true here to avoid flickering.
loadChannelsForCategory(reselectedCat)
} else {
- // Category disappeared (deleted group?), fallback to default
+ // Category disappeared (deleted group?), fallback to default logic
+ val defaultCat = defaultId?.let { id -> categories.find { it.id == id } }
val favoritesCat = categories.find { it.id == -999L }
- if (favoritesCat != null) {
- selectCategory(favoritesCat)
+
+ if (defaultCat != null) {
+ selectCategory(defaultCat)
+ } else if (favoritesCat != null) {
+ selectCategory(favoritesCat)
} else if (categories.isNotEmpty()) {
selectCategory(categories.first())
}
@@ -191,6 +208,9 @@ class HomeViewModel @Inject constructor(
// Fix for Bug 1: Prevent double-click from reloading/clearing if already selected
if (_uiState.value.selectedCategory?.id == category.id) return
+ // Ephemeral Unlock: switching category re-locks everything
+ parentalControlManager.clearUnlockedCategories()
+
_uiState.update { it.copy(selectedCategory = category, isLoading = true) }
loadChannelsForCategory(category)
}
@@ -434,6 +454,33 @@ class HomeViewModel @Inject constructor(
val storedPin = preferencesRepository.parentalPin.firstOrNull() ?: "0000"
return pin == storedPin
}
+
+ fun unlockCategory(category: Category) {
+ parentalControlManager.unlockCategory(category.id)
+ }
+
+ fun setDefaultCategory(category: Category) {
+ viewModelScope.launch {
+ preferencesRepository.setDefaultCategory(category.id)
+ _uiState.update { it.copy(userMessage = "Set '${category.name}' as default") }
+ }
+ }
+
+ fun toggleCategoryLock(category: Category) {
+ viewModelScope.launch {
+ val newStatus = !category.isUserProtected
+ categoryRepository.setCategoryProtection(category.id, newStatus)
+ val msg = if (newStatus) "Locked '${category.name}'" else "Unlocked '${category.name}'"
+ _uiState.update { it.copy(userMessage = msg) }
+ }
+ }
+ fun showCategoryOptions(category: Category) {
+ _uiState.update { it.copy(selectedCategoryForOptions = category) }
+ }
+
+ fun dismissCategoryOptions() {
+ _uiState.update { it.copy(selectedCategoryForOptions = null) }
+ }
}
data class HomeUiState(
@@ -452,7 +499,8 @@ data class HomeUiState(
val userMessage: String? = null,
val showDeleteGroupDialog: Boolean = false,
val groupToDelete: Category? = null,
- val parentalControlLevel: Int = 0
+ val parentalControlLevel: Int = 0,
+ val selectedCategoryForOptions: Category? = null
)
// ── Screen ─────────────────────────────────────────────────────────
@@ -472,6 +520,7 @@ fun HomeScreen(
var pinError by remember { mutableStateOf<String?>(null) }
var pendingUnlockCategory by remember { mutableStateOf<Category?>(null) }
var pendingUnlockChannel by remember { mutableStateOf<Channel?>(null) }
+ var pendingLockToggleCategory by remember { mutableStateOf<Category?>(null) }
val scope = rememberCoroutineScope()
LaunchedEffect(uiState.userMessage) {
@@ -496,7 +545,9 @@ fun HomeScreen(
pinError = null
pendingUnlockCategory?.let { category ->
+ // Use the sequence: Select (clears old unlocks) -> Unlock (adds this one)
viewModel.selectCategory(category)
+ viewModel.unlockCategory(category)
pendingUnlockCategory = null
}
@@ -504,6 +555,11 @@ fun HomeScreen(
onChannelClick(channel, uiState.selectedCategory, uiState.provider)
pendingUnlockChannel = null
}
+
+ pendingLockToggleCategory?.let { category ->
+ viewModel.toggleCategoryLock(category)
+ pendingLockToggleCategory = null
+ }
} else {
pinError = "Incorrect PIN"
}
@@ -513,6 +569,29 @@ fun HomeScreen(
)
}
+ if (uiState.selectedCategoryForOptions != null) {
+ val category = uiState.selectedCategoryForOptions!!
+ CategoryOptionsDialog(
+ category = category,
+ onDismissRequest = { viewModel.dismissCategoryOptions() },
+ onSetAsDefault = {
+ viewModel.setDefaultCategory(category)
+ viewModel.dismissCategoryOptions()
+ },
+ onToggleLock = {
+ viewModel.dismissCategoryOptions()
+ pendingLockToggleCategory = category
+ showPinDialog = true
+ },
+ onDelete = if (category.isVirtual && category.id != -999L) {
+ {
+ viewModel.dismissCategoryOptions()
+ viewModel.requestDeleteGroup(category)
+ }
+ } else null
+ )
+ }
+
Box(modifier = Modifier.fillMaxSize()) {
Column(modifier = Modifier.fillMaxSize()) {
Row(
@@ -577,7 +656,7 @@ fun HomeScreen(
},
key = { it.id }
) { category ->
- val isLocked = category.isAdult && uiState.parentalControlLevel == 1
+ val isLocked = (category.isAdult || category.isUserProtected) && uiState.parentalControlLevel == 1
CategoryItem(
category = category,
@@ -591,7 +670,7 @@ fun HomeScreen(
viewModel.selectCategory(category)
}
},
- onLongClick = { viewModel.requestDeleteGroup(category) }
+ onLongClick = { viewModel.showCategoryOptions(category) }
)
}
}
@@ -685,7 +764,7 @@ fun HomeScreen(
items = uiState.filteredChannels,
key = { it.id }
) { channel ->
- val isLocked = channel.isAdult && uiState.parentalControlLevel == 1
+ val isLocked = (channel.isAdult || channel.isUserProtected || (uiState.selectedCategory?.isUserProtected ?: false)) && uiState.parentalControlLevel == 1
ChannelCard(
channel = channel,
@@ -860,6 +939,7 @@ fun SearchInput(
.height(56.dp)
.background(bgColor, RoundedCornerShape(8.dp))
.border(borderWidth, borderColor, RoundedCornerShape(8.dp))
+ .onFocusChanged { isFocused = it.hasFocus } // Track focus (self or child)
.clickable {
focusRequester.requestFocus()
keyboardController?.show()
@@ -884,8 +964,7 @@ fun SearchInput(
onValueChange = onValueChange,
modifier = Modifier
.fillMaxWidth()
- .focusRequester(focusRequester)
- .onFocusChanged { isFocused = it.isFocused },
+ .focusRequester(focusRequester),
textStyle = MaterialTheme.typography.bodyMedium.copy(
color = OnSurface
),
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt
index 0c31f7e6..81362e6e 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt
@@ -26,7 +26,8 @@ import javax.inject.Inject
@HiltViewModel
class MoviesViewModel @Inject constructor(
private val providerRepository: ProviderRepository,
- private val movieRepository: MovieRepository
+ private val movieRepository: MovieRepository,
+ private val preferencesRepository: com.streamvault.data.preferences.PreferencesRepository
) : ViewModel() {
private val _uiState = MutableStateFlow(MoviesUiState())
@@ -45,12 +46,23 @@ class MoviesViewModel @Inject constructor(
}
}
}
+
+ viewModelScope.launch {
+ preferencesRepository.parentalControlLevel.collect { level ->
+ _uiState.update { it.copy(parentalControlLevel = level) }
+ }
+ }
+ }
+
+ suspend fun verifyPin(pin: String): Boolean {
+ return preferencesRepository.parentalPin.first() == pin
}
}
data class MoviesUiState(
val moviesByCategory: Map<String, List<Movie>> = emptyMap(),
- val isLoading: Boolean = true
+ val isLoading: Boolean = true,
+ val parentalControlLevel: Int = 0
)
@Composable
@@ -61,6 +73,33 @@ fun MoviesScreen(
viewModel: MoviesViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsState()
+ var showPinDialog by remember { mutableStateOf(false) }
+ var pinError by remember { mutableStateOf<String?>(null) }
+ var pendingMovie by remember { mutableStateOf<Movie?>(null) }
+ val scope = rememberCoroutineScope()
+
+ if (showPinDialog) {
+ com.streamvault.app.ui.components.dialogs.PinDialog(
+ onDismissRequest = {
+ showPinDialog = false
+ pinError = null
+ pendingMovie = null
+ },
+ onPinEntered = { pin ->
+ scope.launch {
+ if (viewModel.verifyPin(pin)) {
+ showPinDialog = false
+ pinError = null
+ pendingMovie?.let { onMovieClick(it) }
+ pendingMovie = null
+ } else {
+ pinError = "Incorrect PIN"
+ }
+ }
+ },
+ error = pinError
+ )
+ }
Column(modifier = Modifier.fillMaxSize()) {
TopNavBar(currentRoute = currentRoute, onNavigate = onNavigate)
@@ -87,7 +126,19 @@ fun MoviesScreen(
key = { it.key }
) { (categoryName, movies) ->
CategoryRow(title = categoryName, items = movies) { movie ->
- MovieCard(movie = movie, onClick = { onMovieClick(movie) })
+ val isLocked = (movie.isAdult || movie.isUserProtected) && uiState.parentalControlLevel == 1
+ MovieCard(
+ movie = movie,
+ isLocked = isLocked,
+ onClick = {
+ if (isLocked) {
+ pendingMovie = movie
+ showPinDialog = true
+ } else {
+ onMovieClick(movie)
+ }
+ }
+ )
}
}
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/provider/ProviderSetupScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/provider/ProviderSetupScreen.kt
index 2004aaf9..f574aafe 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/provider/ProviderSetupScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/provider/ProviderSetupScreen.kt
@@ -88,9 +88,12 @@ class ProviderSetupViewModel @Inject constructor(
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true, validationError = null, syncProgress = "Connecting...") }
+ // Pass existingProviderId if editing
+ val existingId = if (_uiState.value.isEditing) _uiState.value.existingProviderId else null
+
when (val result = providerRepository.loginXtream(serverUrl, username, password, name, onProgress = { msg ->
_uiState.update { it.copy(syncProgress = msg) }
- })) {
+ }, id = existingId)) {
is Result.Success -> {
_uiState.update {
it.copy(isLoading = false, loginSuccess = true, error = null, syncProgress = null)
@@ -128,9 +131,12 @@ class ProviderSetupViewModel @Inject constructor(
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true, validationError = null, syncProgress = "Validating...") }
+ // Pass existingProviderId if editing
+ val existingId = if (_uiState.value.isEditing) _uiState.value.existingProviderId else null
+
when (val result = providerRepository.validateM3u(url, name, onProgress = { msg ->
_uiState.update { it.copy(syncProgress = msg) }
- })) {
+ }, id = existingId)) {
is Result.Success -> {
_uiState.update {
it.copy(isLoading = false, loginSuccess = true, error = null, syncProgress = null)
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt
index aa3ec1d0..facee3f8 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt
@@ -38,6 +38,7 @@ import com.streamvault.domain.repository.SeriesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.*
+import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
@@ -45,7 +46,8 @@ class SearchViewModel @Inject constructor(
private val providerRepository: ProviderRepository,
private val channelRepository: ChannelRepository,
private val movieRepository: MovieRepository,
- private val seriesRepository: SeriesRepository
+ private val seriesRepository: SeriesRepository,
+ private val preferencesRepository: com.streamvault.data.preferences.PreferencesRepository
) : ViewModel() {
private val _query = MutableStateFlow("")
@@ -54,16 +56,32 @@ class SearchViewModel @Inject constructor(
private val _selectedTab = MutableStateFlow(SearchTab.ALL)
val selectedTab: StateFlow<SearchTab> = _selectedTab.asStateFlow()
+ private val _parentalControlLevel = MutableStateFlow(0)
+
+ init {
+ viewModelScope.launch {
+ preferencesRepository.parentalControlLevel.collect { level ->
+ _parentalControlLevel.value = level
+ }
+ }
+ }
+
@OptIn(FlowPreview::class)
val uiState: StateFlow<SearchUiState> = combine(
providerRepository.getActiveProvider(),
_query.debounce(300),
- _selectedTab
- ) { provider, query, tab ->
- Triple(provider, query, tab)
- }.flatMapLatest { (provider, query, tab) ->
+ _selectedTab,
+ _parentalControlLevel
+ ) { provider, query, tab, level ->
+ SearchFilterParams(provider, query, tab, level)
+ }.flatMapLatest { params ->
+ val provider = params.provider
+ val query = params.query
+ val tab = params.tab
+ val level = params.level
+
if (provider == null || query.length < 2) {
- flowOf(SearchUiState())
+ flowOf(SearchUiState(parentalControlLevel = level))
} else {
val providerId = provider.id
combine(
@@ -79,7 +97,8 @@ class SearchViewModel @Inject constructor(
movies = movies,
series = series,
isLoading = false,
- hasSearched = true
+ hasSearched = true,
+ parentalControlLevel = level
)
}
}
@@ -92,8 +111,19 @@ class SearchViewModel @Inject constructor(
fun onTabSelected(tab: SearchTab) {
_selectedTab.value = tab
}
+
+ suspend fun verifyPin(pin: String): Boolean {
+ return preferencesRepository.parentalPin.first() == pin
+ }
}
+private data class SearchFilterParams(
+ val provider: com.streamvault.domain.model.Provider?,
+ val query: String,
+ val tab: SearchTab,
+ val level: Int
+)
+
enum class SearchTab(val title: String) {
ALL("All"),
LIVE("Live TV"),
@@ -106,7 +136,8 @@ data class SearchUiState(
val movies: List<Movie> = emptyList(),
val series: List<Series> = emptyList(),
val isLoading: Boolean = false,
- val hasSearched: Boolean = false
+ val hasSearched: Boolean = false,
+ val parentalControlLevel: Int = 0
) {
val isEmpty: Boolean get() = hasSearched && channels.isEmpty() && movies.isEmpty() && series.isEmpty()
}
@@ -123,32 +154,48 @@ fun SearchScreen(
val selectedTab by viewModel.selectedTab.collectAsState()
val uiState by viewModel.uiState.collectAsState()
val focusManager = LocalFocusManager.current
+ var showPinDialog by remember { mutableStateOf(false) }
+ var pinError by remember { mutableStateOf<String?>(null) }
+ var pendingChannel by remember { mutableStateOf<Channel?>(null) }
+ var pendingMovie by remember { mutableStateOf<Movie?>(null) }
+ var pendingSeries by remember { mutableStateOf<Series?>(null) }
+ val scope = rememberCoroutineScope()
+
+ if (showPinDialog) {
+ com.streamvault.app.ui.components.dialogs.PinDialog(
+ onDismissRequest = {
+ showPinDialog = false
+ pinError = null
+ pendingChannel = null
+ pendingMovie = null
+ pendingSeries = null
+ },
+ onPinEntered = { pin ->
+ scope.launch {
+ if (viewModel.verifyPin(pin)) {
+ showPinDialog = false
+ pinError = null
+ pendingChannel?.let { onChannelClick(it) }
+ pendingMovie?.let { onMovieClick(it) }
+ pendingSeries?.let { onSeriesClick(it) }
+ pendingChannel = null
+ pendingMovie = null
+ pendingSeries = null
+ } else {
+ pinError = "Incorrect PIN"
+ }
+ }
+ },
+ error = pinError
+ )
+ }
Column(
modifier = Modifier
.fillMaxSize()
.padding(24.dp)
) {
- // Search Bar
- SearchTextField(
- value = query,
- onValueChange = viewModel::onQueryChange,
- onDone = { focusManager.clearFocus() }
- )
-
- Spacer(modifier = Modifier.height(16.dp))
-
- // Tabs
- Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
- SearchTab.values().forEach { tab ->
- FilterChip(
- selected = tab == selectedTab,
- onClick = { viewModel.onTabSelected(tab) },
- content = { Text(tab.title) }
- )
- }
- }
-
+// ... (omitted SearchTextField and FilterChips) ...
Spacer(modifier = Modifier.height(24.dp))
// Results
@@ -175,9 +222,18 @@ fun SearchScreen(
}
}
items(uiState.channels) { channel ->
+ val isLocked = (channel.isAdult || channel.isUserProtected) && uiState.parentalControlLevel == 1
ChannelCard(
channel = channel,
- onClick = { onChannelClick(channel) },
+ isLocked = isLocked,
+ onClick = {
+ if (isLocked) {
+ pendingChannel = channel
+ showPinDialog = true
+ } else {
+ onChannelClick(channel)
+ }
+ },
modifier = Modifier.aspectRatio(16f/9f)
)
}
@@ -191,9 +247,18 @@ fun SearchScreen(
}
}
items(uiState.movies) { movie ->
+ val isLocked = (movie.isAdult || movie.isUserProtected) && uiState.parentalControlLevel == 1
MovieCard(
movie = movie,
- onClick = { onMovieClick(movie) },
+ isLocked = isLocked,
+ onClick = {
+ if (isLocked) {
+ pendingMovie = movie
+ showPinDialog = true
+ } else {
+ onMovieClick(movie)
+ }
+ },
modifier = Modifier.aspectRatio(2f/3f)
)
}
@@ -207,9 +272,18 @@ fun SearchScreen(
}
}
items(uiState.series) { series ->
+ val isLocked = (series.isAdult || series.isUserProtected) && uiState.parentalControlLevel == 1
SeriesCard(
series = series,
- onClick = { onSeriesClick(series) },
+ isLocked = isLocked,
+ onClick = {
+ if (isLocked) {
+ pendingSeries = series
+ showPinDialog = true
+ } else {
+ onSeriesClick(series)
+ }
+ },
modifier = Modifier.aspectRatio(2f/3f)
)
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt
index 1eaf0f37..adb8ccfe 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt
@@ -27,7 +27,8 @@ import javax.inject.Inject
@HiltViewModel
class SeriesViewModel @Inject constructor(
private val providerRepository: ProviderRepository,
- private val seriesRepository: SeriesRepository
+ private val seriesRepository: SeriesRepository,
+ private val preferencesRepository: com.streamvault.data.preferences.PreferencesRepository
) : ViewModel() {
private val _uiState = MutableStateFlow(SeriesUiState())
@@ -46,12 +47,23 @@ class SeriesViewModel @Inject constructor(
}
}
}
+
+ viewModelScope.launch {
+ preferencesRepository.parentalControlLevel.collect { level ->
+ _uiState.update { it.copy(parentalControlLevel = level) }
+ }
+ }
+ }
+
+ suspend fun verifyPin(pin: String): Boolean {
+ return preferencesRepository.parentalPin.first() == pin
}
}
data class SeriesUiState(
val seriesByCategory: Map<String, List<Series>> = emptyMap(),
- val isLoading: Boolean = true
+ val isLoading: Boolean = true,
+ val parentalControlLevel: Int = 0
)
@Composable
@@ -62,6 +74,33 @@ fun SeriesScreen(
viewModel: SeriesViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsState()
+ var showPinDialog by remember { mutableStateOf(false) }
+ var pinError by remember { mutableStateOf<String?>(null) }
+ var pendingSeriesId by remember { mutableStateOf<Long?>(null) }
+ val scope = rememberCoroutineScope()
+
+ if (showPinDialog) {
+ com.streamvault.app.ui.components.dialogs.PinDialog(
+ onDismissRequest = {
+ showPinDialog = false
+ pinError = null
+ pendingSeriesId = null
+ },
+ onPinEntered = { pin ->
+ scope.launch {
+ if (viewModel.verifyPin(pin)) {
+ showPinDialog = false
+ pinError = null
+ pendingSeriesId?.let { onSeriesClick(it) }
+ pendingSeriesId = null
+ } else {
+ pinError = "Incorrect PIN"
+ }
+ }
+ },
+ error = pinError
+ )
+ }
Column(modifier = Modifier.fillMaxSize()) {
TopNavBar(currentRoute = currentRoute, onNavigate = onNavigate)
@@ -88,10 +127,17 @@ fun SeriesScreen(
key = { it.key }
) { (categoryName, seriesList) ->
CategoryRow(title = categoryName, items = seriesList) { series ->
+ val isLocked = (series.isAdult || series.isUserProtected) && uiState.parentalControlLevel == 1
SeriesCard(
series = series,
+ isLocked = isLocked,
onClick = {
- onSeriesClick(series.id)
+ if (isLocked) {
+ pendingSeriesId = series.id
+ showPinDialog = true
+ } else {
+ onSeriesClick(series.id)
+ }
}
)
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreen.kt
index 7889ac4f..53962527 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreen.kt
@@ -138,6 +138,7 @@ fun SettingsScreen(
onNavigate: (String) -> Unit,
onAddProvider: () -> Unit = {},
onEditProvider: (Provider) -> Unit = {},
+ onNavigateToParentalControl: (Long) -> Unit = {},
currentRoute: String,
viewModel: SettingsViewModel = hiltViewModel()
) {
@@ -213,7 +214,8 @@ fun SettingsScreen(
onConnect = { viewModel.setActiveProvider(provider.id) },
onRefresh = { viewModel.refreshProvider(provider.id) },
onDelete = { viewModel.deleteProvider(provider.id) },
- onEdit = { onEditProvider(provider) }
+ onEdit = { onEditProvider(provider) },
+ onParentalControl = { onNavigateToParentalControl(provider.id) }
)
}
@@ -250,6 +252,28 @@ fun SettingsScreen(
}
}
+ // Parental Control
+ item {
+ Spacer(Modifier.height(16.dp))
+ Text(
+ text = "Parental Control",
+ style = MaterialTheme.typography.titleMedium,
+ color = Primary,
+ modifier = Modifier.padding(bottom = 8.dp)
+ )
+ ParentalControlCard(
+ level = uiState.parentalControlLevel,
+ onChangeLevel = {
+ pendingAction = ParentalAction.ChangeLevel
+ showPinDialog = true
+ },
+ onChangePin = {
+ pendingAction = ParentalAction.ChangePin
+ showPinDialog = true
+ }
+ )
+ }
+
// Decoder settings
item {
Spacer(Modifier.height(16.dp))
@@ -400,7 +424,8 @@ private fun LevelOption(level: Int, text: String, currentLevel: Int, onSelect: (
onClick = onSelect
)
Spacer(modifier = Modifier.width(8.dp))
- Text(text, style = MaterialTheme.typography.bodyMedium, color = OnBackground)
+ // Explicitly use Black for dialog text as it likely has a light background
+ Text(text, style = MaterialTheme.typography.bodyMedium, color = Color.Black)
}
}
@@ -435,8 +460,23 @@ private fun ParentalControlCard(
color = if (level == 0) ErrorColor else Primary
)
}
- Button(onClick = onChangeLevel) {
- Text("Change")
+
+ // Custom Focusable Button for "Change"
+ Surface(
+ onClick = onChangeLevel,
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(6.dp)),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = Secondary.copy(alpha = 0.2f),
+ focusedContainerColor = Secondary.copy(alpha = 0.5f),
+ contentColor = Secondary,
+ focusedContentColor = Secondary
+ )
+ ) {
+ Text(
+ text = "Change",
+ style = MaterialTheme.typography.labelMedium,
+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
+ )
}
}
@@ -448,8 +488,23 @@ private fun ParentalControlCard(
verticalAlignment = Alignment.CenterVertically
) {
Text("Parental PIN", style = MaterialTheme.typography.bodyLarge, color = OnBackground)
- OutlinedButton(onClick = onChangePin) {
- Text("Change PIN")
+
+ // Custom Focusable Button for "Change PIN"
+ Surface(
+ onClick = onChangePin,
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(6.dp)),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = Primary.copy(alpha = 0.2f),
+ focusedContainerColor = Primary.copy(alpha = 0.5f),
+ contentColor = Primary,
+ focusedContentColor = Primary
+ )
+ ) {
+ Text(
+ text = "Change PIN",
+ style = MaterialTheme.typography.labelMedium,
+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
+ )
}
}
}
@@ -463,7 +518,9 @@ private fun ProviderSettingsCard(
onConnect: () -> Unit,
onRefresh: () -> Unit,
onDelete: () -> Unit,
- onEdit: () -> Unit) {
+ onEdit: () -> Unit,
+ onParentalControl: () -> Unit
+) {
// Use Column layout - provider info + buttons below as separate focusable items
Column(
modifier = Modifier
@@ -594,6 +651,24 @@ private fun ProviderSettingsCard(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
)
}
+
+ if (isActive) {
+ Surface(
+ onClick = onParentalControl,
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(6.dp)),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = Primary.copy(alpha = 0.15f),
+ focusedContainerColor = Primary.copy(alpha = 0.3f)
+ )
+ ) {
+ Text(
+ text = "πŸ›‘οΈ Parental Control",
+ style = MaterialTheme.typography.labelMedium,
+ color = Primary,
+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
+ )
+ }
+ }
}
}
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/parental/ParentalControlGroupScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/parental/ParentalControlGroupScreen.kt
new file mode 100644
index 00000000..91d441b2
--- /dev/null
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/parental/ParentalControlGroupScreen.kt
@@ -0,0 +1,233 @@
+package com.streamvault.app.ui.screens.settings.parental
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.*
+import androidx.compose.foundation.clickable
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.ArrowBack
+import androidx.compose.material.icons.filled.Search
+import androidx.tv.material3.*
+import androidx.compose.runtime.*
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.unit.dp
+import androidx.hilt.navigation.compose.hiltViewModel
+import com.streamvault.app.ui.components.TopNavBar
+import com.streamvault.domain.model.Category
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.FocusRequester
+
+@Composable
+fun ParentalControlGroupScreen(
+ currentRoute: String,
+ onNavigate: (String) -> Unit,
+ onBack: () -> Unit,
+ viewModel: ParentalControlGroupViewModel = hiltViewModel()
+) {
+ val uiState by viewModel.uiState.collectAsState()
+ val backButtonFocusRequester = remember { FocusRequester() }
+
+ LaunchedEffect(Unit) {
+ backButtonFocusRequester.requestFocus()
+ }
+
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .background(MaterialTheme.colorScheme.background)
+ ) {
+ TopNavBar(
+ currentRoute = currentRoute,
+ onNavigate = onNavigate
+ )
+
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 32.dp, vertical = 16.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ IconButton(
+ onClick = onBack,
+ modifier = Modifier.focusRequester(backButtonFocusRequester)
+ ) {
+ Icon(Icons.Default.ArrowBack, contentDescription = "Back")
+ }
+ Text(
+ text = "πŸ›‘οΈ Protected Groups",
+ style = MaterialTheme.typography.headlineSmall,
+ color = MaterialTheme.colorScheme.primary,
+ modifier = Modifier.padding(start = 16.dp)
+ )
+ }
+
+ // Search Bar
+ // Search Bar with Click-to-Focus (No layout jump)
+ val focusManager = androidx.compose.ui.platform.LocalFocusManager.current
+ var isSearchActive by remember { mutableStateOf(false) }
+ val searchFocusRequester = remember { FocusRequester() }
+
+ Box(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(16.dp)
+ ) {
+ androidx.compose.material3.OutlinedTextField(
+ value = uiState.searchQuery,
+ onValueChange = { viewModel.onSearchQueryChange(it) },
+ modifier = Modifier
+ .fillMaxWidth()
+ .focusRequester(searchFocusRequester)
+ .onFocusChanged {
+ if (!it.isFocused && isSearchActive) {
+ // Optional: if focus lost via other means
+ }
+ },
+ placeholder = { Text("Search categories...", color = MaterialTheme.colorScheme.onSurfaceVariant) },
+ leadingIcon = { Icon(Icons.Default.Search, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant) },
+ singleLine = true,
+ keyboardActions = androidx.compose.foundation.text.KeyboardActions(
+ onDone = {
+ focusManager.clearFocus()
+ isSearchActive = false
+ }
+ ),
+ colors = androidx.compose.material3.OutlinedTextFieldDefaults.colors(
+ focusedTextColor = MaterialTheme.colorScheme.onSurface,
+ unfocusedTextColor = MaterialTheme.colorScheme.onSurface,
+ cursorColor = MaterialTheme.colorScheme.primary,
+ focusedBorderColor = MaterialTheme.colorScheme.primary,
+ unfocusedBorderColor = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ )
+
+ // Overlay to intercept clicks when inactive
+ if (!isSearchActive) {
+ Box(
+ modifier = Modifier
+ .matchParentSize()
+ .clickable(
+ interactionSource = remember { androidx.compose.foundation.interaction.MutableInteractionSource() },
+ indication = null, // No ripple on overlay, or use ripple if desired
+ onClick = {
+ isSearchActive = true
+ searchFocusRequester.requestFocus()
+ }
+ )
+ )
+ }
+ }
+
+ if (uiState.isLoading) {
+ Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+ androidx.compose.material3.CircularProgressIndicator(color = MaterialTheme.colorScheme.primary)
+ }
+ } else {
+ LazyColumn(
+ modifier = Modifier.fillMaxSize(),
+ contentPadding = PaddingValues(16.dp),
+ verticalArrangement = Arrangement.spacedBy(8.dp)
+ ) {
+ items(uiState.categories, key = { it.id }) { category ->
+ CategoryProtectionCard(
+ category = category,
+ onToggle = { viewModel.toggleCategoryProtection(category) }
+ )
+ }
+ }
+ }
+ }
+}
+
+@Composable
+fun CategoryProtectionCard(
+ category: Category,
+ onToggle: () -> Unit
+) {
+ var isFocused by remember { mutableStateOf(false) }
+
+ // Optimistic state for smooth animation
+ // We initialize with the category state, but update immediately on user interaction
+ var isChecked by remember(category.isUserProtected, category.isAdult) {
+ mutableStateOf(category.isUserProtected || category.isAdult)
+ }
+
+ val borderColor = if (isFocused) MaterialTheme.colorScheme.primary else Color.Transparent
+ val borderWidth = if (isFocused) 2.dp else 0.dp
+ val backgroundColor = if (isFocused) MaterialTheme.colorScheme.surface else MaterialTheme.colorScheme.surfaceVariant
+
+ Surface(
+ onClick = {
+ if (!category.isAdult) {
+ isChecked = !isChecked // Optimistic update
+ onToggle()
+ }
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .onFocusChanged { isFocused = it.isFocused }
+ .border(borderWidth, borderColor, MaterialTheme.shapes.medium),
+ scale = ClickableSurfaceDefaults.scale(focusedScale = 1.02f),
+ shape = ClickableSurfaceDefaults.shape(MaterialTheme.shapes.medium),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = MaterialTheme.colorScheme.surfaceVariant,
+ focusedContainerColor = MaterialTheme.colorScheme.surface,
+ pressedContainerColor = MaterialTheme.colorScheme.surfaceVariant,
+ focusedContentColor = MaterialTheme.colorScheme.onSurface,
+ pressedContentColor = MaterialTheme.colorScheme.onSurface
+ )
+ ) {
+ Row(
+ modifier = Modifier
+ .padding(16.dp)
+ .fillMaxWidth(),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.SpaceBetween
+ ) {
+ Column(
+ modifier = Modifier
+ .weight(1f)
+ .padding(end = 16.dp)
+ ) {
+ Text(
+ text = category.name,
+ style = MaterialTheme.typography.titleMedium,
+ color = MaterialTheme.colorScheme.onSurface,
+ maxLines = 1,
+ overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis
+ )
+ if (category.isAdult) {
+ Text(
+ text = "Adult Category (Auto-Protected)",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.error,
+ maxLines = 1,
+ overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis
+ )
+ }
+ }
+
+ androidx.compose.material3.Switch(
+ checked = isChecked,
+ onCheckedChange = {
+ if (!category.isAdult) {
+ isChecked = it // Optimistic update
+ onToggle()
+ }
+ },
+ enabled = !category.isAdult,
+ colors = androidx.compose.material3.SwitchDefaults.colors(
+ checkedThumbColor = MaterialTheme.colorScheme.primary,
+ checkedTrackColor = MaterialTheme.colorScheme.primaryContainer,
+ uncheckedThumbColor = MaterialTheme.colorScheme.onSurfaceVariant,
+ uncheckedTrackColor = MaterialTheme.colorScheme.surfaceVariant
+ )
+ )
+ }
+ }
+}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/parental/ParentalControlGroupViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/parental/ParentalControlGroupViewModel.kt
new file mode 100644
index 00000000..ec67ad49
--- /dev/null
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/parental/ParentalControlGroupViewModel.kt
@@ -0,0 +1,65 @@
+package com.streamvault.app.ui.screens.settings.parental
+
+import androidx.lifecycle.SavedStateHandle
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.repository.CategoryRepository
+import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.flow.*
+import kotlinx.coroutines.launch
+import javax.inject.Inject
+
+data class ParentalControlGroupUiState(
+ val providerId: Long = -1L,
+ val categories: List<Category> = emptyList(),
+ val searchQuery: String = "",
+ val isLoading: Boolean = false
+)
+
+@HiltViewModel
+class ParentalControlGroupViewModel @Inject constructor(
+ private val categoryRepository: CategoryRepository,
+ savedStateHandle: SavedStateHandle
+) : ViewModel() {
+
+ private val providerId: Long = checkNotNull(savedStateHandle["providerId"])
+
+ private val _searchQuery = MutableStateFlow("")
+ val searchQuery = _searchQuery.asStateFlow()
+
+ private val _isLoading = MutableStateFlow(true)
+ val isLoading = _isLoading.asStateFlow()
+
+ val uiState: StateFlow<ParentalControlGroupUiState> = combine(
+ categoryRepository.getCategories(providerId),
+ _searchQuery,
+ _isLoading
+ ) { categories, query, loading ->
+ val filtered = if (query.isBlank()) {
+ categories
+ } else {
+ categories.filter { it.name.contains(query, ignoreCase = true) }
+ }
+ ParentalControlGroupUiState(
+ providerId = providerId,
+ categories = filtered,
+ searchQuery = query,
+ isLoading = false // After first load, categories flow will emit
+ )
+ }.stateIn(
+ scope = viewModelScope,
+ started = SharingStarted.WhileSubscribed(5000),
+ initialValue = ParentalControlGroupUiState(providerId = providerId, isLoading = true)
+ )
+
+ fun onSearchQueryChange(query: String) {
+ _searchQuery.value = query
+ }
+
+ fun toggleCategoryProtection(category: Category) {
+ viewModelScope.launch {
+ categoryRepository.setCategoryProtection(category.id, !category.isUserProtected)
+ }
+ }
+}
diff --git a/build_log.txt b/build_log.txt
index d14790b3..c5c75b5f 100644
Binary files a/build_log.txt and b/build_log.txt differ
diff --git a/build_log_assemble.txt b/build_log_assemble.txt
new file mode 100644
index 00000000..1b774da0
Binary files /dev/null and b/build_log_assemble.txt differ
diff --git a/build_log_debug_url.txt b/build_log_debug_url.txt
new file mode 100644
index 00000000..9b03de72
Binary files /dev/null and b/build_log_debug_url.txt differ
diff --git a/build_log_debug_url_v2.txt b/build_log_debug_url_v2.txt
new file mode 100644
index 00000000..f87e14ac
Binary files /dev/null and b/build_log_debug_url_v2.txt differ
diff --git a/build_log_errors.txt b/build_log_errors.txt
new file mode 100644
index 00000000..c0cb2572
Binary files /dev/null and b/build_log_errors.txt differ
diff --git a/build_log_errors_2.txt b/build_log_errors_2.txt
new file mode 100644
index 00000000..1cf5b1cc
Binary files /dev/null and b/build_log_errors_2.txt differ
diff --git a/build_log_kt.txt b/build_log_kt.txt
new file mode 100644
index 00000000..4c2121c1
Binary files /dev/null and b/build_log_kt.txt differ
diff --git a/build_log_master.txt b/build_log_master.txt
new file mode 100644
index 00000000..489be26c
Binary files /dev/null and b/build_log_master.txt differ
diff --git a/build_log_master_final.txt b/build_log_master_final.txt
new file mode 100644
index 00000000..1b774da0
Binary files /dev/null and b/build_log_master_final.txt differ
diff --git a/build_output.txt b/build_output.txt
index df21c7a8..863afd05 100644
Binary files a/build_output.txt and b/build_output.txt differ
diff --git a/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt b/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt
index b3736b94..24a8617a 100644
--- a/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt
+++ b/data/src/main/java/com/streamvault/data/local/StreamVaultDatabase.kt
@@ -17,7 +17,7 @@ import com.streamvault.data.local.entity.*
FavoriteEntity::class,
VirtualGroupEntity::class
],
- version = 2,
+ version = 3,
exportSchema = false
)
abstract class StreamVaultDatabase : RoomDatabase() {
@@ -30,4 +30,19 @@ abstract class StreamVaultDatabase : RoomDatabase() {
abstract fun programDao(): ProgramDao
abstract fun favoriteDao(): FavoriteDao
abstract fun virtualGroupDao(): VirtualGroupDao
+
+ companion object {
+ val MIGRATION_2_3 = object : androidx.room.migration.Migration(2, 3) {
+ override fun migrate(database: androidx.sqlite.db.SupportSQLiteDatabase) {
+ database.execSQL("ALTER TABLE categories ADD COLUMN is_user_protected INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE channels ADD COLUMN is_user_protected INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE movies ADD COLUMN is_adult INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE movies ADD COLUMN is_user_protected INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE series ADD COLUMN is_adult INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE series ADD COLUMN is_user_protected INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE episodes ADD COLUMN is_adult INTEGER NOT NULL DEFAULT 0")
+ database.execSQL("ALTER TABLE episodes ADD COLUMN is_user_protected INTEGER NOT NULL DEFAULT 0")
+ }
+ }
+ }
}
diff --git a/data/src/main/java/com/streamvault/data/local/dao/Daos.kt b/data/src/main/java/com/streamvault/data/local/dao/Daos.kt
index 566541b8..ba3cb904 100644
--- a/data/src/main/java/com/streamvault/data/local/dao/Daos.kt
+++ b/data/src/main/java/com/streamvault/data/local/dao/Daos.kt
@@ -71,6 +71,9 @@ interface ChannelDao {
@Query("SELECT COUNT(*) FROM channels WHERE provider_id = :providerId")
fun getCount(providerId: Long): Flow<Int>
+
+ @Query("UPDATE channels SET is_user_protected = :isProtected WHERE category_id = :categoryId")
+ suspend fun updateProtectionStatus(categoryId: Long, isProtected: Boolean)
}
@Dao
@@ -113,6 +116,9 @@ interface MovieDao {
@Query("SELECT COUNT(*) FROM movies WHERE provider_id = :providerId")
fun getCount(providerId: Long): Flow<Int>
+
+ @Query("UPDATE movies SET is_user_protected = :isProtected WHERE category_id = :categoryId")
+ suspend fun updateProtectionStatus(categoryId: Long, isProtected: Boolean)
}
@Dao
@@ -146,6 +152,9 @@ interface SeriesDao {
@Query("SELECT COUNT(*) FROM series WHERE provider_id = :providerId")
fun getCount(providerId: Long): Flow<Int>
+
+ @Query("UPDATE series SET is_user_protected = :isProtected WHERE category_id = :categoryId")
+ suspend fun updateProtectionStatus(categoryId: Long, isProtected: Boolean)
}
@@ -183,6 +192,9 @@ interface CategoryDao {
deleteByProviderAndType(providerId, type)
insertAll(categories)
}
+
+ @Query("UPDATE categories SET is_user_protected = :isProtected WHERE category_id = :categoryId")
+ suspend fun updateProtectionStatus(categoryId: Long, isProtected: Boolean)
}
@Dao
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.kt
index 8f1f4289..b908009c 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
@@ -50,7 +50,8 @@ data class ChannelEntity(
@ColumnInfo(name = "catch_up_supported") val catchUpSupported: Boolean = false,
@ColumnInfo(name = "catch_up_days") val catchUpDays: Int = 0,
@ColumnInfo(name = "provider_id") val providerId: Long = 0,
- @ColumnInfo(name = "is_adult") val isAdult: Boolean = false
+ @ColumnInfo(name = "is_adult") val isAdult: Boolean = false,
+ @ColumnInfo(name = "is_user_protected") val isUserProtected: Boolean = false
)
@Entity(
@@ -85,7 +86,9 @@ data class MovieEntity(
@ColumnInfo(name = "youtube_trailer") val youtubeTrailer: String? = null,
@ColumnInfo(name = "provider_id") val providerId: Long = 0,
@ColumnInfo(name = "watch_progress") val watchProgress: Long = 0L,
- @ColumnInfo(name = "last_watched_at") val lastWatchedAt: Long = 0L
+ @ColumnInfo(name = "last_watched_at") val lastWatchedAt: Long = 0L,
+ @ColumnInfo(name = "is_adult") val isAdult: Boolean = false,
+ @ColumnInfo(name = "is_user_protected") val isUserProtected: Boolean = false
)
@Entity(
@@ -115,7 +118,9 @@ data class SeriesEntity(
@ColumnInfo(name = "youtube_trailer") val youtubeTrailer: String? = null,
@ColumnInfo(name = "episode_run_time") val episodeRunTime: String? = null,
@ColumnInfo(name = "last_modified") val lastModified: Long = 0L,
- @ColumnInfo(name = "provider_id") val providerId: Long = 0
+ @ColumnInfo(name = "provider_id") val providerId: Long = 0,
+ @ColumnInfo(name = "is_adult") val isAdult: Boolean = false,
+ @ColumnInfo(name = "is_user_protected") val isUserProtected: Boolean = false
)
@Entity(
@@ -144,7 +149,9 @@ data class EpisodeEntity(
@ColumnInfo(name = "series_id") val seriesId: Long = 0,
@ColumnInfo(name = "provider_id") val providerId: Long = 0,
@ColumnInfo(name = "watch_progress") val watchProgress: Long = 0L,
- @ColumnInfo(name = "last_watched_at") val lastWatchedAt: Long = 0L
+ @ColumnInfo(name = "last_watched_at") val lastWatchedAt: Long = 0L,
+ @ColumnInfo(name = "is_adult") val isAdult: Boolean = false,
+ @ColumnInfo(name = "is_user_protected") val isUserProtected: Boolean = false
)
@Entity(
@@ -162,7 +169,8 @@ data class CategoryEntity(
@ColumnInfo(name = "parent_id") val parentId: Long? = null,
val type: String = "LIVE", // LIVE, MOVIE, SERIES
@ColumnInfo(name = "provider_id") val providerId: Long = 0,
- @ColumnInfo(name = "is_adult") val isAdult: Boolean = false
+ @ColumnInfo(name = "is_adult") val isAdult: Boolean = false,
+ @ColumnInfo(name = "is_user_protected") val isUserProtected: Boolean = false
)
@Entity(
diff --git a/data/src/main/java/com/streamvault/data/mapper/EntityMappers.kt b/data/src/main/java/com/streamvault/data/mapper/EntityMappers.kt
index a5c4f053..42242bee 100644
--- a/data/src/main/java/com/streamvault/data/mapper/EntityMappers.kt
+++ b/data/src/main/java/com/streamvault/data/mapper/EntityMappers.kt
@@ -53,7 +53,9 @@ fun ChannelEntity.toDomain() = Channel(
number = number,
catchUpSupported = catchUpSupported,
catchUpDays = catchUpDays,
- providerId = providerId
+ providerId = providerId,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
fun Channel.toEntity() = ChannelEntity(
@@ -69,7 +71,9 @@ fun Channel.toEntity() = ChannelEntity(
number = number,
catchUpSupported = catchUpSupported,
catchUpDays = catchUpDays,
- providerId = providerId
+ providerId = providerId,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
// ── Movie ──────────────────────────────────────────────────────────
@@ -96,7 +100,9 @@ fun MovieEntity.toDomain() = Movie(
youtubeTrailer = youtubeTrailer,
providerId = providerId,
watchProgress = watchProgress,
- lastWatchedAt = lastWatchedAt
+ lastWatchedAt = lastWatchedAt,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
fun Movie.toEntity() = MovieEntity(
@@ -122,7 +128,9 @@ fun Movie.toEntity() = MovieEntity(
youtubeTrailer = youtubeTrailer,
providerId = providerId,
watchProgress = watchProgress,
- lastWatchedAt = lastWatchedAt
+ lastWatchedAt = lastWatchedAt,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
// ── Series ─────────────────────────────────────────────────────────
@@ -144,7 +152,9 @@ fun SeriesEntity.toDomain() = Series(
youtubeTrailer = youtubeTrailer,
episodeRunTime = episodeRunTime,
lastModified = lastModified,
- providerId = providerId
+ providerId = providerId,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
fun Series.toEntity() = SeriesEntity(
@@ -165,7 +175,9 @@ fun Series.toEntity() = SeriesEntity(
youtubeTrailer = youtubeTrailer,
episodeRunTime = episodeRunTime,
lastModified = lastModified,
- providerId = providerId
+ providerId = providerId,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
// ── Episode ────────────────────────────────────────────────────────
@@ -186,7 +198,9 @@ fun EpisodeEntity.toDomain() = Episode(
seriesId = seriesId,
providerId = providerId,
watchProgress = watchProgress,
- lastWatchedAt = lastWatchedAt
+ lastWatchedAt = lastWatchedAt,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
fun Episode.toEntity() = EpisodeEntity(
@@ -206,7 +220,9 @@ fun Episode.toEntity() = EpisodeEntity(
seriesId = seriesId,
providerId = providerId,
watchProgress = watchProgress,
- lastWatchedAt = lastWatchedAt
+ lastWatchedAt = lastWatchedAt,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
// ── Category ───────────────────────────────────────────────────────
@@ -215,7 +231,9 @@ fun CategoryEntity.toDomain() = com.streamvault.domain.model.Category(
id = categoryId,
name = name,
parentId = parentId,
- type = try { ContentType.valueOf(type) } catch (_: Exception) { ContentType.LIVE }
+ type = try { ContentType.valueOf(type) } catch (_: Exception) { ContentType.LIVE },
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
fun com.streamvault.domain.model.Category.toEntity(providerId: Long) = CategoryEntity(
@@ -223,7 +241,9 @@ fun com.streamvault.domain.model.Category.toEntity(providerId: Long) = CategoryE
name = name,
parentId = parentId,
type = type.name,
- providerId = providerId
+ providerId = providerId,
+ isAdult = isAdult,
+ isUserProtected = isUserProtected
)
// ── Program ────────────────────────────────────────────────────────
diff --git a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
index 63a20be1..079e9f80 100644
--- a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
+++ b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
@@ -26,6 +26,7 @@ class PreferencesRepository @Inject constructor(
val DEFAULT_VIEW_MODE = stringPreferencesKey("default_view_mode")
val PARENTAL_CONTROL_LEVEL = intPreferencesKey("parental_control_level")
val PARENTAL_PIN = stringPreferencesKey("parental_pin")
+ val DEFAULT_CATEGORY_ID = longPreferencesKey("default_category_id")
}
val lastActiveProviderId: Flow<Long?> = context.dataStore.data.map { preferences ->
@@ -38,7 +39,7 @@ class PreferencesRepository @Inject constructor(
val parentalControlLevel: Flow<Int> = context.dataStore.data
.map { preferences ->
- preferences[PreferencesKeys.PARENTAL_CONTROL_LEVEL] ?: 0 // 0 = OFF, 1 = LOCKED, 2 = HIDDEN
+ preferences[PreferencesKeys.PARENTAL_CONTROL_LEVEL] ?: 1 // Default to 1 = LOCKED
}
val parentalPin: Flow<String> = context.dataStore.data
@@ -74,4 +75,14 @@ class PreferencesRepository @Inject constructor(
context.dataStore.edit { preferences ->
}
}
+
+ val defaultCategoryId: Flow<Long?> = context.dataStore.data.map { preferences ->
+ preferences[PreferencesKeys.DEFAULT_CATEGORY_ID]
+ }
+
+ suspend fun setDefaultCategory(categoryId: Long) {
+ context.dataStore.edit { preferences ->
+ preferences[PreferencesKeys.DEFAULT_CATEGORY_ID] = categoryId
+ }
+ }
}
diff --git a/data/src/main/java/com/streamvault/data/remote/xtream/XtreamProvider.kt b/data/src/main/java/com/streamvault/data/remote/xtream/XtreamProvider.kt
index 549497a4..78c102c5 100644
--- a/data/src/main/java/com/streamvault/data/remote/xtream/XtreamProvider.kt
+++ b/data/src/main/java/com/streamvault/data/remote/xtream/XtreamProvider.kt
@@ -205,7 +205,9 @@ class XtreamProvider(
streamUrl = buildSeriesStreamUrl(
ep.id.toLongOrNull() ?: 0,
ep.containerExtension
- )
+ ),
+ isAdult = false,
+ isUserProtected = false
)
},
episodeCount = episodes.size
@@ -298,7 +300,8 @@ class XtreamProvider(
catchUpDays = tvArchiveDuration ?: 0,
providerId = providerId,
streamUrl = "$serverUrl/live/$username/$password/$streamId.ts",
- isAdult = isCatAdult
+ isAdult = isCatAdult,
+ isUserProtected = false
)
}
@@ -311,7 +314,9 @@ class XtreamProvider(
containerExtension = containerExtension,
rating = rating5based?.toFloatOrNull() ?: 0f,
providerId = providerId,
- streamUrl = buildMovieStreamUrl(streamId, containerExtension)
+ streamUrl = buildMovieStreamUrl(streamId, containerExtension),
+ isAdult = isAdultContent(categoryName),
+ isUserProtected = false
)
private fun XtreamSeriesItem.toDomain() = Series(
@@ -329,7 +334,9 @@ class XtreamProvider(
youtubeTrailer = youtubeTrailer,
episodeRunTime = episodeRunTime,
lastModified = lastModified?.toLongOrNull() ?: 0L,
- providerId = providerId
+ providerId = providerId,
+ isAdult = false, // Category name not on series item in Xtream
+ isUserProtected = false
)
private fun XtreamEpgListing.toDomain(): Program {
diff --git a/data/src/main/java/com/streamvault/data/repository/CategoryRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/CategoryRepositoryImpl.kt
new file mode 100644
index 00000000..0721bd09
--- /dev/null
+++ b/data/src/main/java/com/streamvault/data/repository/CategoryRepositoryImpl.kt
@@ -0,0 +1,35 @@
+package com.streamvault.data.repository
+
+import com.streamvault.data.local.dao.*
+import com.streamvault.data.local.entity.CategoryEntity
+import com.streamvault.data.mapper.toDomain
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.model.ContentType
+import com.streamvault.domain.repository.CategoryRepository
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.map
+import javax.inject.Inject
+import javax.inject.Singleton
+
+@Singleton
+class CategoryRepositoryImpl @Inject constructor(
+ private val categoryDao: CategoryDao,
+ private val channelDao: ChannelDao,
+ private val movieDao: MovieDao,
+ private val seriesDao: SeriesDao
+) : CategoryRepository {
+
+ override fun getCategories(providerId: Long): Flow<List<Category>> =
+ categoryDao.getByProviderAndType(providerId, ContentType.LIVE.name)
+ .map { entities -> entities.map { it.toDomain() } }
+
+ override suspend fun setCategoryProtection(categoryId: Long, isProtected: Boolean) {
+ // Update category table
+ categoryDao.updateProtectionStatus(categoryId, isProtected)
+
+ // Update items tables
+ channelDao.updateProtectionStatus(categoryId, isProtected)
+ movieDao.updateProtectionStatus(categoryId, isProtected)
+ seriesDao.updateProtectionStatus(categoryId, isProtected)
+ }
+}
diff --git a/data/src/main/java/com/streamvault/data/repository/ChannelRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/ChannelRepositoryImpl.kt
index 47b523d9..eb7dd0e1 100644
--- a/data/src/main/java/com/streamvault/data/repository/ChannelRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/ChannelRepositoryImpl.kt
@@ -3,6 +3,8 @@ package com.streamvault.data.repository
import com.streamvault.data.local.dao.CategoryDao
import com.streamvault.data.local.dao.ChannelDao
import com.streamvault.data.local.entity.CategoryCount
+import com.streamvault.data.local.entity.CategoryEntity
+import com.streamvault.data.local.entity.ChannelEntity
import com.streamvault.data.mapper.toDomain
import com.streamvault.domain.model.Category
import com.streamvault.domain.model.Channel
@@ -20,22 +22,36 @@ import javax.inject.Singleton
class ChannelRepositoryImpl @Inject constructor(
private val channelDao: ChannelDao,
private val categoryDao: CategoryDao,
- private val preferencesRepository: PreferencesRepository
+ private val preferencesRepository: PreferencesRepository,
+ private val parentalControlManager: com.streamvault.domain.manager.ParentalControlManager
) : ChannelRepository {
override fun getChannels(providerId: Long): Flow<List<Channel>> =
combine(
channelDao.getByProvider(providerId),
- preferencesRepository.parentalControlLevel
- ) { entities, level ->
- // Level 2 = HIDDEN. If hidden, filter out adult channels.
- if (level == 2) {
- entities.filter { !it.isAdult }
+ preferencesRepository.parentalControlLevel,
+ parentalControlManager.unlockedCategories
+ ) { entities, level, unlockedCats ->
+ // Level 2 = HIDDEN.
+ // If hidden, filter out adult/protected UNLESS they are in unlockedCats.
+ val filtered = if (level == 2) {
+ entities.filter { entity ->
+ val isUnlocked = entity.categoryId != null && unlockedCats.contains(entity.categoryId)
+ (!entity.isAdult && !entity.isUserProtected) || isUnlocked
+ }
} else {
entities
}
- }.map { entities ->
- entities.map { it.toDomain() }
+
+ filtered.map { entity ->
+ val domain = entity.toDomain()
+ // If category is unlocked, mark channel as NOT protected/ADULT for this session
+ if (entity.categoryId != null && unlockedCats.contains(entity.categoryId)) {
+ domain.copy(isUserProtected = false, isAdult = false)
+ } else {
+ domain
+ }
+ }
}
override fun getChannelsByCategory(providerId: Long, categoryId: Long): Flow<List<Channel>> =
@@ -45,24 +61,39 @@ class ChannelRepositoryImpl @Inject constructor(
} else {
channelDao.getByCategory(providerId, categoryId)
},
- preferencesRepository.parentalControlLevel
- ) { entities, level ->
- // Level 2 = HIDDEN. If hidden, filter out adult channels.
- if (level == 2) {
- entities.filter { !it.isAdult }
+ preferencesRepository.parentalControlLevel,
+ parentalControlManager.unlockedCategories
+ ) { entities, level, unlockedCats ->
+ // Level 2 = HIDDEN.
+ // If hidden, filter out adult/protected UNLESS they are in unlockedCats.
+ val filtered = if (level == 2) {
+ entities.filter { entity ->
+ val isUnlocked = entity.categoryId != null && unlockedCats.contains(entity.categoryId)
+ (!entity.isAdult && !entity.isUserProtected) || isUnlocked
+ }
} else {
entities
}
- }.map { entities ->
- entities.map { it.toDomain() }
+
+ filtered.map { entity ->
+ val domain = entity.toDomain()
+ // If category is unlocked, mark channel as NOT protected/ADULT for this session
+ if (entity.categoryId != null && unlockedCats.contains(entity.categoryId)) {
+ domain.copy(isUserProtected = false, isAdult = false)
+ } else {
+ domain
+ }
+ }
}
override fun getCategories(providerId: Long): Flow<List<Category>> =
combine(
categoryDao.getByProviderAndType(providerId, ContentType.LIVE.name),
channelDao.getCategoryCounts(providerId),
- channelDao.getCount(providerId)
- ) { categories, counts, totalCount ->
+ channelDao.getCount(providerId),
+ preferencesRepository.parentalControlLevel,
+ parentalControlManager.unlockedCategories
+ ) { categories: List<CategoryEntity>, counts: List<CategoryCount>, totalCount: Int, level: Int, unlockedCats: Set<Long> ->
android.util.Log.d("ChannelRepo", "getCategories: ${categories.size} cats, ${counts.size} counts, total: $totalCount")
val countMap = counts.associate { it.categoryId to it.item_count }
@@ -74,14 +105,52 @@ class ChannelRepositoryImpl @Inject constructor(
)
val mappedCategories = categories.map { entity ->
- entity.toDomain().copy(count = countMap[entity.categoryId] ?: 0)
+ val domain = entity.toDomain().copy(count = countMap[entity.categoryId] ?: 0)
+ // If unlocked, update domain model (though Category model doesn't strictly need it if we trust the check elsewhere,
+ // but nice for UI to show 'unlocked' icon if we had one. For now just passing through).
+ if (unlockedCats.contains(entity.categoryId)) {
+ domain.copy(isUserProtected = false)
+ } else {
+ domain
+ }
+ }
+
+ // Filter categories if level is HIDDEN
+ val filteredCategories = if (level == 2) {
+ mappedCategories.filter { category ->
+ (!category.isAdult && !category.isUserProtected) || unlockedCats.contains(category.id)
+ }
+ } else {
+ mappedCategories
}
- listOf(allChannelsCategory) + mappedCategories
+ listOf(allChannelsCategory) + filteredCategories
}
override fun searchChannels(providerId: Long, query: String): Flow<List<Channel>> =
- channelDao.search(providerId, query).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ channelDao.search(providerId, query),
+ preferencesRepository.parentalControlLevel,
+ parentalControlManager.unlockedCategories
+ ) { entities, level, unlockedCats ->
+ val filtered = if (level == 2) {
+ entities.filter { entity ->
+ val isUnlocked = entity.categoryId != null && unlockedCats.contains(entity.categoryId)
+ (!entity.isAdult && !entity.isUserProtected) || isUnlocked
+ }
+ } else {
+ entities
+ }
+
+ filtered.map { entity ->
+ val domain = entity.toDomain()
+ if (entity.categoryId != null && unlockedCats.contains(entity.categoryId)) {
+ domain.copy(isUserProtected = false, isAdult = false)
+ } else {
+ domain
+ }
+ }
+ }
override suspend fun getChannel(channelId: Long): Channel? =
channelDao.getById(channelId)?.toDomain()
diff --git a/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt
index 5508ef9e..1c567df5 100644
--- a/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt
@@ -2,6 +2,8 @@ package com.streamvault.data.repository
import com.streamvault.data.local.dao.CategoryDao
import com.streamvault.data.local.dao.MovieDao
+import com.streamvault.data.local.entity.MovieEntity
+import com.streamvault.data.local.entity.CategoryEntity
import com.streamvault.data.mapper.toDomain
import com.streamvault.domain.model.Category
import com.streamvault.domain.model.ContentType
@@ -9,28 +11,67 @@ import com.streamvault.domain.model.Movie
import com.streamvault.domain.model.Result
import com.streamvault.domain.repository.MovieRepository
import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import javax.inject.Inject
+import com.streamvault.data.preferences.PreferencesRepository
import javax.inject.Singleton
@Singleton
class MovieRepositoryImpl @Inject constructor(
private val movieDao: MovieDao,
- private val categoryDao: CategoryDao
+ private val categoryDao: CategoryDao,
+ private val preferencesRepository: PreferencesRepository
) : MovieRepository {
override fun getMovies(providerId: Long): Flow<List<Movie>> =
- movieDao.getByProvider(providerId).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ movieDao.getByProvider(providerId),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<MovieEntity>, level: Int ->
+ if (level == 2) {
+ entities.filter { !it.isUserProtected }
+ } else {
+ entities
+ }
+ }.map { list -> list.map { it.toDomain() } }
override fun getMoviesByCategory(providerId: Long, categoryId: Long): Flow<List<Movie>> =
- movieDao.getByCategory(providerId, categoryId).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ movieDao.getByCategory(providerId, categoryId),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<MovieEntity>, level: Int ->
+ if (level == 2) {
+ entities.filter { !it.isUserProtected }
+ } else {
+ entities
+ }
+ }.map { list -> list.map { it.toDomain() } }
override fun getCategories(providerId: Long): Flow<List<Category>> =
- categoryDao.getByProviderAndType(providerId, ContentType.MOVIE.name)
- .map { entities -> entities.map { it.toDomain() } }
+ combine(
+ categoryDao.getByProviderAndType(providerId, ContentType.MOVIE.name),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<CategoryEntity>, level: Int ->
+ val mapped = entities.map { it.toDomain() }
+ if (level == 2) {
+ mapped.filter { !it.isAdult && !it.isUserProtected }
+ } else {
+ mapped
+ }
+ }
override fun searchMovies(providerId: Long, query: String): Flow<List<Movie>> =
- movieDao.search(providerId, query).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ movieDao.search(providerId, query),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<MovieEntity>, level: Int ->
+ if (level == 2) {
+ entities.filter { !it.isUserProtected }
+ } else {
+ entities
+ }
+ }.map { list -> list.map { it.toDomain() } }
override suspend fun getMovie(movieId: Long): Movie? =
movieDao.getById(movieId)?.toDomain()
diff --git a/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt
index d725f531..ca7b0622 100644
--- a/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt
@@ -82,23 +82,30 @@ class ProviderRepositoryImpl @Inject constructor(
username: String,
password: String,
name: String,
- onProgress: ((String) -> Unit)?
+ onProgress: ((String) -> Unit)?,
+ id: Long?
): Result<Provider> {
onProgress?.invoke("Authenticating...")
val provider = createXtreamProvider(0, serverUrl, username, password)
return when (val authResult = provider.authenticate()) {
is Result.Success -> {
- // Check if provider already exists
- val existingProvider = providerDao.getByUrlAndUser(serverUrl, username)
+ // Check if provider already exists by ID first, then by URL/User
+ val existingProvider = if (id != null) {
+ providerDao.getById(id)
+ } else {
+ providerDao.getByUrlAndUser(serverUrl, username)
+ }
val providerData = if (existingProvider != null) {
onProgress?.invoke("Updating existing provider...")
// Update existing provider details
val updated = existingProvider.copy(
name = name.ifBlank { existingProvider.name },
+ serverUrl = serverUrl,
+ username = username,
password = password, // Update password if changed
isActive = true,
- lastSyncedAt = 0 // Reset sync time to force update? Or keep?
+ lastSyncedAt = 0 // Reset sync time to force update
)
providerDao.update(updated)
updated.toDomain()
@@ -139,19 +146,26 @@ class ProviderRepositoryImpl @Inject constructor(
}
}
- override suspend fun validateM3u(url: String, name: String, onProgress: ((String) -> Unit)?): Result<Provider> = try {
+ override suspend fun validateM3u(url: String, name: String, onProgress: ((String) -> Unit)?, id: Long?): Result<Provider> = try {
onProgress?.invoke("Validating playlist URL...")
val providerName = name.ifBlank {
url.substringAfterLast("/").substringBefore("?").ifBlank { "M3U Playlist" }
}
- // Check for existing
- val existingProvider = providerDao.getByUrlAndUser(url, "")
+ // Check for existing by ID first, then by URL
+ val existingProvider = if (id != null) {
+ providerDao.getById(id)
+ } else {
+ providerDao.getByUrlAndUser(url, "")
+ }
val providerData = if (existingProvider != null) {
val updated = existingProvider.copy(
name = if (name.isNotBlank()) name else existingProvider.name,
- isActive = true
+ serverUrl = url,
+ m3uUrl = url,
+ isActive = true,
+ lastSyncedAt = 0 // Reset sync time
)
providerDao.update(updated)
updated.toDomain()
diff --git a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
index ad00727d..a5ab3209 100644
--- a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
@@ -1,33 +1,73 @@
package com.streamvault.data.repository
import com.streamvault.data.local.dao.*
+import com.streamvault.data.local.entity.*
import com.streamvault.data.mapper.*
import com.streamvault.domain.model.*
import com.streamvault.domain.repository.SeriesRepository
import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import javax.inject.Inject
+import com.streamvault.data.preferences.PreferencesRepository
import javax.inject.Singleton
@Singleton
class SeriesRepositoryImpl @Inject constructor(
private val seriesDao: SeriesDao,
private val episodeDao: EpisodeDao,
- private val categoryDao: CategoryDao
+ private val categoryDao: CategoryDao,
+ private val preferencesRepository: PreferencesRepository
) : SeriesRepository {
override fun getSeries(providerId: Long): Flow<List<Series>> =
- seriesDao.getByProvider(providerId).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ seriesDao.getByProvider(providerId),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<SeriesEntity>, level: Int ->
+ if (level == 2) {
+ entities.filter { !it.isUserProtected }
+ } else {
+ entities
+ }
+ }.map { list: List<SeriesEntity> -> list.map { it.toDomain() } }
override fun getSeriesByCategory(providerId: Long, categoryId: Long): Flow<List<Series>> =
- seriesDao.getByCategory(providerId, categoryId).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ seriesDao.getByCategory(providerId, categoryId),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<SeriesEntity>, level: Int ->
+ if (level == 2) {
+ entities.filter { !it.isUserProtected }
+ } else {
+ entities
+ }
+ }.map { list: List<SeriesEntity> -> list.map { it.toDomain() } }
override fun getCategories(providerId: Long): Flow<List<Category>> =
- categoryDao.getByProviderAndType(providerId, ContentType.SERIES.name)
- .map { entities -> entities.map { it.toDomain() } }
+ combine(
+ categoryDao.getByProviderAndType(providerId, ContentType.SERIES.name),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<CategoryEntity>, level: Int ->
+ val mapped = entities.map { it.toDomain() }
+ if (level == 2) {
+ mapped.filter { !it.isAdult && !it.isUserProtected }
+ } else {
+ mapped
+ }
+ }
override fun searchSeries(providerId: Long, query: String): Flow<List<Series>> =
- seriesDao.search(providerId, query).map { entities -> entities.map { it.toDomain() } }
+ combine(
+ seriesDao.search(providerId, query),
+ preferencesRepository.parentalControlLevel
+ ) { entities: List<SeriesEntity>, level: Int ->
+ if (level == 2) {
+ entities.filter { !it.isUserProtected }
+ } else {
+ entities
+ }
+ }.map { list: List<SeriesEntity> -> list.map { it.toDomain() } }
override suspend fun getSeriesById(seriesId: Long): Series? =
seriesDao.getById(seriesId)?.toDomain()
diff --git a/domain/bin/main/com/streamvault/domain/manager/ParentalControlManager.kt b/domain/bin/main/com/streamvault/domain/manager/ParentalControlManager.kt
new file mode 100644
index 00000000..2f82762d
--- /dev/null
+++ b/domain/bin/main/com/streamvault/domain/manager/ParentalControlManager.kt
@@ -0,0 +1,27 @@
+package com.streamvault.domain.manager
+
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import javax.inject.Inject
+import javax.inject.Singleton
+
+@Singleton
+class ParentalControlManager @Inject constructor() {
+ private val _unlockedCategories = MutableStateFlow<Set<Long>>(emptySet())
+ val unlockedCategories: StateFlow<Set<Long>> = _unlockedCategories.asStateFlow()
+
+ fun unlockCategory(categoryId: Long) {
+ val current = _unlockedCategories.value.toMutableSet()
+ current.add(categoryId)
+ _unlockedCategories.value = current
+ }
+
+ fun isCategoryUnlocked(categoryId: Long): Boolean {
+ return _unlockedCategories.value.contains(categoryId)
+ }
+
+ fun clearUnlockedCategories() {
+ _unlockedCategories.value = emptySet()
+ }
+}
diff --git a/domain/bin/main/com/streamvault/domain/model/Category.kt b/domain/bin/main/com/streamvault/domain/model/Category.kt
index 16f7ecf0..a26bfd47 100644
--- a/domain/bin/main/com/streamvault/domain/model/Category.kt
+++ b/domain/bin/main/com/streamvault/domain/model/Category.kt
@@ -7,5 +7,6 @@ data class Category(
val type: ContentType = ContentType.LIVE,
val isVirtual: Boolean = false,
val count: Int = 0,
- val isAdult: Boolean = false
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/bin/main/com/streamvault/domain/model/Channel.kt b/domain/bin/main/com/streamvault/domain/model/Channel.kt
index 8d7f0130..02e859f8 100644
--- a/domain/bin/main/com/streamvault/domain/model/Channel.kt
+++ b/domain/bin/main/com/streamvault/domain/model/Channel.kt
@@ -16,5 +16,6 @@ data class Channel(
val providerId: Long = 0,
val currentProgram: Program? = null,
val nextProgram: Program? = null,
- val isAdult: Boolean = false
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/bin/main/com/streamvault/domain/model/Movie.kt b/domain/bin/main/com/streamvault/domain/model/Movie.kt
index ae073408..365804fe 100644
--- a/domain/bin/main/com/streamvault/domain/model/Movie.kt
+++ b/domain/bin/main/com/streamvault/domain/model/Movie.kt
@@ -23,5 +23,7 @@ data class Movie(
val isFavorite: Boolean = false,
val providerId: Long = 0,
val watchProgress: Long = 0L,
- val lastWatchedAt: Long = 0L
+ val lastWatchedAt: Long = 0L,
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/bin/main/com/streamvault/domain/model/Series.kt b/domain/bin/main/com/streamvault/domain/model/Series.kt
index e46daa09..61c5efd6 100644
--- a/domain/bin/main/com/streamvault/domain/model/Series.kt
+++ b/domain/bin/main/com/streamvault/domain/model/Series.kt
@@ -19,7 +19,9 @@ data class Series(
val providerId: Long = 0,
val seasons: List<Season> = emptyList(),
val episodeRunTime: String? = null,
- val lastModified: Long = 0L
+ val lastModified: Long = 0L,
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
data class Season(
@@ -47,5 +49,7 @@ data class Episode(
val seriesId: Long = 0,
val providerId: Long = 0,
val watchProgress: Long = 0L,
- val lastWatchedAt: Long = 0L
+ val lastWatchedAt: Long = 0L,
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/bin/main/com/streamvault/domain/repository/CategoryRepository.kt b/domain/bin/main/com/streamvault/domain/repository/CategoryRepository.kt
new file mode 100644
index 00000000..a5fb174b
--- /dev/null
+++ b/domain/bin/main/com/streamvault/domain/repository/CategoryRepository.kt
@@ -0,0 +1,9 @@
+package com.streamvault.domain.repository
+
+import com.streamvault.domain.model.Category
+import kotlinx.coroutines.flow.Flow
+
+interface CategoryRepository {
+ fun getCategories(providerId: Long): Flow<List<Category>>
+ suspend fun setCategoryProtection(categoryId: Long, isProtected: Boolean)
+}
diff --git a/domain/bin/main/com/streamvault/domain/repository/ProviderRepository.kt b/domain/bin/main/com/streamvault/domain/repository/ProviderRepository.kt
index 9e2628ec..54a2b3ce 100644
--- a/domain/bin/main/com/streamvault/domain/repository/ProviderRepository.kt
+++ b/domain/bin/main/com/streamvault/domain/repository/ProviderRepository.kt
@@ -12,7 +12,7 @@ interface ProviderRepository {
suspend fun updateProvider(provider: Provider): Result<Unit>
suspend fun deleteProvider(id: Long): Result<Unit>
suspend fun setActiveProvider(id: Long): Result<Unit>
- suspend fun loginXtream(serverUrl: String, username: String, password: String, name: String, onProgress: ((String) -> Unit)? = null): Result<Provider>
- suspend fun validateM3u(url: String, name: String, onProgress: ((String) -> Unit)? = null): Result<Provider>
+ suspend fun loginXtream(serverUrl: String, username: String, password: String, name: String, onProgress: ((String) -> Unit)? = null, id: Long? = null): Result<Provider>
+ suspend fun validateM3u(url: String, name: String, onProgress: ((String) -> Unit)? = null, id: Long? = null): Result<Provider>
suspend fun refreshProviderData(providerId: Long, onProgress: ((String) -> Unit)? = null): Result<Unit>
}
diff --git a/domain/src/main/java/com/streamvault/domain/manager/ParentalControlManager.kt b/domain/src/main/java/com/streamvault/domain/manager/ParentalControlManager.kt
new file mode 100644
index 00000000..2f82762d
--- /dev/null
+++ b/domain/src/main/java/com/streamvault/domain/manager/ParentalControlManager.kt
@@ -0,0 +1,27 @@
+package com.streamvault.domain.manager
+
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import javax.inject.Inject
+import javax.inject.Singleton
+
+@Singleton
+class ParentalControlManager @Inject constructor() {
+ private val _unlockedCategories = MutableStateFlow<Set<Long>>(emptySet())
+ val unlockedCategories: StateFlow<Set<Long>> = _unlockedCategories.asStateFlow()
+
+ fun unlockCategory(categoryId: Long) {
+ val current = _unlockedCategories.value.toMutableSet()
+ current.add(categoryId)
+ _unlockedCategories.value = current
+ }
+
+ fun isCategoryUnlocked(categoryId: Long): Boolean {
+ return _unlockedCategories.value.contains(categoryId)
+ }
+
+ fun clearUnlockedCategories() {
+ _unlockedCategories.value = emptySet()
+ }
+}
diff --git a/domain/src/main/java/com/streamvault/domain/model/Category.kt b/domain/src/main/java/com/streamvault/domain/model/Category.kt
index 16f7ecf0..a26bfd47 100644
--- a/domain/src/main/java/com/streamvault/domain/model/Category.kt
+++ b/domain/src/main/java/com/streamvault/domain/model/Category.kt
@@ -7,5 +7,6 @@ data class Category(
val type: ContentType = ContentType.LIVE,
val isVirtual: Boolean = false,
val count: Int = 0,
- val isAdult: Boolean = false
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/src/main/java/com/streamvault/domain/model/Channel.kt b/domain/src/main/java/com/streamvault/domain/model/Channel.kt
index 8d7f0130..02e859f8 100644
--- a/domain/src/main/java/com/streamvault/domain/model/Channel.kt
+++ b/domain/src/main/java/com/streamvault/domain/model/Channel.kt
@@ -16,5 +16,6 @@ data class Channel(
val providerId: Long = 0,
val currentProgram: Program? = null,
val nextProgram: Program? = null,
- val isAdult: Boolean = false
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/src/main/java/com/streamvault/domain/model/Movie.kt b/domain/src/main/java/com/streamvault/domain/model/Movie.kt
index ae073408..365804fe 100644
--- a/domain/src/main/java/com/streamvault/domain/model/Movie.kt
+++ b/domain/src/main/java/com/streamvault/domain/model/Movie.kt
@@ -23,5 +23,7 @@ data class Movie(
val isFavorite: Boolean = false,
val providerId: Long = 0,
val watchProgress: Long = 0L,
- val lastWatchedAt: Long = 0L
+ val lastWatchedAt: Long = 0L,
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/src/main/java/com/streamvault/domain/model/Series.kt b/domain/src/main/java/com/streamvault/domain/model/Series.kt
index e46daa09..61c5efd6 100644
--- a/domain/src/main/java/com/streamvault/domain/model/Series.kt
+++ b/domain/src/main/java/com/streamvault/domain/model/Series.kt
@@ -19,7 +19,9 @@ data class Series(
val providerId: Long = 0,
val seasons: List<Season> = emptyList(),
val episodeRunTime: String? = null,
- val lastModified: Long = 0L
+ val lastModified: Long = 0L,
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
data class Season(
@@ -47,5 +49,7 @@ data class Episode(
val seriesId: Long = 0,
val providerId: Long = 0,
val watchProgress: Long = 0L,
- val lastWatchedAt: Long = 0L
+ val lastWatchedAt: Long = 0L,
+ val isAdult: Boolean = false,
+ val isUserProtected: Boolean = false
)
diff --git a/domain/src/main/java/com/streamvault/domain/repository/CategoryRepository.kt b/domain/src/main/java/com/streamvault/domain/repository/CategoryRepository.kt
new file mode 100644
index 00000000..a5fb174b
--- /dev/null
+++ b/domain/src/main/java/com/streamvault/domain/repository/CategoryRepository.kt
@@ -0,0 +1,9 @@
+package com.streamvault.domain.repository
+
+import com.streamvault.domain.model.Category
+import kotlinx.coroutines.flow.Flow
+
+interface CategoryRepository {
+ fun getCategories(providerId: Long): Flow<List<Category>>
+ suspend fun setCategoryProtection(categoryId: Long, isProtected: Boolean)
+}
diff --git a/domain/src/main/java/com/streamvault/domain/repository/ProviderRepository.kt b/domain/src/main/java/com/streamvault/domain/repository/ProviderRepository.kt
index 9e2628ec..54a2b3ce 100644
--- a/domain/src/main/java/com/streamvault/domain/repository/ProviderRepository.kt
+++ b/domain/src/main/java/com/streamvault/domain/repository/ProviderRepository.kt
@@ -12,7 +12,7 @@ interface ProviderRepository {
suspend fun updateProvider(provider: Provider): Result<Unit>
suspend fun deleteProvider(id: Long): Result<Unit>
suspend fun setActiveProvider(id: Long): Result<Unit>
- suspend fun loginXtream(serverUrl: String, username: String, password: String, name: String, onProgress: ((String) -> Unit)? = null): Result<Provider>
- suspend fun validateM3u(url: String, name: String, onProgress: ((String) -> Unit)? = null): Result<Provider>
+ suspend fun loginXtream(serverUrl: String, username: String, password: String, name: String, onProgress: ((String) -> Unit)? = null, id: Long? = null): Result<Provider>
+ suspend fun validateM3u(url: String, name: String, onProgress: ((String) -> Unit)? = null, id: Long? = null): Result<Provider>
suspend fun refreshProviderData(providerId: Long, onProgress: ((String) -> Unit)? = null): Result<Unit>
}
diff --git a/final_build_output.txt b/final_build_output.txt
new file mode 100644
index 00000000..fab618c9
Binary files /dev/null and b/final_build_output.txt differ