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.runtime) // ADDED: Explicitly add runtime
|
||||||
implementation(libs.androidx.room.ktx)
|
implementation(libs.androidx.room.ktx)
|
||||||
implementation(libs.core.ktx)
|
implementation(libs.core.ktx)
|
||||||
|
implementation(libs.androidx.compose.runtime)
|
||||||
ksp(libs.room.compiler)
|
ksp(libs.room.compiler)
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
|
|||||||
@@ -154,8 +154,22 @@ fun AppNavHost(
|
|||||||
NewWordReviewScreen(navController = navController)
|
NewWordReviewScreen(navController = navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(NavigationRoutes.START_EXERCISE) {
|
composable(
|
||||||
StartExerciseScreen(navController = navController)
|
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.
|
// 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.Text
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
@@ -76,17 +77,30 @@ import kotlinx.coroutines.launch
|
|||||||
@Composable
|
@Composable
|
||||||
fun StartExerciseScreen(
|
fun StartExerciseScreen(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
|
preselectedCategoryId: Int? = null,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val activity = androidx.compose.ui.platform.LocalContext.current.findActivity()
|
val activity = androidx.compose.ui.platform.LocalContext.current.findActivity()
|
||||||
val vocabularyViewModel: VocabularyViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
val vocabularyViewModel: VocabularyViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||||
|
val categoryViewModel: CategoryViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||||
val exerciseViewModel: VocabularyExerciseViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
val exerciseViewModel: VocabularyExerciseViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||||
|
|
||||||
val exerciseConfig by exerciseViewModel.pendingExerciseConfig.collectAsState()
|
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 selectedLanguagePairs by remember { mutableStateOf<List<Pair<Language, Language>>>(emptyList()) }
|
||||||
var selectedCategories by remember { mutableStateOf<List<VocabularyCategory>>(emptyList()) }
|
var selectedCategories by remember { mutableStateOf<List<VocabularyCategory>>(emptyList()) }
|
||||||
var selectedStages by remember { mutableStateOf<List<VocabularyStage>>(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 selectedOriginLanguage by remember { mutableStateOf<Language?>(null) }
|
||||||
var selectedTargetLanguage by remember { mutableStateOf<Language?>(null) }
|
var selectedTargetLanguage by remember { mutableStateOf<Language?>(null) }
|
||||||
val isDirectionPreferenceSet = selectedOriginLanguage != null || selectedTargetLanguage != null
|
val isDirectionPreferenceSet = selectedOriginLanguage != null || selectedTargetLanguage != null
|
||||||
|
|||||||
@@ -255,9 +255,7 @@ fun CategoryDetailScreen(
|
|||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
categoryProgress = categoryProgress,
|
categoryProgress = categoryProgress,
|
||||||
onStartExerciseClick = {
|
onStartExerciseClick = {
|
||||||
val categories = listOf(category)
|
navController.navigate("start_exercise?categoryId=$categoryId")
|
||||||
val categoryIds = categories.joinToString(",") { it?.id.toString() }
|
|
||||||
navController.navigate("vocabulary_exercise/false?categories=$categoryIds")
|
|
||||||
},
|
},
|
||||||
onEditClick = {
|
onEditClick = {
|
||||||
categoryViewModel.setShowEditCategoryDialog(true, categoryId)
|
categoryViewModel.setShowEditCategoryDialog(true, categoryId)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ coreKtxVersion = "1.7.0"
|
|||||||
truth = "1.4.5"
|
truth = "1.4.5"
|
||||||
zstdJni = "1.5.7-7"
|
zstdJni = "1.5.7-7"
|
||||||
composeMarkdown = "0.5.8"
|
composeMarkdown = "0.5.8"
|
||||||
|
runtime = "1.10.3"
|
||||||
|
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
@@ -102,6 +103,7 @@ hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", ve
|
|||||||
hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version = "1.3.0" }
|
hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version = "1.3.0" }
|
||||||
mockk = { module = "io.mockk:mockk", version = "1.14.9" }
|
mockk = { module = "io.mockk:mockk", version = "1.14.9" }
|
||||||
compose-markdown = { module = "com.github.jeziellago:compose-markdown", version.ref = "composeMarkdown" }
|
compose-markdown = { module = "com.github.jeziellago:compose-markdown", version.ref = "composeMarkdown" }
|
||||||
|
androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "runtime" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
Reference in New Issue
Block a user