parent
76130b9358
commit
797ce00665
@ -1,48 +1,37 @@
|
||||
package fr.iut.pm.movieapplication.api.dtos
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import fr.iut.pm.movieapplication.model.Genre
|
||||
|
||||
class MovieDetailsDTO(
|
||||
|
||||
adult : Boolean?,
|
||||
backdropPath : String?,
|
||||
val budget : Int,
|
||||
val genres : List<GenreDTO>,
|
||||
val homepage : String?,
|
||||
id : Int,
|
||||
originalLanguage : String,
|
||||
originalTitle : String,
|
||||
overview : String?,
|
||||
popularity : Double,
|
||||
posterPath : String?,
|
||||
data class MovieDetailsDTO(
|
||||
|
||||
val adult: Boolean,
|
||||
@Json(name = "backdrop_path")
|
||||
val backdropPath: String?,
|
||||
val budget: Int,
|
||||
val genres: List<GenreDTO>,
|
||||
val homepage: String?,
|
||||
val id: Int,
|
||||
@Json(name = "original_language")
|
||||
val originalLanguage: String,
|
||||
@Json(name = "original_title")
|
||||
val originalTitle: String,
|
||||
val overview: String?,
|
||||
val popularity: Double,
|
||||
@Json(name = "poster_path")
|
||||
val posterPath: String?,
|
||||
//prod companies
|
||||
//prod countries
|
||||
releaseDate : String?,
|
||||
val revenue : Int,
|
||||
@Json(name = "release_date")
|
||||
val releaseDate: String,
|
||||
val revenue: Int,
|
||||
//spoken language
|
||||
val status : String,
|
||||
title : String,
|
||||
voteAverage : Double,
|
||||
voteCount : Int
|
||||
|
||||
|
||||
|
||||
) : MediaResultDTO(
|
||||
adult = adult,
|
||||
backdropPath = backdropPath,
|
||||
id = id,
|
||||
originalLanguage = originalLanguage,
|
||||
originalTitle = originalTitle,
|
||||
overview = overview,
|
||||
popularity = popularity,
|
||||
posterPath = posterPath,
|
||||
releaseDate = releaseDate,
|
||||
title = title,
|
||||
voteAverage = voteAverage,
|
||||
voteCount = voteCount,
|
||||
) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
val status: String,
|
||||
val title: String,
|
||||
@Json(name = "vote_average")
|
||||
val voteAverage: Double,
|
||||
@Json(name = "vote_count")
|
||||
val voteCount: Int
|
||||
|
||||
)
|
||||
{}
|
@ -1,50 +1,34 @@
|
||||
package fr.iut.pm.movieapplication.model.media.movie
|
||||
|
||||
import fr.iut.pm.movieapplication.model.ProductionCompany
|
||||
import fr.iut.pm.movieapplication.model.ProductionCountry
|
||||
|
||||
|
||||
data class MovieDetails(
|
||||
|
||||
override val posterPath: String,
|
||||
override val adult: Boolean,
|
||||
override val overview: String,
|
||||
override val releaseDate: String,
|
||||
// override val genreIds : List<Int>,
|
||||
override val id: Int,
|
||||
override val originalTitle: String,
|
||||
override val originalLanguage: String,
|
||||
override val title: String?,
|
||||
override val backdropPath: String?,
|
||||
override val popularity: Double,
|
||||
override val voteCount: Int,
|
||||
// override val video: Boolean?,
|
||||
override val voteAverage: Double,
|
||||
val mediaType: String,
|
||||
|
||||
val budget: Int?,
|
||||
val homePage: String?,
|
||||
val productionCompanies: Array<ProductionCompany>?,
|
||||
val productionCountries: Array<ProductionCountry>?,
|
||||
val revenue: Int?,
|
||||
val runtime: Int?,
|
||||
val status: String?,
|
||||
val tagLine: String?
|
||||
|
||||
) : Movie(posterPath,
|
||||
adult,
|
||||
overview,
|
||||
releaseDate,
|
||||
// genreIds,
|
||||
id,
|
||||
originalTitle,
|
||||
originalLanguage,
|
||||
title,
|
||||
backdropPath,
|
||||
popularity,
|
||||
voteCount,
|
||||
// video,
|
||||
voteAverage) {
|
||||
import fr.iut.pm.movieapplication.model.Genre
|
||||
|
||||
|
||||
class MovieDetails(
|
||||
|
||||
adult : Boolean?,
|
||||
backdropPath : String?,
|
||||
val budget : Int,
|
||||
val genres : List<Genre>,
|
||||
val homepage : String?,
|
||||
id : Int,
|
||||
originalLanguage : String,
|
||||
originalTitle : String,
|
||||
overview : String?,
|
||||
popularity : Double,
|
||||
posterPath : String?,
|
||||
//prod companies
|
||||
//prod countries
|
||||
releaseDate : String?,
|
||||
val revenue : Int,
|
||||
//spoken language
|
||||
val status : String,
|
||||
title : String,
|
||||
voteAverage : Double,
|
||||
voteCount : Int
|
||||
|
||||
) : Movie(posterPath, adult, overview, releaseDate, id, originalTitle, originalLanguage,
|
||||
title, backdropPath, popularity, voteCount, voteAverage)
|
||||
{
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package fr.iut.pm.movieapplication.ui.dialog
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.net.toUri
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import coil.load
|
||||
import fr.iut.pm.movieapplication.R
|
||||
import fr.iut.pm.movieapplication.databinding.MovieDialogBinding
|
||||
import fr.iut.pm.movieapplication.ui.viewmodel.MoviesDialogVM
|
||||
import fr.iut.pm.movieapplication.ui.viewmodel.MoviesDialogVMFactory
|
||||
import fr.iut.pm.movieapplication.utils.Constants
|
||||
|
||||
class MovieDialog : DialogFragment() {
|
||||
|
||||
val moviesDialogVM by viewModels<MoviesDialogVM> { MoviesDialogVMFactory(arguments?.getInt("movieId") ?: 0) }
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val binding = MovieDialogBinding.inflate(inflater)
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
binding.closeItem.setOnClickListener { dismiss() }
|
||||
moviesDialogVM.getMovieDetailLiveData().observe(viewLifecycleOwner) {
|
||||
binding.movieDetails = it
|
||||
binding.detailsImage.load(it.posterPath?.let { it ->
|
||||
(Constants.IMG_URL + it).toUri().buildUpon().scheme("https").build()
|
||||
})
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package fr.iut.pm.movieapplication.ui.viewmodel
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import fr.iut.pm.movieapplication.model.media.movie.MovieDetails
|
||||
import fr.iut.pm.movieapplication.repository.MovieRepository
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MoviesDialogVM(private val movieId : Int) : ViewModel() {
|
||||
|
||||
private val repository = MovieRepository()
|
||||
|
||||
private var _movieDetailsLiveData : MutableLiveData<MovieDetails> = MutableLiveData()
|
||||
fun getMovieDetailLiveData() : LiveData<MovieDetails> = _movieDetailsLiveData
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
if(movieId != 0) _movieDetailsLiveData.postValue(repository.getMovieDetails(movieId))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MoviesDialogVMFactory(private val movieId : Int) : ViewModelProvider.Factory
|
||||
{
|
||||
override fun<T:ViewModel>create(modelClass:Class<T>) : T
|
||||
{
|
||||
return MoviesDialogVM(movieId) as T
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package fr.iut.pm.movieapplication.utils
|
||||
|
||||
import fr.iut.pm.movieapplication.api.dtos.MovieDTO
|
||||
import fr.iut.pm.movieapplication.api.dtos.MovieDetailsDTO
|
||||
import fr.iut.pm.movieapplication.model.media.movie.Movie
|
||||
import fr.iut.pm.movieapplication.model.media.movie.MovieDetails
|
||||
|
||||
object MovieMapper {
|
||||
|
||||
fun mapToMovie(movieDTO : MovieDTO) : Movie {
|
||||
return Movie(
|
||||
posterPath = movieDTO.posterPath,
|
||||
adult = movieDTO.adult,
|
||||
overview = movieDTO.overview,
|
||||
releaseDate = movieDTO.releaseDate,
|
||||
id = movieDTO.id,
|
||||
originalTitle = movieDTO.originalTitle,
|
||||
originalLanguage = movieDTO.originalLanguage,
|
||||
title = movieDTO.title,
|
||||
backdropPath = movieDTO.backdropPath,
|
||||
popularity = movieDTO.popularity,
|
||||
voteCount = movieDTO.voteCount,
|
||||
voteAverage = movieDTO.voteAverage
|
||||
)
|
||||
}
|
||||
|
||||
fun mapToMovieDetails(movieDetailsDTO: MovieDetailsDTO ) : MovieDetails {
|
||||
return MovieDetails(
|
||||
posterPath = movieDetailsDTO.posterPath,
|
||||
adult = movieDetailsDTO.adult!!,
|
||||
overview = movieDetailsDTO.overview ?: "",
|
||||
releaseDate = movieDetailsDTO.releaseDate ?: "",
|
||||
id = movieDetailsDTO.id,
|
||||
originalTitle = movieDetailsDTO.originalTitle,
|
||||
originalLanguage = movieDetailsDTO.originalLanguage,
|
||||
title = movieDetailsDTO.title,
|
||||
backdropPath = movieDetailsDTO.backdropPath,
|
||||
popularity = movieDetailsDTO.popularity,
|
||||
voteCount = movieDetailsDTO.voteCount,
|
||||
voteAverage = movieDetailsDTO.voteAverage,
|
||||
budget = movieDetailsDTO.budget,
|
||||
genres = movieDetailsDTO.genres.map { MediaResultMapper.mapGenreDTOToGenre(it) },
|
||||
homepage = movieDetailsDTO.homepage,
|
||||
revenue = movieDetailsDTO.revenue,
|
||||
status = movieDetailsDTO.status
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
</vector>
|
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<variable
|
||||
name="movieDetails"
|
||||
type="fr.iut.pm.movieapplication.model.media.movie.MovieDetails" />
|
||||
|
||||
</data>
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/default_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/close_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
|
||||
android:src="@drawable/ic_close"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:contentDescription="Close" />
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/details_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:autoText="true"
|
||||
android:hint="The title of the movie"
|
||||
android:text="@{movieDetails.title}"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="#000"
|
||||
app:layout_constraintEnd_toStartOf="@+id/close_item"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@{movieDetails.overview}"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/details_image"
|
||||
app:layout_constraintTop_toBottomOf="@+id/details_image" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="Enregistrer"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Voir détails"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/button"
|
||||
app:layout_constraintStart_toStartOf="@+id/button" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
Loading…
Reference in new issue