ViewModel pour NavBar

pull/51/head
Leni BEAULATON 3 weeks ago
parent 9d54fce591
commit c813196555

@ -11,8 +11,6 @@ import com.example.what_the_fantasy.data.model.Favorite
import com.example.what_the_fantasy.data.model.Quote
import com.example.what_the_fantasy.data.model.SrcLanguage
import com.example.what_the_fantasy.ui.components.hashPassword
import com.example.what_the_fantasy.ui.states.AuthUserState
import kotlinx.coroutines.flow.StateFlow
import java.time.LocalDate
class ServicesStub : IServices {

@ -1,5 +1,6 @@
package com.example.what_the_fantasy.ui.components
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@ -10,7 +11,9 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.*
@ -18,10 +21,10 @@ import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.IconToggleButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@ -32,20 +35,24 @@ import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.rememberAsyncImagePainter
import coil.compose.rememberImagePainter
import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.ui.theme.*
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun NavBar(onProfile : Boolean = false ,
onFavorite : Boolean = false ,
onAccueil : Boolean = false ,
onQuiz : Boolean = false ,
index:Int,
fun NavBar(onProfile : Boolean = false,
onFavorite : Boolean = false,
onAccueil : Boolean = false,
onQuiz : Boolean = false,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
navControllerProfil: (Int) -> Unit,
navControllerFavorite:(Int) -> Unit,
navControllerAccueil: (Int) -> Unit,
navControllerQuiz: (Int) -> Unit,
content : @Composable ()-> Unit ) {
var theme by remember { mutableStateOf(true) }
@ -64,7 +71,7 @@ fun NavBar(onProfile : Boolean = false ,
Arrangement.SpaceBetween,
verticalAlignment = Alignment.Bottom
) {
ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",navControllerProfil,index,onProfile)
ButtonIconVectorInt(currentUserState.imagePath,"Profile",navControllerProfil,currentUserState.id,onProfile)
IconButton(onClick = { theme=!theme},
@ -100,17 +107,17 @@ fun NavBar(onProfile : Boolean = false ,
ButtonIconPainterInt(painterResource(
if(onFavorite)R.drawable.favorite_button_full
else R.drawable.favorite_button_empty
),"Favorite",navControllerFavorite,index,onFavorite)
),"Favorite",navControllerFavorite,currentUserState.id,onFavorite)
ButtonIconPainterInt(painterResource(
if(onAccueil)R.drawable.home_button_full
else R.drawable.home_button_empty
),"Accueil",navControllerAccueil,index,onAccueil)
),"Accueil",navControllerAccueil,currentUserState.id,onAccueil)
ButtonIconPainterInt(painterResource(
if(onQuiz)R.drawable.quiz_button_full
else R.drawable.quiz_button_empty
),"Quiz",navControllerQuiz,index,onQuiz)
),"Quiz",navControllerQuiz,currentUserState.id,onQuiz)
}
}
@ -118,7 +125,7 @@ fun NavBar(onProfile : Boolean = false ,
}
@Composable
fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,index: Int,onPage : Boolean){
fun ButtonIconVectorInt(img : String, name : String, nav : (Int)->Unit ,index: Int,onPage : Boolean){
IconButton(onClick = {nav(index)},
enabled = !onPage,
colors = IconButtonColors(Color.Transparent, MaterialTheme.colorScheme.onBackground,//couleur quand il n'est pas selectionné
@ -126,10 +133,13 @@ fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,ind
modifier = Modifier
.size(60.dp)
) {
Icon(img,
Image(
painter = rememberAsyncImagePainter(img),
contentDescription = name,
modifier = Modifier
.fillMaxSize()
.clip(CircleShape) // Pour rendre l'image circulaire
)
}
}

@ -105,7 +105,6 @@ fun AppNavigator() {
composable<Accueil> {
val accueil: Accueil = it.toRoute()
AccueilPage(
index = accueil.userIndex,
navFavorite = { navController.navigate(Favorite(accueil.userIndex)) },
navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) },
navProfil = { navController.navigate(Profil(accueil.userIndex)) },
@ -117,7 +116,9 @@ fun AppNavigator() {
)
)
},
services = services
services = services,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<Favorite> {
@ -135,7 +136,9 @@ fun AppNavigator() {
)
)
},
services = services
services = services,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<Profil> {
@ -163,7 +166,9 @@ fun AppNavigator() {
navQuiz = { navController.navigate(QuizMenu(quote.userIndex)) },
navProfil = { navController.navigate(Profil(quote.userIndex)) },
navFavorite = { navController.navigate(Favorite(quote.userIndex)) },
service = services
service = services,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<Search> { SearchPage() }
@ -197,7 +202,9 @@ fun AppNavigator() {
source
)
)
}
},
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<RecapSubmit> {
@ -209,20 +216,24 @@ fun AppNavigator() {
source = recapSubmit.source,
navAccueil = { navController.navigate(Accueil(recapSubmit.userIndex)) },
navFavorite = { navController.navigate(Favorite(recapSubmit.userIndex)) },
navProfil = { navController.navigate(Profil(recapSubmit.userIndex)) }
navProfil = { navController.navigate(Profil(recapSubmit.userIndex)) },
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<QuizMenu> {
val quizMenu: QuizMenu = it.toRoute()
QuizMenu(
index = quizMenu.userIndex,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navAccueil = { navController.navigate(Accueil(quizMenu.userIndex)) },
navFavorite = { navController.navigate(Favorite(quizMenu.userIndex)) },
navProfil = { navController.navigate(Profil(quizMenu.userIndex)) },
navControllerQuiz = { idQuiz ->
navController.navigate(Quiz(quizMenu.userIndex, idQuiz))
}
},
)
}
composable<Quiz> {
@ -236,7 +247,9 @@ fun AppNavigator() {
navControllerQuizEnd = { idQuiz, pts ->
navController.navigate(QuizEnd(quiz.userIndex, idQuiz, pts))
},
idQuiz = quiz.idQuiz
idQuiz = quiz.idQuiz,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<QuizEnd> {
@ -248,7 +261,9 @@ fun AppNavigator() {
navAccueil = { navController.navigate(Accueil(quizEnd.userIndex)) },
navFavorite = { navController.navigate(Favorite(quizEnd.userIndex)) },
navProfil = { navController.navigate(Profil(quizEnd.userIndex)) },
navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) }
navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) },
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
}

