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
data class Quote (
@SerializedName("id")
val id: Int,
@SerializedName("content")
val content: String,
@SerializedName("like")
@ -11,6 +15,8 @@ data class Quote (
@SerializedName("langage")
val language: SrcLanguage,
@SerializedName("character")
val character: String,
@SerializedName("titleSource")
@ -18,9 +24,14 @@ data class Quote (
@SerializedName("imagePath")
val imgUrl: String,
@SerializedName("type")
val type: SrcType ,
@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 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) {
Movie("movie" ),
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.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.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.services.APIReponceList
import com.google.gson.Gson
@ -89,6 +91,7 @@ object RetrofitInstance {
private val gson: Gson = GsonBuilder()
.registerTypeAdapter(SrcLanguage::class.java, LangAdapter())
.registerTypeAdapter(SrcType::class.java, SrcTypeAdapter())
.create()
val api: ApiService by lazy {

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

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

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

Loading…
Cancel
Save