API Accueil marche

ConnectAPI
Kentin BRONGNIART 2 weeks ago
parent 5ba379ea9f
commit 5e99fa71f2

@ -3,7 +3,11 @@ package com.example.what_the_fantasy.data.model
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
data class Quote ( data class Quote (
@SerializedName("id")
val id: Int, val id: Int,
@SerializedName("content")
val content: String, val content: String,
@SerializedName("like") @SerializedName("like")
@ -11,6 +15,8 @@ data class Quote (
@SerializedName("langage") @SerializedName("langage")
val language: SrcLanguage, val language: SrcLanguage,
@SerializedName("character")
val character: String, val character: String,
@SerializedName("titleSource") @SerializedName("titleSource")
@ -18,9 +24,14 @@ data class Quote (
@SerializedName("imagePath") @SerializedName("imagePath")
val imgUrl: String, val imgUrl: String,
@SerializedName("type")
val type: SrcType , val type: SrcType ,
@SerializedName("dateSource") @SerializedName("dateSource")
val date: Int val date: Int,
@SerializedName("isValide")
val isValide : Boolean = true
) )

@ -2,9 +2,50 @@ package com.example.what_the_fantasy.data.model
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import com.example.what_the_fantasy.R import com.example.what_the_fantasy.R
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import java.lang.reflect.Type
enum class SrcType (val value: String) { enum class SrcType (val value: String) {
Movie("movie" ), Movie("movie" ),
VideoGame("videoGame"), VideoGame("videoGame"),
Series("series"), Series("series");
companion object {
fun fromCode(value: Int): SrcType? = SrcType.values().find {
if (value==0){
it.value == "movie"
}
else if (value==1){
it.value == "videoGame"
}
else{
it.value == "series"
}
}
}
}
class SrcTypeAdapter : JsonSerializer<SrcType>, JsonDeserializer<SrcType> {
override fun serialize(
src: SrcType?,
typeOfSrc: Type?,
context: JsonSerializationContext?
): JsonElement = JsonPrimitive(src?.value)
override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?
): SrcType {
val value = json?.asInt
return SrcType.fromCode(value ?: throw JsonParseException("Code null"))
?: throw JsonParseException("Unknown Status code: $value")
}
} }

@ -2,8 +2,10 @@ package com.example.what_the_fantasy.data.retrofit
import com.example.what_the_fantasy.data.model.Image import com.example.what_the_fantasy.data.model.Image
import com.example.what_the_fantasy.data.model.LangAdapter import com.example.what_the_fantasy.data.model.LangAdapter
import com.example.what_the_fantasy.data.model.SrcTypeAdapter
import com.example.what_the_fantasy.data.model.Quote 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.SrcLanguage
import com.example.what_the_fantasy.data.model.SrcType
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
import com.example.what_the_fantasy.data.services.APIReponceList import com.example.what_the_fantasy.data.services.APIReponceList
import com.google.gson.Gson import com.google.gson.Gson
@ -89,6 +91,7 @@ object RetrofitInstance {
private val gson: Gson = GsonBuilder() private val gson: Gson = GsonBuilder()
.registerTypeAdapter(SrcLanguage::class.java, LangAdapter()) .registerTypeAdapter(SrcLanguage::class.java, LangAdapter())
.registerTypeAdapter(SrcType::class.java, SrcTypeAdapter())
.create() .create()
val api: ApiService by lazy { val api: ApiService by lazy {

@ -7,11 +7,11 @@ data class APIReponceList<T> (
val totalCount: Int, val totalCount: Int,
@SerializedName("pageIndex") @SerializedName("pageIndex")
var index: Int, val index: Int,
@SerializedName("countPerPage") @SerializedName("countPerPage")
var count: Int, val count: Int,
@SerializedName("items") @SerializedName("items")
var items: MutableList<T>, val items: MutableList<T>,
) )

@ -139,7 +139,7 @@ fun AppNavigator() {
) )
}, },
navSearch = { navController.navigate(Search(currentUserState.id))}, navSearch = { navController.navigate(Search(currentUserState.id))},
services = servicesStub, services = services,
currentUserVM = currentUserVM, currentUserVM = currentUserVM,
currentUserState = currentUserState, currentUserState = currentUserState,
) )

@ -52,7 +52,7 @@ fun AccueilPage(
val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote) val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote)
val titleSuggestion = stringResource(R.string.TitleHomeSuggestion) val titleSuggestion = stringResource(R.string.TitleHomeSuggestion)
val page = remember { mutableIntStateOf(1) } val page = remember { mutableIntStateOf(0) }
val quotes = remember { mutableStateListOf<Quote>() } val quotes = remember { mutableStateListOf<Quote>() }
val state = rememberLazyListState() val state = rememberLazyListState()
val layoutInfo = remember { derivedStateOf { state.layoutInfo } } val layoutInfo = remember { derivedStateOf { state.layoutInfo } }
@ -61,11 +61,10 @@ fun AccueilPage(
val fullyVisibleItemsInfo = visibleItemsInfo.toMutableList() val fullyVisibleItemsInfo = visibleItemsInfo.toMutableList()
val lastItem = if (fullyVisibleItemsInfo.isNotEmpty()) fullyVisibleItemsInfo.last() else null val lastItem = if (fullyVisibleItemsInfo.isNotEmpty()) fullyVisibleItemsInfo.last() else null
val dailyQuote = DailyQuoteStub.dailyQuote val dailyQuote = remember { mutableStateOf(Quote(-1,"",0,SrcLanguage.vo,"","","",SrcType.Movie,0)) }
//var dailyQuote = remember{ Quote(-1,"",0,SrcLanguage.vo,"","","",SrcType.Movie,0) } LaunchedEffect(true){
//LaunchedEffect(true){ dailyQuote.value=services.getDalyQuote(currentUserState.langage)
// dailyQuote = services.getDalyQuote(currentUserState.langage) }
//}
LaunchedEffect(page.intValue) { LaunchedEffect(page.intValue) {
if (!isLoading.value) { if (!isLoading.value) {
@ -101,9 +100,9 @@ fun AccueilPage(
.background(MaterialTheme.colorScheme.background) .background(MaterialTheme.colorScheme.background)
) { ) {
LazyColumn(modifier = Modifier.weight(1f), state = state) { LazyColumn(modifier = Modifier.weight(1f), state = state) {
if(dailyQuote.id!=-1) { if(dailyQuote.value.id!=-1) {
item { item {
Column(Modifier.clickable { navQuote(dailyQuote.id) }) { Column(Modifier.clickable { navQuote(dailyQuote.value.id) }) {
Text( Text(
text = titleDalyQuote, text = titleDalyQuote,
color = MaterialTheme.colorScheme.onBackground, color = MaterialTheme.colorScheme.onBackground,
@ -113,7 +112,7 @@ fun AccueilPage(
.padding(16.dp), .padding(16.dp),
textAlign = TextAlign.Center textAlign = TextAlign.Center
) )
QuoteLittle(dailyQuote) QuoteLittle(dailyQuote.value)
} }
} }
} }

Loading…
Cancel
Save