@ -21,28 +21,31 @@ import com.example.what_the_fantasy.data.local.DailyQuoteStub
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun AccueilPage(
index: Int,
navFavorite: (Int) -> Unit,
navQuiz: (Int) -> Unit,
navProfil: (Int) -> Unit,
navQuote: (Int) -> Unit,
services: IServices
services: IServices,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
) {
var itemCount by remember { mutableStateOf(15) }
val dailyQuote = DailyQuoteStub.dailyQuote
val quotes = services.getAllQuote().take(itemCount)
val user = services.getUserById(index) ?: return
val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote)
val titleSuggestion = stringResource(R.string.TitleHomeSuggestion)
NavBar(
onAccueil = true,
index = index,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = { },
navControllerProfil = navProfil,
@ -82,7 +85,7 @@ fun AccueilPage(
Column(Modifier.clickable {navQuote(quote.id)}
) {
if(quote.language == user.langage){
if(quote.language == currentUserState.langage){
QuoteLittle(quote)
Spacer(modifier = Modifier.height(16.dp))
}

@ -21,7 +21,9 @@ import com.example.what_the_fantasy.data.local.FavoriteStub
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun FavoritePage(
@ -30,7 +32,9 @@ fun FavoritePage(
navQuiz: (Int) -> Unit,
navProfil: (Int) -> Unit,
navQuote: (Int) -> Unit,
services: IServices
services: IServices,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
val user = services.getUserById(index) ?: return
@ -38,7 +42,8 @@ fun FavoritePage(
val TitlePage = stringResource(R.string.TitleFavorite)
NavBar(onFavorite = true,
index = index,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = { },
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

@ -28,7 +28,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -46,7 +45,6 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import com.example.what_the_fantasy.Logs.LogsUsers
import com.example.what_the_fantasy.R
@ -67,11 +65,10 @@ fun ProfilPage(navFavorite: (Int) -> Unit,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
// val currentUserVM : CurrentUserViewModel = viewModel()
// val currentUserState by currentUserVM.currentUserState.collectAsState()
Log.e("Profil","${currentUserState.id}")
NavBar(onProfile = true,
index = currentUserState.id,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = {},

@ -17,6 +17,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.data.local.QuizStub
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
val gradient = Brush.linearGradient(
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)),
@ -33,8 +35,12 @@ fun QuizEndPage(
navAccueil: (Int) -> Unit,
navProfil:(Int) -> Unit,
navQuiz: (Int) -> Unit,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
NavBar(index = index,
NavBar(
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

@ -31,17 +31,22 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.data.local.QuizStub
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun QuizMenu(
index: Int,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
navFavorite: (Int) -> Unit,
navAccueil: (Int) -> Unit,
navProfil:(Int) -> Unit,
navControllerQuiz: (Int) -> Unit
navControllerQuiz: (Int) -> Unit,
) {
NavBar(onQuiz = true,
index = index,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

@ -19,10 +19,14 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.data.local.QuizStub
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun QuizPage(
index: Int,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
navFavorite: (Int) -> Unit,
navAccueil: (Int) -> Unit,
navProfil:(Int) -> Unit,
@ -56,7 +60,9 @@ fun QuizPage(
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
else navControllerQuizEnd(idQuiz, pts) // Retour menu
}
NavBar(index = index,
NavBar(
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

@ -35,11 +35,13 @@ import com.example.what_the_fantasy.R
import coil.compose.AsyncImage
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.theme.gradienBox
import com.example.what_the_fantasy.ui.theme.iconText
import com.example.what_the_fantasy.ui.theme.likeIcon
import com.example.what_the_fantasy.ui.theme.whiteBackcgroundText
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun QuotePage(
@ -49,12 +51,15 @@ fun QuotePage(
navAccueil: (Int) -> Unit,
navFavorite:(Int) -> Unit,
navQuiz: (Int) -> Unit,
navProfil:(Int) -> Unit)
navProfil:(Int) -> Unit,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,)
{
var quote = service.getQuote(quoteId) ?: return
val context = LocalContext.current
NavBar(onProfile = true,
index = index,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

@ -39,6 +39,8 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import com.example.what_the_fantasy.data.model.Character
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
@ -49,10 +51,13 @@ fun RecapSubmitPage(
navProfil:(Int) -> Unit,
quoteContent : String,
character: String,
source: String
source: String,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
NavBar(onQuiz = true,
index = index,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

@ -34,8 +34,10 @@ import com.example.what_the_fantasy.ui.components.ErrorMessageSubmitQuoteCompone
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.components.SpaceHeightComponent
import com.example.what_the_fantasy.ui.components.TitlePageComponent
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.theme.gradienBox
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun SubmitQuotePage(
@ -44,10 +46,13 @@ fun SubmitQuotePage(
navAccueil: (Int) -> Unit,
navProfil:(Int) -> Unit,
navControllerQuiz: (Int) -> Unit,
navRecap: (String, String, String) -> Unit
navRecap: (String, String, String) -> Unit,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
NavBar(
index = index,
currentUserVM = currentUserVM,
currentUserState = currentUserState,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,

Loading…
Cancel
Save