|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package com.example.what_the_fantasy.data.services
|
|
|
|
|
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
|
import com.example.what_the_fantasy.data.local.ImageStub.allImages
|
|
|
|
|
import com.example.what_the_fantasy.data.model.Comment
|
|
|
|
|
import com.example.what_the_fantasy.data.model.Favorite
|
|
|
|
|
import com.example.what_the_fantasy.data.model.Quote
|
|
|
|
@ -8,6 +11,8 @@ 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.retrofit.RetrofitInstance
|
|
|
|
|
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
|
|
|
|
|
import java.time.LocalDate
|
|
|
|
|
import java.util.Date
|
|
|
|
|
|
|
|
|
|
//import com.example.what_the_fantasy.data.model.Comment
|
|
|
|
|
//import com.example.what_the_fantasy.data.model.Favorite
|
|
|
|
@ -124,12 +129,62 @@ class ServicesAPI : IServices {
|
|
|
|
|
TODO()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun EditImage(index: Int): String {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun EditImage(index: Int, currentUserViewModel : CurrentUserViewModel): String {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
val responseUser = RetrofitInstance.api.getUserById(index)
|
|
|
|
|
|
|
|
|
|
val updatedUser = User(
|
|
|
|
|
id = index,
|
|
|
|
|
username = responseUser.username,
|
|
|
|
|
email = responseUser.email,// Nouvel email d'utilisateur
|
|
|
|
|
password = responseUser.password,
|
|
|
|
|
imgUrl = randomImage(),
|
|
|
|
|
langage = responseUser.langage,
|
|
|
|
|
date = responseUser.date
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val response = RetrofitInstance.api.updateUsername(index, updatedUser)
|
|
|
|
|
|
|
|
|
|
if (response.isSuccessful) {
|
|
|
|
|
currentUserViewModel.setUser(updatedUser)
|
|
|
|
|
return updatedUser.imgUrl
|
|
|
|
|
} else {
|
|
|
|
|
return responseUser.imgUrl
|
|
|
|
|
}
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
return ""
|
|
|
|
|
Log.d("EditEmail", "Exception occurred: ${e.message}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun ChangeLangage(index: Int): SrcLanguage {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override suspend fun ChangeLangage(index: Int, currentUserViewModel : CurrentUserViewModel): SrcLanguage {
|
|
|
|
|
val responseUser = RetrofitInstance.api.getUserById(index)
|
|
|
|
|
var langage : SrcLanguage
|
|
|
|
|
|
|
|
|
|
if(responseUser.langage == SrcLanguage.vf){
|
|
|
|
|
langage = SrcLanguage.vo
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
langage = SrcLanguage.vf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val updatedUser = User(
|
|
|
|
|
id = index,
|
|
|
|
|
username = responseUser.username,
|
|
|
|
|
email = responseUser.email,
|
|
|
|
|
password = responseUser.password,
|
|
|
|
|
imgUrl = responseUser.imgUrl,
|
|
|
|
|
langage = langage,
|
|
|
|
|
date = responseUser.date
|
|
|
|
|
)
|
|
|
|
|
RetrofitInstance.api.updateUsername(index, updatedUser)
|
|
|
|
|
currentUserViewModel.setUser(updatedUser)
|
|
|
|
|
return langage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun isUsernameExist(username: String): Boolean {
|
|
|
|
@ -192,8 +247,22 @@ class ServicesAPI : IServices {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.O)
|
|
|
|
|
override suspend fun getDalyQuote(langage : SrcLanguage): Quote {
|
|
|
|
|
val today = LocalDate.now()
|
|
|
|
|
return RetrofitInstance.api.getDailyQuote(today.year, today.monthValue, today.dayOfMonth, langage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun search(type: String, search: String, indexCount: Int): List<Quote> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
suspend fun randomImage() : String{
|
|
|
|
|
val imagesList = RetrofitInstance.api.getAllImages(0, 300)
|
|
|
|
|
val sizeList = imagesList.size
|
|
|
|
|
return RetrofitInstance.api.getImageById((0..sizeList).random()).url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|