diff --git a/Project/android/app/src/main/java/sae/android/sae_2a/VM/VocabularyViewModel.kt b/Project/android/app/src/main/java/sae/android/sae_2a/VM/VocabularyViewModel.kt new file mode 100644 index 0000000..24546ec --- /dev/null +++ b/Project/android/app/src/main/java/sae/android/sae_2a/VM/VocabularyViewModel.kt @@ -0,0 +1,26 @@ +package sae.android.sae_2a.VM + +import androidx.compose.runtime.mutableStateListOf +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.launch +import sae.android.sae_2a.data.Vocabulary + +class VocabularyViewModel : ViewModel() { + private val _vocabulary = mutableStateListOf() + val vocabulary: List get() = _vocabulary + + init { + loadVocabulary() + } + + private fun loadVocabulary() { + viewModelScope.launch { + _vocabulary.add(Vocabulary("test","Auteur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple"))) + } + } + + fun addVocabulary(vocabulary: Vocabulary){ + _vocabulary.add(vocabulary) + } +} \ No newline at end of file diff --git a/Project/android/app/src/main/java/sae/android/sae_2a/view/HomeScreen.kt b/Project/android/app/src/main/java/sae/android/sae_2a/view/HomeScreen.kt index 1116504..25cf34a 100644 --- a/Project/android/app/src/main/java/sae/android/sae_2a/view/HomeScreen.kt +++ b/Project/android/app/src/main/java/sae/android/sae_2a/view/HomeScreen.kt @@ -10,8 +10,8 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentWidth -//import androidx.compose.material.BottomNavigation -//import androidx.compose.material.BottomNavigationItem +import androidx.compose.material.BottomNavigation +import androidx.compose.material.BottomNavigationItem import androidx.compose.material3.Button import androidx.compose.material3.Icon import androidx.compose.material3.Scaffold diff --git a/Project/android/app/src/main/java/sae/android/sae_2a/view/VocabularyListScreen.kt b/Project/android/app/src/main/java/sae/android/sae_2a/view/VocabularyListScreen.kt index ae1ba75..0e5e248 100644 --- a/Project/android/app/src/main/java/sae/android/sae_2a/view/VocabularyListScreen.kt +++ b/Project/android/app/src/main/java/sae/android/sae_2a/view/VocabularyListScreen.kt @@ -25,6 +25,7 @@ import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Text @@ -40,12 +41,14 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.sp +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.compose.rememberNavController import sae.android.sae_2a.R +import sae.android.sae_2a.VM.VocabularyViewModel @Composable fun VocabularyScreen(onNavigateToList: () -> Unit, onNavigateToDetails: (Vocabulary) -> Unit = {}){ - val vocabulary = listOf( + /*val vocabulary = listOf( Vocabulary("test","Auteur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), Vocabulary("test2","Auteur2", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), Vocabulary("test","Auteur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), @@ -64,21 +67,30 @@ fun VocabularyScreen(onNavigateToList: () -> Unit, onNavigateToDetails: (Vocabul Vocabulary("test2","Auteur2", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), Vocabulary("test","Auteur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), Vocabulary("test2","Auteur2", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), - ) - DisplayLists(vocabulary, onNavigateToDetails) + )*/ + val vocVM: VocabularyViewModel = viewModel() + DisplayLists(vocVM.vocabulary, vocVM, onNavigateToDetails) } @Composable -fun DisplayLists(vocabulary: List, onCardClick: (Vocabulary) -> Unit = {}){ +fun DisplayLists(vocabulary: List, vocVM: VocabularyViewModel, onCardClick: (Vocabulary) -> Unit = {}){ LazyVerticalGrid( columns = GridCells.Adaptive(150.dp), horizontalArrangement = Arrangement.spacedBy(10.dp), contentPadding = PaddingValues(10.dp), - verticalArrangement = Arrangement.spacedBy(10.dp)) { + verticalArrangement = Arrangement.spacedBy(10.dp), + modifier = Modifier.padding(0.dp, 40.dp, 0.dp, 0.dp)) { items(vocabulary.size) { voc -> VocCard(vocabulary[voc]) Spacer(modifier = Modifier.size(10.dp)) } } + Text(text = stringResource(id = R.string.voc_list_title), + fontSize = 30.sp, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth()) + Button(onClick = { vocVM.addVocabulary(Vocabulary("test2","Auteur2", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple"))) }) { + Text(text = stringResource(id = R.string.add_voc)) + } } diff --git a/Project/android/app/src/main/res/values/strings.xml b/Project/android/app/src/main/res/values/strings.xml index 8b56d0e..d37cc00 100644 --- a/Project/android/app/src/main/res/values/strings.xml +++ b/Project/android/app/src/main/res/values/strings.xml @@ -15,4 +15,6 @@ Register Account Details Change Password + Vocabulary lists + New list \ No newline at end of file diff --git a/Project/android/build.gradle.kts b/Project/android/build.gradle.kts index 4645626..a7d3dac 100644 --- a/Project/android/build.gradle.kts +++ b/Project/android/build.gradle.kts @@ -1,5 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.2.2" apply false + id("com.android.application") version "8.3.1" apply false id("org.jetbrains.kotlin.android") version "1.9.0" apply false } \ No newline at end of file diff --git a/Project/android/gradle/wrapper/gradle-wrapper.properties b/Project/android/gradle/wrapper/gradle-wrapper.properties index b206bab..7195314 100644 --- a/Project/android/gradle/wrapper/gradle-wrapper.properties +++ b/Project/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Mar 13 08:54:26 CET 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists