parent
1fdca22aa4
commit
9840677f9e
@ -1,55 +0,0 @@
|
|||||||
package fr.iut.cinecool
|
|
||||||
|
|
||||||
class ApiClient {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
/*private const val BASE_URL = "https://api.themoviedb.org/3/"
|
|
||||||
|
|
||||||
fun create(): ApiService {
|
|
||||||
|
|
||||||
val gson = GsonBuilder()
|
|
||||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
|
||||||
.create()
|
|
||||||
|
|
||||||
val logger = HttpLoggingInterceptor()
|
|
||||||
logger.level = HttpLoggingInterceptor.Level.BASIC
|
|
||||||
|
|
||||||
val client = OkHttpClient.Builder()
|
|
||||||
.addInterceptor(logger)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val retrofit = Retrofit.Builder()
|
|
||||||
.baseUrl(BASE_URL)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
|
||||||
.client(client)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
return retrofit.create(ApiService::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
val retrofit = Retrofit.Builder()
|
|
||||||
.baseUrl("https://api.themoviedb.org/3/")
|
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val movieApiService = retrofit.create(ApiService::class.java)
|
|
||||||
|
|
||||||
val apiKey = "a97243d7813d31446f6c43284e6854d5"
|
|
||||||
val call = movieApiService.getPopularMovies(apiKey)
|
|
||||||
|
|
||||||
|
|
||||||
call.enqueue(object : Callback<MovieResponse> {
|
|
||||||
override fun onResponse(call: Call<MovieResponse>, response: Response<MovieResponse>) {
|
|
||||||
// Code à exécuter lorsque la réponse est reçue
|
|
||||||
val movies = response.body()?.results
|
|
||||||
// Traitez les films renvoyés ici
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(call: Call<MovieResponse>, t: Throwable) {
|
|
||||||
// Code à exécuter en cas d'échec de la requête
|
|
||||||
}
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package fr.iut.cinecool
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
|
|
||||||
class DetailActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.vu_detail)
|
|
||||||
|
|
||||||
// Récupérer l'identifiant du film depuis les extras de l'intent
|
|
||||||
val movieId = intent.getIntExtra("movieId", -1)
|
|
||||||
|
|
||||||
// Appeler la méthode pour charger les détails du film
|
|
||||||
// loadMovieDetails(movieId)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*private fun loadMovieDetails(movieId: Int) {
|
|
||||||
val apiClient = TheMovieDbApiClient(getString(R.string.tmdb_api_key))
|
|
||||||
apiClient.getMovieDetails(movieId, object : ITheMovieDbApiCallback<MovieAPI> {
|
|
||||||
override fun onSuccess(result: MovieAPI) {
|
|
||||||
// Afficher les détails du film dans la vue
|
|
||||||
titreFilm.text = result.title
|
|
||||||
description.text = result.overview
|
|
||||||
Picasso.get().load("https://image.tmdb.org/t/p/w500/${result.posterPath}").into(afficheFilm)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(error: Throwable) {
|
|
||||||
// Gérer l'erreur de récupération des détails du film
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
@ -1,75 +1,53 @@
|
|||||||
package fr.iut.cinecool
|
package fr.iut.cinecool
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.fragment.app.Fragment
|
import com.bumptech.glide.Glide
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import fr.iut.cinecool.API.Movie
|
||||||
import kotlinx.coroutines.Dispatchers
|
// import fr.iut.cinecool.databinding.FragmentMovieDetailBinding
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class MovieDetailFragment : Fragment() {
|
class MovieDetailFragment : Fragment() {
|
||||||
/*
|
/*private var _binding: FragmentDetailMovieBinding? = null
|
||||||
private lateinit var binding: FragmentMovieDetailBinding
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?, savedInstanceState: Bundle?): View
|
override fun onCreateView(
|
||||||
{
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
binding = FragmentMovieDetailBinding.inflate(inflater, container, false)
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
_binding = FragmentDetailMovieBinding.inflate(inflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?)
|
|
||||||
{
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val movieId = arguments?.getInt(ARG_MOVIE_ID)
|
// Récupérez le film passé en argument
|
||||||
|
val movie: Movie? = arguments?.getParcelable("movie")
|
||||||
|
|
||||||
|
// Mettez à jour les vues avec les données du film
|
||||||
|
if (movie != null) {
|
||||||
|
binding.titreFilm.text = movie.title
|
||||||
|
binding.description.text = movie.overview
|
||||||
|
|
||||||
// Appel de l'API pour récupérer les détails du film
|
val imageUrl = "https://image.tmdb.org/t/p/w500${movie.poster_path}"
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
Glide.with(binding.afficheFilm.context)
|
||||||
val response = movieId?.let { MovieApiService().getMovieDetails(it) }
|
.load(imageUrl)
|
||||||
withContext(Dispatchers.Main)
|
.placeholder(R.drawable.imitation_game)
|
||||||
{
|
.into(binding.afficheFilm)
|
||||||
if (response != null) {
|
|
||||||
if (response.isSuccessful)
|
|
||||||
{
|
|
||||||
val movie = response.body()
|
|
||||||
if (movie != null)
|
|
||||||
{
|
|
||||||
// Affichage des détails du film dans l'interface utilisateur
|
|
||||||
binding.titreFilm.text = movie.title
|
|
||||||
binding.description.text = movie.overview
|
|
||||||
binding.afficheFilm.load("https://image.tmdb.org/t/p/w500${movie.posterPath}") // Utilisation de la librairie Coil pour charger l'image
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
Toast.makeText(
|
|
||||||
requireContext(),
|
|
||||||
getString(R.string.error_loading_movie),
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Ajout d'un écouteur de clic pour le bouton de retour
|
|
||||||
|
// Gérer le clic sur le bouton de retour
|
||||||
binding.backButton.setOnClickListener {
|
binding.backButton.setOnClickListener {
|
||||||
requireActivity().onBackPressed()
|
findNavController().popBackStack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
override fun onDestroyView() {
|
||||||
private const val ARG_MOVIE_ID = "movie_id"
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
fun newInstance(movieId: Int): MovieDetailFragment {
|
|
||||||
val args = Bundle().apply {
|
|
||||||
putInt(ARG_MOVIE_ID, movieId)
|
|
||||||
}
|
|
||||||
return MovieDetailFragment().apply {
|
|
||||||
arguments = args
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in new issue