Compare commits
9 Commits
Système_de
...
master
Author | SHA1 | Date |
---|---|---|
|
4717c77101 | 2 years ago |
|
fc2fdd3195 | 2 years ago |
|
f26bafe1b5 | 2 years ago |
|
fe0d730521 | 2 years ago |
|
dc075d8eb2 | 2 years ago |
![]() |
1864cc1ede | 2 years ago |
![]() |
15ee0a23e9 | 2 years ago |
![]() |
32d629f879 | 2 years ago |
![]() |
3db51c3cb0 | 2 years ago |
@ -1,47 +0,0 @@
|
|||||||
package fr.iut.cinecool.API
|
|
||||||
|
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.Parcelable
|
|
||||||
|
|
||||||
data class MovieResponse(
|
|
||||||
val page: Int,
|
|
||||||
val results: List<Movie>,
|
|
||||||
val total_pages: Int,
|
|
||||||
val total_results: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class Movie(
|
|
||||||
val id: Int,
|
|
||||||
val title: String,
|
|
||||||
val poster_path: 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,25 @@
|
|||||||
|
package fr.iut.cinecool.API.OSM
|
||||||
|
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
|
||||||
|
object ApiClientOSM {
|
||||||
|
private const val OSM_BASE_URL = "https://nominatim.openstreetmap.org/"
|
||||||
|
private const val ORS_BASE_URL = "https://api.openrouteservice.org/"
|
||||||
|
|
||||||
|
fun getOSMClient(): ApiService {
|
||||||
|
return Retrofit.Builder()
|
||||||
|
.baseUrl(OSM_BASE_URL)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
.create(ApiService::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getORSClient(): ApiService {
|
||||||
|
return Retrofit.Builder()
|
||||||
|
.baseUrl(ORS_BASE_URL)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
.create(ApiService::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package fr.iut.cinecool.API.OSM
|
||||||
|
|
||||||
|
import fr.iut.cinecool.model.CinemaResult
|
||||||
|
import fr.iut.cinecool.model.RouteResult
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
interface ApiService {
|
||||||
|
@GET("search")
|
||||||
|
fun searchCinemas(
|
||||||
|
@Query("q") query: String,
|
||||||
|
@Query("format") format: String = "json"
|
||||||
|
): Call<List<CinemaResult>>
|
||||||
|
|
||||||
|
@GET("v2/directions/driving-car")
|
||||||
|
fun getRoute(
|
||||||
|
@Query("api_key") apiKey: String,
|
||||||
|
@Query("start") start: String,
|
||||||
|
@Query("end") end: String
|
||||||
|
): Call<RouteResult>
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package fr.iut.cinecool.API.OSM
|
||||||
|
import fr.iut.cinecool.model.CinemaResult
|
||||||
|
import fr.iut.cinecool.model.RouteResult
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.Callback
|
||||||
|
import retrofit2.Response
|
||||||
|
|
||||||
|
class MethodApiOSM {
|
||||||
|
|
||||||
|
fun searchCinemas(latitude: Double, longitude: Double) {
|
||||||
|
val apiService = ApiClientOSM.getOSMClient()
|
||||||
|
val call = apiService.searchCinemas("cinema near $latitude,$longitude")
|
||||||
|
call.enqueue(object : Callback<List<CinemaResult>> {
|
||||||
|
override fun onResponse(call: Call<List<CinemaResult>>, response: Response<List<CinemaResult>>) {
|
||||||
|
val cinemas = response.body()
|
||||||
|
// Trouvez le cinéma le plus proche ou affichez la liste des cinémas
|
||||||
|
// Puis, utilisez la fonction getRoute() pour obtenir l'itinéraire
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<List<CinemaResult>>, t: Throwable) {
|
||||||
|
// Gérer l'échec
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRoute(startLat: Double, startLon: Double, endLat: Double, endLon: Double) {
|
||||||
|
val apiKey = "5b3ce3597851110001cf6248953315121da3401d85fa50fce9c0991e"
|
||||||
|
val apiService = ApiClientOSM.getORSClient()
|
||||||
|
val call = apiService.getRoute(apiKey, "$startLat,$startLon", "$endLat,$endLon")
|
||||||
|
call.enqueue(object : Callback<RouteResult> {
|
||||||
|
override fun onResponse(call: Call<RouteResult>, response: Response<RouteResult>) {
|
||||||
|
val routeResult = response.body()
|
||||||
|
val steps = routeResult?.routes?.get(0)?.segments?.get(0)?.steps
|
||||||
|
if (steps != null) {
|
||||||
|
// Utilisez les instructions de l'itinéraire pour guider l'utilisateur
|
||||||
|
} else {
|
||||||
|
// Gérer le cas où il n'y a pas d'itinéraire disponible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<RouteResult>, t: Throwable) {
|
||||||
|
// Gérer l'échec
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package fr.iut.cinecool.API
|
package fr.iut.cinecool.API.THMDB
|
||||||
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
|
||||||
object ApiClient {
|
object ApiClientTHMDB {
|
||||||
private const val BASE_URL = "https://api.themoviedb.org/3/"
|
private const val BASE_URL = "https://api.themoviedb.org/3/"
|
||||||
|
|
||||||
private val retrofit: Retrofit = Retrofit.Builder()
|
private val retrofit: Retrofit = Retrofit.Builder()
|
@ -1,4 +1,4 @@
|
|||||||
package fr.iut.cinecool.API
|
package fr.iut.cinecool.API.THMDB
|
||||||
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
@ -1,7 +1,7 @@
|
|||||||
package fr.iut.cinecool.API
|
package fr.iut.cinecool.API.THMDB
|
||||||
|
|
||||||
class Repository {
|
class MethodApiTHMDB {
|
||||||
private val apiService = ApiClient.apiService
|
private val apiService = ApiClientTHMDB.apiService
|
||||||
|
|
||||||
suspend fun getPopularMovies(apiKey: String, page: Int): MovieResponse {
|
suspend fun getPopularMovies(apiKey: String, page: Int): MovieResponse {
|
||||||
return apiService.getPopularMovies(apiKey, page)
|
return apiService.getPopularMovies(apiKey, page)
|
@ -1,18 +0,0 @@
|
|||||||
package fr.iut.cinecool
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.navigation.NavController
|
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
|
||||||
|
|
||||||
class CinemaActivity : AppCompatActivity() {
|
|
||||||
private lateinit var navController: NavController
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.activity_cinema)
|
|
||||||
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment
|
|
||||||
navController = navHostFragment.navController
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package fr.iut.cinecool
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
|
|
||||||
|
|
||||||
class CinemaFragment : Fragment() {
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?
|
|
||||||
): View? {
|
|
||||||
// Inflate the layout for this fragment
|
|
||||||
return inflater.inflate(R.layout.fragment_cinema, container, false)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +1,43 @@
|
|||||||
package fr.iut.cinecool
|
package fr.iut.cinecool
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.ImageView
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
|
import android.Manifest
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
private lateinit var navController: NavController
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_master)
|
||||||
val loginButton = findViewById<ImageView>(R.id.loginButton)
|
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment
|
||||||
loginButton.setOnClickListener(){
|
navController = navHostFragment.navController
|
||||||
login()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
private val REQUEST_LOCATION_PERMISSION = 1
|
||||||
|
|
||||||
/*ActivityCompat.requestPermissions(this,
|
private fun checkLocationPermission() {
|
||||||
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION,1)
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
)*/
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), REQUEST_LOCATION_PERMISSION)
|
||||||
|
} else {
|
||||||
|
// Appeler searchCinemas() avec les coordonnées de l'utilisateur
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fun login(){
|
|
||||||
val name = findViewById<EditText>(R.id.name).text
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
if (name.isNotEmpty()){
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
val intent = Intent(applicationContext,CinemaActivity::class.java)
|
if (requestCode == REQUEST_LOCATION_PERMISSION) {
|
||||||
startActivity(intent)
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
System.out.println(name)
|
// Appeler searchCinemas() avec les coordonnées de l'utilisateur
|
||||||
|
} else {
|
||||||
|
// Gérer le cas où la permission est refusée
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,52 +0,0 @@
|
|||||||
package fr.iut.cinecool
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.navigation.fragment.findNavController
|
|
||||||
import fr.iut.cinecool.API.Movie
|
|
||||||
// import fr.iut.cinecool.databinding.FragmentMovieDetailBinding
|
|
||||||
|
|
||||||
class MovieDetailFragment : Fragment() {
|
|
||||||
/*private var _binding: FragmentDetailMovieBinding? = null
|
|
||||||
private val binding get() = _binding!!
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?
|
|
||||||
): View? {
|
|
||||||
_binding = FragmentDetailMovieBinding.inflate(inflater, container, false)
|
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
val imageUrl = "https://image.tmdb.org/t/p/w500${movie.poster_path}"
|
|
||||||
Glide.with(binding.afficheFilm.context)
|
|
||||||
.load(imageUrl)
|
|
||||||
.placeholder(R.drawable.imitation_game)
|
|
||||||
.into(binding.afficheFilm)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gérer le clic sur le bouton de retour
|
|
||||||
binding.backButton.setOnClickListener {
|
|
||||||
findNavController().popBackStack()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
super.onDestroyView()
|
|
||||||
_binding = null
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
|||||||
|
package fr.iut.cinecool.fragments
|
||||||
|
|
||||||
|
import android.content.Context.LOCATION_SERVICE
|
||||||
|
import android.location.LocationManager
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.ImageView
|
||||||
|
import androidx.core.content.ContextCompat.getSystemService
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import fr.iut.cinecool.R
|
||||||
|
import fr.iut.cinecool.databinding.FragmentLoginBinding
|
||||||
|
import fr.iut.cinecool.databinding.FragmentMoviesBinding
|
||||||
|
|
||||||
|
class LoginFragment : Fragment() {
|
||||||
|
private var locationManager : LocationManager? = null
|
||||||
|
private var _binding: FragmentLoginBinding? = null
|
||||||
|
private val binding get() = _binding!!
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
_binding = FragmentLoginBinding.inflate(inflater, container, false)
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
//locationManager = this.context?.let { getSystemService(it,LOCATION_SERVICE) } as LocationManager?
|
||||||
|
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
val loginButton = view.findViewById<ImageView>(R.id.loginButton)
|
||||||
|
loginButton.setOnClickListener(){
|
||||||
|
login()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun login(){
|
||||||
|
val name = view?.findViewById<EditText>(R.id.name)?.text
|
||||||
|
if (name != null) {
|
||||||
|
findNavController().navigate(R.id.login_to_movies)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,23 @@
|
|||||||
package fr.iut.cinecool.model
|
package fr.iut.cinecool.model
|
||||||
|
|
||||||
data class Cinema (val id:Int, val latitude:Int, val longitude:Int, val city:String, val name:String, /*var movies:ArrayList<Movie>*/)
|
data class CinemaResult(
|
||||||
|
val lat: Double,
|
||||||
|
val lon: Double,
|
||||||
|
val display_name: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class RouteResult(
|
||||||
|
val routes: List<Route>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Route(
|
||||||
|
val segments: List<Segment>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Segment(
|
||||||
|
val steps: List<Step>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Step(
|
||||||
|
val instruction: String
|
||||||
|
)
|
||||||
|
@ -1,5 +1,47 @@
|
|||||||
package fr.iut.cinecool.model
|
package fr.iut.cinecool.API.THMDB
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.os.Parcel
|
||||||
data class Movie(val id:Int, val name:String, var mark:Int, val realisator:String, var duration: Double, val icon:Int)
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
data class MovieResponse(
|
||||||
|
val page: Int,
|
||||||
|
val results: List<Movie>,
|
||||||
|
val total_pages: Int,
|
||||||
|
val total_results: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Movie(
|
||||||
|
val id: Int,
|
||||||
|
val title: String,
|
||||||
|
val poster_path: 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package fr.iut.cinecool.model
|
|
||||||
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
data class Session(val id:Int, val date: Date, val beginHour:Int, val endingHour:Int, val room:String)
|
|
@ -1,16 +0,0 @@
|
|||||||
package fr.iut.cinecool.model
|
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import fr.iut.cinecool.R
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
class Stub( var sessions:ArrayList<Session> = ArrayList(),var movies:ArrayList<Movie> = ArrayList(),var cinemas:ArrayList<Cinema> = ArrayList()) {
|
|
||||||
fun loading(){
|
|
||||||
val date = Date(2023,3,12)
|
|
||||||
sessions.addAll(listOf(Session(0,date,14,16,"2A"),Session(1,date,4,6,"5B")))
|
|
||||||
movies.add(Movie(1,"trop bg",2,"Pas moi",2.0, R.drawable.no_pictures))
|
|
||||||
movies.add(Movie(0,"Imitation Game",4,"Moi",3.0,R.drawable.imitation_game))
|
|
||||||
cinemas.add(Cinema(0,12367,67894,"clf","CineJaude"))
|
|
||||||
cinemas.add(Cinema(1,87634,43567,"Aubière","CGR Le Paris"))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package fr.iut.cinecool.model
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
|
|
||||||
|
|
||||||
class cineViewModel : ViewModel() {
|
|
||||||
private val _cine = MutableLiveData<fr.iut.cinecool.API.Movie>()
|
|
||||||
val cine: LiveData<fr.iut.cinecool.API.Movie> = _cine
|
|
||||||
|
|
||||||
fun setCine(cine: fr.iut.cinecool.API.Movie) {
|
|
||||||
_cine.value = cine
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,17 @@
|
|||||||
|
package fr.iut.cinecool.viewModel
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import fr.iut.cinecool.API.THMDB.Movie
|
||||||
|
|
||||||
|
|
||||||
|
class cineViewModel : ViewModel() {
|
||||||
|
private val _cine = MutableLiveData<Movie>()
|
||||||
|
val cine: LiveData<Movie> = _cine
|
||||||
|
|
||||||
|
fun setCine(cine: Movie) {
|
||||||
|
_cine.value = cine
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,28 +1,28 @@
|
|||||||
package fr.iut.cinecool
|
package fr.iut.cinecool.viewModel
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import fr.iut.cinecool.API.Movie
|
import fr.iut.cinecool.API.THMDB.Movie
|
||||||
import fr.iut.cinecool.API.Repository
|
import fr.iut.cinecool.API.THMDB.MethodApiTHMDB
|
||||||
|
|
||||||
class MovieViewModel : ViewModel() {
|
class MovieViewModel : ViewModel() {
|
||||||
private val repository = Repository()
|
private val methodApiTHMDB = MethodApiTHMDB()
|
||||||
|
|
||||||
val popularMovies = MutableLiveData<List<Movie>>()
|
val popularMovies = MutableLiveData<List<Movie>>()
|
||||||
val searchResults = MutableLiveData<List<Movie>>()
|
val searchResults = MutableLiveData<List<Movie>>()
|
||||||
|
|
||||||
fun getPopularMovies(apiKey: String, page: Int) {
|
fun getPopularMovies(apiKey: String, page: Int) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val movies = repository.getPopularMovies(apiKey, page)
|
val movies = methodApiTHMDB.getPopularMovies(apiKey, page)
|
||||||
popularMovies.postValue(movies.results)
|
popularMovies.postValue(movies.results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun searchMovies(apiKey: String, query: String, page: Int) {
|
fun searchMovies(apiKey: String, query: String, page: Int) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val movies = repository.searchMovies(apiKey, query, page)
|
val movies = methodApiTHMDB.searchMovies(apiKey, query, page)
|
||||||
searchResults.postValue(movies.results)
|
searchResults.postValue(movies.results)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".CinemaFragment">
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/recyclerCinemas"/>
|
|
||||||
</FrameLayout>
|
|
@ -0,0 +1,16 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">CineCool</string>
|
||||||
|
<string name="title_activity_main">MainActivity</string>
|
||||||
|
<!-- Strings used for fragments for navigation -->
|
||||||
|
<string name="first_fragment_label">First Fragment</string>
|
||||||
|
<string name="second_fragment_label">Second Fragment</string>
|
||||||
|
<string name="next">Suivant</string>
|
||||||
|
<string name="previous">Précédent</string>
|
||||||
|
|
||||||
|
<string name="hello_first_fragment">Hello first fragment</string>
|
||||||
|
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
|
||||||
|
<string name="error_loading_movie">erreur de chargement des films</string>
|
||||||
|
<string name="tmdb_api_key">a97243d7813d31446f6c43284e6854d5</string>
|
||||||
|
<string name="welcome">Bienvenue dans CineCool</string>
|
||||||
|
<string name="research">Recherche</string>
|
||||||
|
</resources>
|
Loading…
Reference in new issue