diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/retrofit/ApiService.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/retrofit/ApiService.kt index 9b4f53e..e301532 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/retrofit/ApiService.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/retrofit/ApiService.kt @@ -5,6 +5,7 @@ import com.example.what_the_fantasy.data.model.LangAdapter import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.SrcLanguage import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.data.services.APIReponceList import com.google.gson.Gson import com.google.gson.GsonBuilder import retrofit2.Response @@ -61,7 +62,10 @@ interface ApiService { @GET("quote/{id}") suspend fun getQuoteById(@Path("id")id : Int):Quote @GET("quote/all") - suspend fun getAllQuote( @Query("index") index: Int, @Query("count") count: Int):List + suspend fun getAllQuote( + @Query("index") index: Int, + @Query("count") count: Int + ): APIReponceList @GET("image/all") diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/APIReponceList.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/APIReponceList.kt new file mode 100644 index 0000000..cf19a5f --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/APIReponceList.kt @@ -0,0 +1,17 @@ +package com.example.what_the_fantasy.data.services + +import com.google.gson.annotations.SerializedName + +data class APIReponceList ( + @SerializedName("totalCount") + val totalCount: Int, + + @SerializedName("pageIndex") + var index: Int, + + @SerializedName("countPerPage") + var count: Int, + + @SerializedName("items") + var items: MutableList, +) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt index 230702e..527e576 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt @@ -40,7 +40,7 @@ interface IServices { suspend fun isFavorite(idQuote : Int, iduser: Int): Boolean fun getAllFavorite(): List fun getAllQuote(): List - fun getSomeQuotes(nb: Int, page: Int) : MutableList + suspend fun getSomeQuotes(nb: Int, page: Int) : MutableList suspend fun getDalyQuote(langage : SrcLanguage) : Quote fun search(type : String ,search:String ,indexCount: Int): List } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt index 5b6452f..9c6222a 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt @@ -270,8 +270,9 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } - override fun getSomeQuotes(nb: Int, page: Int): MutableList { - TODO("Not yet implemented") + override suspend fun getSomeQuotes(nb: Int, page: Int): MutableList { + val reponce = RetrofitInstance.api.getAllQuote(page,nb) + return reponce.items } @RequiresApi(Build.VERSION_CODES.O) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt index 9d1840d..aab0342 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt @@ -143,7 +143,7 @@ class ServicesStub : IServices { return (quotes.find { it.id == id }) } - override fun getSomeQuotes(nb: Int, page: Int): MutableList { + override suspend fun getSomeQuotes(nb: Int, page: Int): MutableList { var nbQuote = nb if(nb < 0) nbQuote = 1 diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt index 9b99147..be30590 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt @@ -16,6 +16,7 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.navigation.toRoute +import com.example.what_the_fantasy.data.services.ServicesAPI import com.example.what_the_fantasy.data.services.ServicesStub import com.example.what_the_fantasy.ui.screens.* import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel @@ -73,7 +74,8 @@ data class RecapSubmit(val userIndex: Int, @Composable fun AppNavigator() { val navController = rememberNavController() - val services = ServicesStub() + val servicesStub = ServicesStub() + val services = ServicesAPI() //ViewModel pour l'authentification val authUserVM : AuthUserViewModel = viewModel() @@ -157,7 +159,7 @@ fun AppNavigator() { ) }, navSearch = { navController.navigate(Search(currentUserState.id))}, - services = services, + services = servicesStub, currentUserVM = currentUserVM, currentUserState = currentUserState, ) @@ -187,7 +189,7 @@ fun AppNavigator() { navQuiz = { navController.navigate(QuizMenu(currentUserState.id)) }, navProfil = { navController.navigate(Profil(currentUserState.id)) }, navFavorite = { navController.navigate(Favorite(currentUserState.id)) }, - service = services, + service = servicesStub, currentUserVM = currentUserVM, currentUserState = currentUserState, navSearch = { navController.navigate(Search(currentUserState.id))}, diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index d23a091..d40ac8d 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -1,6 +1,7 @@ package com.example.what_the_fantasy.ui.screens import android.annotation.SuppressLint +import android.util.Log import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* @@ -20,6 +21,8 @@ import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.DailyQuoteStub import com.example.what_the_fantasy.data.model.Quote +import com.example.what_the_fantasy.data.model.SrcLanguage +import com.example.what_the_fantasy.data.model.SrcType 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 @@ -43,9 +46,12 @@ fun AccueilPage( ) { - //val dailyQuote = services.getDalyQuote(currentUserState.langage) - - val dailyQuote = DailyQuoteStub.dailyQuote + val coroutineScope = rememberCoroutineScope() + val dailyQuote = Quote(-1,"",0,SrcLanguage.vo,"","","",SrcType.Movie,0) + coroutineScope.launch { + val dailyQuote = services.getDalyQuote(currentUserState.langage) + } + //val dailyQuote = DailyQuoteStub.dailyQuote val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote) val titleSuggestion = stringResource(R.string.TitleHomeSuggestion) @@ -65,6 +71,7 @@ fun AccueilPage( isLoading.value = true delay(500) val newQuotes = services.getSomeQuotes(15, page.intValue) + Log.d("Accueil",newQuotes.toString()) val uniqueQuotes = newQuotes.filterNot { new -> quotes.any { it.id == new.id } } if (uniqueQuotes.isNotEmpty()) { @@ -93,10 +100,24 @@ fun AccueilPage( .background(MaterialTheme.colorScheme.background) ) { LazyColumn(modifier = Modifier.weight(1f), state = state) { - item { - Column(Modifier.clickable { navQuote(dailyQuote.id) }) { + if(dailyQuote.id!=-1) { + item { + Column(Modifier.clickable { navQuote(dailyQuote.id) }) { + Text( + text = titleDalyQuote, + color = MaterialTheme.colorScheme.onBackground, + fontSize = 24.sp, + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + textAlign = TextAlign.Center + ) + QuoteLittle(dailyQuote) + } + + Text( - text = titleDalyQuote, + text = titleSuggestion, color = MaterialTheme.colorScheme.onBackground, fontSize = 24.sp, modifier = Modifier @@ -104,20 +125,8 @@ fun AccueilPage( .padding(16.dp), textAlign = TextAlign.Center ) - QuoteLittle(dailyQuote) } - - Text( - text = titleSuggestion, - color = MaterialTheme.colorScheme.onBackground, - fontSize = 24.sp, - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - textAlign = TextAlign.Center - ) } - items(quotes) { quote -> if (quote.language == currentUserState.langage) { Column(Modifier.clickable { navQuote(quote.id ) }) {