detail in progress

Système_de_proximité
Bastien JACQUELIN 2 years ago
parent 5c1ae6f94d
commit f44fe2a940

@ -1,5 +1,8 @@
package fr.iut.cinecool.API package fr.iut.cinecool.API
import android.os.Parcel
import android.os.Parcelable
data class MovieResponse( data class MovieResponse(
val page: Int, val page: Int,
val results: List<Movie>, val results: List<Movie>,
@ -12,4 +15,33 @@ data class Movie(
val title: String, val title: String,
val poster_path: String?, val poster_path: String?,
val overview: String val overview: String
) ) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readString()!!,
parcel.readString(),
parcel.readString()!!
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(id)
parcel.writeString(title)
parcel.writeString(poster_path)
parcel.writeString(overview)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Movie> {
override fun createFromParcel(parcel: Parcel): Movie {
return Movie(parcel)
}
override fun newArray(size: Int): Array<Movie?> {
return arrayOfNulls(size)
}
}
}

@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.bumptech.glide.Glide
import fr.iut.cinecool.API.Movie import fr.iut.cinecool.API.Movie
// import fr.iut.cinecool.databinding.FragmentMovieDetailBinding // import fr.iut.cinecool.databinding.FragmentMovieDetailBinding

@ -1,5 +1,6 @@
package fr.iut.cinecool package fr.iut.cinecool
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import android.view.LayoutInflater import android.view.LayoutInflater
@ -17,6 +18,7 @@ import fr.iut.cinecool.model.Movie
import fr.iut.cinecool.model.Stub import fr.iut.cinecool.model.Stub
class MoviesFragment : Fragment() { class MoviesFragment : Fragment() {
private var _binding: FragmentMoviesBinding? = null private var _binding: FragmentMoviesBinding? = null
private val binding get() = _binding!! private val binding get() = _binding!!
private lateinit var movieAdapter: MovieAdapter private lateinit var movieAdapter: MovieAdapter
@ -29,6 +31,7 @@ class MoviesFragment : Fragment() {
): View? { ): View? {
_binding = FragmentMoviesBinding.inflate(inflater, container, false) _binding = FragmentMoviesBinding.inflate(inflater, container, false)
return binding.root return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -41,19 +44,29 @@ class MoviesFragment : Fragment() {
initRecyclerView() initRecyclerView()
// Observe les changements des données des films populaires // Observe les changements des données des films populaires
movieViewModel.popularMovies.observe(viewLifecycleOwner, { movies -> movieViewModel.popularMovies.observe(viewLifecycleOwner) { movies ->
movieAdapter.updateMovies(movies) movieAdapter.updateMovies(movies)
}) }
// Charge les films populaires // Charge les films populaires
loadPopularMovies() loadPopularMovies()
} }
private fun initRecyclerView() { private fun initRecyclerView() {
binding.recyclerMovie.setHasFixedSize(true) binding.recyclerMovie.setHasFixedSize(true)
binding.recyclerMovie.layoutManager = LinearLayoutManager(context) binding.recyclerMovie.layoutManager = LinearLayoutManager(context)
movieAdapter = MovieAdapter(ArrayList()) movieAdapter = MovieAdapter(ArrayList())
binding.recyclerMovie.adapter = movieAdapter binding.recyclerMovie.adapter = movieAdapter
movieAdapter.onItemClick = {
val fragment = SessionFragment()
val myBundle = Bundle()
myBundle.putParcelable("movie",it)
fragment.arguments=myBundle
findNavController().navigate(R.id.movies_to_sessions)
}
} }
private fun loadPopularMovies() { private fun loadPopularMovies() {

@ -6,7 +6,9 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.TextView
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import fr.iut.cinecool.API.Movie
class SessionFragment : Fragment() { class SessionFragment : Fragment() {
@ -20,6 +22,16 @@ class SessionFragment : Fragment() {
button.setOnClickListener { button.setOnClickListener {
findNavController().navigate(R.id.action_SessionFragment_to_fragment_movies) findNavController().navigate(R.id.action_SessionFragment_to_fragment_movies)
} }
init()
return view return view
} }
private fun init() {
val movie = arguments?.getParcelable<Movie>("movie")
if(movie!=null){
requireView().findViewById<TextView>(R.id.title).text=movie.title
requireView().findViewById<TextView>(R.id.description).text=movie.overview
//requireView().findViewById<TextView>(R.id.afficheFilm).setText()=movie.poster_path
}
}
} }

@ -7,12 +7,11 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import fr.iut.cinecool.R import fr.iut.cinecool.R
import com.bumptech.glide.Glide
import fr.iut.cinecool.API.Movie import fr.iut.cinecool.API.Movie
class MovieAdapter(private var moviesList: List<Movie>) : class MovieAdapter(private var moviesList: List<Movie>) :
RecyclerView.Adapter<MovieAdapter.MovieViewHolder>() { RecyclerView.Adapter<MovieAdapter.MovieViewHolder>() {
var onItemClick : ((Movie)->Unit)?=null
class MovieViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { class MovieViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val imageView = itemView.findViewById<ImageView>(R.id.imageView) val imageView = itemView.findViewById<ImageView>(R.id.imageView)
val MovieName = itemView.findViewById<TextView>(R.id.MovieName) val MovieName = itemView.findViewById<TextView>(R.id.MovieName)
@ -29,17 +28,21 @@ class MovieAdapter(private var moviesList: List<Movie>) :
} }
override fun onBindViewHolder(holder: MovieViewHolder, position: Int) { override fun onBindViewHolder(holder: MovieViewHolder, position: Int) {
val movie = moviesList[position] val movie = moviesList[position]/*
val imageUrl = "https://image.tmdb.org/t/p/w500${movie.poster_path}" val imageUrl = "https://image.tmdb.org/t/p/w500${movie.poster_path}"
Glide.with(holder.itemView.context) Glide.with(holder.itemView.context)
.load(imageUrl) .load(imageUrl)
.placeholder(R.drawable.imitation_game) .placeholder(R.drawable.imitation_game)
.into(holder.imageView) .into(holder.imageView)*/
holder.MovieName.text = movie.title holder.MovieName.text = movie.title
// Pour cet exemple, je mets l'overview en tant qu'OtherInformations, vous pouvez le personnaliser selon vos besoins
holder.OtherInformations.text = movie.overview holder.OtherInformations.text = movie.overview
holder.itemView.setOnClickListener {
onItemClick?.invoke(movie)
}
// Pour cet exemple, je mets l'overview en tant qu'OtherInformations, vous pouvez le personnaliser selon vos besoins
} }
// Ajoutez cette méthode pour mettre à jour la liste des films // Ajoutez cette méthode pour mettre à jour la liste des films

@ -1,6 +1,5 @@
package fr.iut.cinecool.model package fr.iut.cinecool.model
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import com.google.gson.annotations.SerializedName
data class Movie(val id:Int, val name:String, var mark:Int, val realisator:String, var duration: Double, val icon:Int) data class Movie(val id:Int, val name:String, var mark:Int, val realisator:String, var duration: Double, val icon:Int)

@ -6,14 +6,56 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".SessionFragment"> tools:context=".SessionFragment">
<Button <ImageButton
android:id="@+id/returnButton" android:id="@+id/returnButton"
android:layout_width="wrap_content" android:layout_width="60dp"
android:layout_height="wrap_content" android:layout_height="55dp"
android:text="Button Sessions" android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginStart="10dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/back_arrow" />
<TextView
android:id="@+id/title"
android:layout_width="220dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:layout_marginTop="80dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/logo"
android:layout_width="65dp"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/cinema"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:scaleType="fitCenter"
/>
<ImageView
android:id="@+id/afficheFilm"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title"
app:srcCompat="@drawable/imitation_game" />
<TextView
android:id="@+id/description"
android:layout_width="380dp"
android:layout_height="100dp"
android:layout_marginTop="25dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/afficheFilm" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save