avancé sur vocabulary

android
Antoine JOURDAIN 1 year ago
parent 0699f131f2
commit 8fe24d6540

@ -11,6 +11,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import sae.android.sae_2a.game.VocabularyScreen
import sae.android.sae_2a.view.MyApp
import sae.android.sae_2a.ui.theme.SAE_2ATheme
import sae.android.sae_2a.view.PreviewLoginScreen
@ -18,7 +20,7 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PreviewLoginScreen()
MyApp()
}
}
}

@ -3,5 +3,5 @@ package sae.android.sae_2a.data
data class Vocabulary(
val name: String,
val aut: String?,
val listWord: Map<String, String>
val words: Map<String, String>
)

@ -33,7 +33,7 @@ fun MyApp() {
val navController = rememberNavController()
NavHost(navController, startDestination = "HomeScreen") {
composable("HomeScreen") { HomeScreen( NavigateToRegister = { navController.navigate("RegisterScreen")} ,NavigateToLogin = { navController.navigate("VocabularyScreen") }) }
composable("VocabularyScreen") { VocabularyScreen(onNavigateToList = { navController.navigate("HomeScreen") }) }
composable("VocabularyScreen") { VocabularyScreen(onNavigateToList = { navController.popBackStack() }) }
composable("RegisterScreen") { RegisterScreen(NavigateToApp = { navController.navigate("VocabularyScreen") }) }
}

@ -1,10 +1,13 @@
package sae.android.sae_2a.game
import android.widget.GridLayout
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
@ -19,8 +22,11 @@ import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
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.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -34,21 +40,39 @@ 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.navigation.compose.rememberNavController
import sae.android.sae_2a.R
@Composable
fun VocabularyScreen(onNavigateToList: () -> Unit){
fun VocabularyScreen(onNavigateToList: () -> Unit, onNavigateToDetails: (Vocabulary) -> Unit = {}){
val vocabulary = listOf(
Vocabulary("test","Autheur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")),
Vocabulary("test2","Autheur2", 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")),
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")),
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")),
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")),
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")),
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")),
Vocabulary("test2","Auteur2", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")),
)
DisplayLists(vocabulary)
DisplayLists(vocabulary, onNavigateToDetails)
}
@Composable
fun DisplayLists(vocabulary: List<Vocabulary>) {
fun DisplayLists(vocabulary: List<Vocabulary>, onCardClick: (Vocabulary) -> Unit = {}){
LazyVerticalGrid( columns = GridCells.Adaptive(150.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = PaddingValues(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)) {
items(vocabulary.size) { voc ->
VocCard(vocabulary[voc])
@ -58,9 +82,12 @@ fun DisplayLists(vocabulary: List<Vocabulary>) {
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun VocCard(vocabulary: Vocabulary){
Card(shape = RectangleShape,
onClick = {
},
modifier = Modifier
.size(150.dp, 150.dp)
.border(2.dp, Color.DarkGray, shape = RoundedCornerShape(8.dp, 8.dp))) {
@ -94,3 +121,84 @@ fun PreviewCard(){
laMap["Pomme"] = "Apple"
VocCard(Vocabulary("test","Autheur", laMap))
}
@Preview
@Composable
fun PreviewVocabularyScreen(){
VocabularyScreen({})
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun VocabularyDetails(vocabulary: Vocabulary){
LazyColumn(modifier = Modifier.fillMaxSize()) {
stickyHeader(
) {
Text(
vocabulary.name, fontSize = 30.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Text(
stringResource(R.string.created_by) + (vocabulary.aut
?: stringResource(id = R.string.unknown)),
fontSize = 20.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
}
vocabulary.words.forEach { (key, value) ->
item {
WordCard(key, value)
}
}
}
}
@Composable
fun WordCard(key: String, value: String) {
Row {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
.weight(0.5f)
) {
Text(text = key, fontSize = 30.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth())
}
Card(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
.weight(0.5f)
) {
Text(text = value, fontSize = 30.sp,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth())
}
}
}
@Preview
@Composable
fun PreviewVocabularyDetails(){
val laMap = HashMap<String, String>()
laMap["Fromage"] = "Cheese"
laMap["Pomme"] = "Apple"
laMap["Pain"] = "Bread"
laMap["Eau"] = "Water"
laMap["Lait"] = "Milk"
laMap["Beurre"] = "Butter"
laMap["Sucre"] = "Sugar"
laMap["Sel"] = "Salt"
laMap["Poivre"] = "Pepper"
laMap["Farine"] = "Flour"
laMap["Oeuf"] = "Egg"
laMap["Viande"] = "Meat"
laMap["Poisson"] = "Fish"
laMap["Légume"] = "Vegetable"
laMap["Fruit"] = "Fruit"
VocabularyDetails(Vocabulary("test","Autheur", laMap))
}

@ -6,6 +6,6 @@
<string name="logOut">Log Out</string>
<string name="password">Password</string>
<string name="voc_image_description">Picture representing vocabulary</string>
<string name="created_by">Created by</string>
<string name="created_by">Created by\u0020</string>
<string name="unknown">Unknown</string>
</resources>
Loading…
Cancel
Save