implement category preselection in StartExerciseScreen and update navigation logic from CategoryDetailScreen
This commit is contained in:
@@ -126,6 +126,7 @@ dependencies {
|
||||
implementation(libs.androidx.room.runtime) // ADDED: Explicitly add runtime
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.core.ktx)
|
||||
implementation(libs.androidx.compose.runtime)
|
||||
ksp(libs.room.compiler)
|
||||
|
||||
// Networking
|
||||
|
||||
@@ -154,8 +154,22 @@ fun AppNavHost(
|
||||
NewWordReviewScreen(navController = navController)
|
||||
}
|
||||
|
||||
composable(NavigationRoutes.START_EXERCISE) {
|
||||
StartExerciseScreen(navController = navController)
|
||||
composable(
|
||||
route = "${NavigationRoutes.START_EXERCISE}?categoryId={categoryId}",
|
||||
arguments = listOf(
|
||||
navArgument("categoryId") {
|
||||
type = NavType.StringType
|
||||
nullable = true
|
||||
defaultValue = null
|
||||
}
|
||||
)
|
||||
) { backStackEntry ->
|
||||
val categoryIdString = backStackEntry.arguments?.getString("categoryId")
|
||||
val categoryId = categoryIdString?.toIntOrNull()
|
||||
StartExerciseScreen(
|
||||
navController = navController,
|
||||
preselectedCategoryId = categoryId
|
||||
)
|
||||
}
|
||||
|
||||
// Define all other navigation graphs at the same top level.
|
||||
|
||||
@@ -35,6 +35,7 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
@@ -76,17 +77,30 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun StartExerciseScreen(
|
||||
navController: NavHostController,
|
||||
preselectedCategoryId: Int? = null,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val activity = androidx.compose.ui.platform.LocalContext.current.findActivity()
|
||||
val vocabularyViewModel: VocabularyViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||
val categoryViewModel: CategoryViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||
val exerciseViewModel: VocabularyExerciseViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||
|
||||
val exerciseConfig by exerciseViewModel.pendingExerciseConfig.collectAsState()
|
||||
val allCategories by categoryViewModel.categories.collectAsState(initial = emptyList())
|
||||
var selectedLanguagePairs by remember { mutableStateOf<List<Pair<Language, Language>>>(emptyList()) }
|
||||
var selectedCategories by remember { mutableStateOf<List<VocabularyCategory>>(emptyList()) }
|
||||
var selectedStages by remember { mutableStateOf<List<VocabularyStage>>(emptyList()) }
|
||||
|
||||
// Initialize preselected category
|
||||
LaunchedEffect(allCategories, preselectedCategoryId) {
|
||||
if (preselectedCategoryId != null) {
|
||||
val category = allCategories.find { it.id == preselectedCategoryId }
|
||||
if (category != null && category !in selectedCategories) {
|
||||
selectedCategories = listOf(category)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var selectedOriginLanguage by remember { mutableStateOf<Language?>(null) }
|
||||
var selectedTargetLanguage by remember { mutableStateOf<Language?>(null) }
|
||||
val isDirectionPreferenceSet = selectedOriginLanguage != null || selectedTargetLanguage != null
|
||||
|
||||
@@ -255,9 +255,7 @@ fun CategoryDetailScreen(
|
||||
subtitle = subtitle,
|
||||
categoryProgress = categoryProgress,
|
||||
onStartExerciseClick = {
|
||||
val categories = listOf(category)
|
||||
val categoryIds = categories.joinToString(",") { it?.id.toString() }
|
||||
navController.navigate("vocabulary_exercise/false?categories=$categoryIds")
|
||||
navController.navigate("start_exercise?categoryId=$categoryId")
|
||||
},
|
||||
onEditClick = {
|
||||
categoryViewModel.setShowEditCategoryDialog(true, categoryId)
|
||||
|
||||
Reference in New Issue
Block a user