Lucie GOIGOUX 1 year ago
commit a8de648b8b

@ -40,7 +40,7 @@ android {
compose = true compose = true
} }
composeOptions { composeOptions {
kotlinCompilerExtensionVersion = "1.5.1" kotlinCompilerExtensionVersion = "1.5.11"
} }
packaging { packaging {
resources { resources {
@ -50,7 +50,7 @@ android {
} }
dependencies { dependencies {
implementation("androidx.compose.material:material:1.6.4")
implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.0") implementation("androidx.activity:activity-compose:1.7.0")

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

@ -0,0 +1,21 @@
package sae.android.sae_2a.VM
import android.text.Spannable.Factory
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import sae.android.sae_2a.data.Game
class GameViewModel : ViewModel() {
}

@ -0,0 +1,5 @@
package sae.android.sae_2a.data
data class Game(
val name: String
)

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

@ -0,0 +1,76 @@
package sae.android.sae_2a.view
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.paddingFrom
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.foundation.lazy.LazyColumn
import androidx.compose.material3.Button
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.AlignmentLine
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import sae.android.sae_2a.data.Game
import sae.android.sae_2a.data.Vocabulary
import sae.android.sae_2a.game.DisplayLists
@Composable
fun GameScreen(NavigateToApp: () -> Unit ){
val game = listOf(
Game("Quizz"),
Game("Memory"),
Game("Asteroid"),
Game("Flashcard"),
)
Surface(modifier = Modifier
.wrapContentWidth(align = Alignment.CenterHorizontally)
.wrapContentHeight(align = Alignment.CenterVertically)
.fillMaxSize(),) {
Column( modifier = Modifier
.background(color = Color.LightGray)
.wrapContentWidth(align = Alignment.CenterHorizontally)) {
Text(text = "Games", fontSize = 32.sp ,modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(vertical = 100.dp)
)
ListGame(games =game )
}
}
}
@Composable
fun ListGame(games : List<Game>){
LazyColumn(){
items( games.size ){
DisplayGame(games[it])
}
}
}
@Composable
fun DisplayGame(game :Game){
Button(onClick = { },modifier = Modifier
.padding(15.dp)
.width(150.dp)
.height(80.dp)) {
Text(text = game.name, fontSize = 20.sp)
}
}

@ -10,7 +10,10 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -28,19 +31,36 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import sae.android.sae_2a.R import sae.android.sae_2a.R
import sae.android.sae_2a.game.VocabularyScreen import sae.android.sae_2a.game.VocabularyScreen
@Preview @Preview
@Composable @Composable
fun MyApp() { fun MyApp() {
val navController = rememberNavController() val navController = rememberNavController()
/* Scaffold(
bottomBar = {
BottomNavigation {
BottomNavigationItem(selected = , onClick = { /*TODO*/ }, icon = { /*TODO*/ }){
}
}
}
)*/
NavHost(navController, startDestination = "HomeScreen") { NavHost(navController, startDestination = "HomeScreen") {
composable("HomeScreen") { HomeScreen( NavigateToRegister = { navController.navigate("RegisterScreen")} ,NavigateToLogin = { navController.navigate("VocabularyScreen") }) } composable("HomeScreen") { HomeScreen( NavigateToRegister = { navController.navigate("RegisterScreen")} ,NavigateToLogin = { navController.navigate("GameScreen") }) }
composable("VocabularyScreen") { VocabularyScreen(onNavigateToList = { navController.navigate("HomeScreen") }) } composable("VocabularyScreen") { VocabularyScreen(onNavigateToList = { navController.popBackStack() }) }
composable("RegisterScreen") { RegisterScreen(NavigateToApp = { navController.navigate("VocabularyScreen") }) } composable("RegisterScreen") { RegisterScreen(NavigateToApp = { navController.navigate("VocabularyScreen") }) }
composable("GameScreen"){ GameScreen() {
//
} }
} }
} }
@Composable
fun BottomNav(){
}
@Composable @Composable
fun HomeScreen(NavigateToRegister: () -> Unit,NavigateToLogin: () -> Unit ){ fun HomeScreen(NavigateToRegister: () -> Unit,NavigateToLogin: () -> Unit ){
@ -63,7 +83,7 @@ fun HomeScreen(NavigateToRegister: () -> Unit,NavigateToLogin: () -> Unit ){
.size(width = 200.dp, height = 200.dp) .size(width = 200.dp, height = 200.dp)
) )
Text(text ="InEnglishPlease", color = Color.White, fontSize = 30.sp, fontWeight = FontWeight(1000) , modifier = Modifier Text(text ="InEnglishPlease", color = Color.White, fontSize = 30.sp, fontWeight = FontWeight(1000) , modifier = Modifier
.padding(70.dp) .padding(40.dp)
.wrapContentHeight(align = Alignment.Top) .wrapContentHeight(align = Alignment.Top)
.wrapContentWidth(align = Alignment.CenterHorizontally) .wrapContentWidth(align = Alignment.CenterHorizontally)
.align(alignment = Alignment.CenterHorizontally)) .align(alignment = Alignment.CenterHorizontally))

@ -1,10 +1,13 @@
package sae.android.sae_2a.game package sae.android.sae_2a.game
import android.widget.GridLayout import android.widget.GridLayout
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column 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.Spacer
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize 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.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment 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.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.navigation.compose.rememberNavController
import sae.android.sae_2a.R import sae.android.sae_2a.R
@Composable @Composable
fun VocabularyScreen(onNavigateToList: () -> Unit){ fun VocabularyScreen(onNavigateToList: () -> Unit, onNavigateToDetails: (Vocabulary) -> Unit = {}){
val vocabulary = listOf( val vocabulary = listOf(
Vocabulary("test","Autheur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")), Vocabulary("test","Auteur", hashMapOf("Fromage" to "Cheese", "Pomme" to "Apple")),
Vocabulary("test2","Autheur2", 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 @Composable
fun DisplayLists(vocabulary: List<Vocabulary>) { fun DisplayLists(vocabulary: List<Vocabulary>, onCardClick: (Vocabulary) -> Unit = {}){
LazyVerticalGrid( columns = GridCells.Adaptive(150.dp), LazyVerticalGrid( columns = GridCells.Adaptive(150.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp), horizontalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = PaddingValues(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)) { verticalArrangement = Arrangement.spacedBy(10.dp)) {
items(vocabulary.size) { voc -> items(vocabulary.size) { voc ->
VocCard(vocabulary[voc]) VocCard(vocabulary[voc])
@ -58,9 +82,12 @@ fun DisplayLists(vocabulary: List<Vocabulary>) {
} }
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun VocCard(vocabulary: Vocabulary){ fun VocCard(vocabulary: Vocabulary){
Card(shape = RectangleShape, Card(shape = RectangleShape,
onClick = {
},
modifier = Modifier modifier = Modifier
.size(150.dp, 150.dp) .size(150.dp, 150.dp)
.border(2.dp, Color.DarkGray, shape = RoundedCornerShape(8.dp, 8.dp))) { .border(2.dp, Color.DarkGray, shape = RoundedCornerShape(8.dp, 8.dp))) {
@ -94,3 +121,84 @@ fun PreviewCard(){
laMap["Pomme"] = "Apple" laMap["Pomme"] = "Apple"
VocCard(Vocabulary("test","Autheur", laMap)) 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))
}

@ -7,7 +7,7 @@
<string name="signIn">Sign In</string> <string name="signIn">Sign In</string>
<string name="password">Password</string> <string name="password">Password</string>
<string name="voc_image_description">Picture representing vocabulary</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> <string name="unknown">Unknown</string>
<string name="profilePicture">Profile Picture</string> <string name="profilePicture">Profile Picture</string>
<string name="home">Home</string> <string name="home">Home</string>

Loading…
Cancel
Save