parent
797ce00665
commit
bf50751c6f
@ -0,0 +1,4 @@
|
|||||||
|
package fr.iut.pm.movieapplication.ui.adapter
|
||||||
|
|
||||||
|
class SearchResultAdapter {
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package fr.iut.pm.movieapplication.ui.fragments
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import fr.iut.pm.movieapplication.ui.viewmodel.SearchResultVM
|
||||||
|
import fr.iut.pm.movieapplication.ui.viewmodel.SearchResultVMFactory
|
||||||
|
|
||||||
|
class SearchResultFragment : Fragment() {
|
||||||
|
|
||||||
|
private val searchResultViewModel by viewModels<SearchResultVM> { SearchResultVMFactory(arguments?.getString("query")!!) }
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
return super.onCreateView(inflater, container, savedInstanceState)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package fr.iut.pm.movieapplication.ui.interfaces
|
||||||
|
|
||||||
|
interface MovieSelection {
|
||||||
|
|
||||||
|
fun onMovieSelected(movieId : Int)
|
||||||
|
}
|
@ -1,4 +1,33 @@
|
|||||||
package fr.iut.pm.movieapplication.ui.viewmodel
|
package fr.iut.pm.movieapplication.ui.viewmodel
|
||||||
|
|
||||||
class HomeSectionsVM {
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import fr.iut.pm.movieapplication.model.media.MediaResult
|
||||||
|
import fr.iut.pm.movieapplication.repository.MediaRepository
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class HomeSectionsVM : ViewModel() {
|
||||||
|
|
||||||
|
private val repository = MediaRepository()
|
||||||
|
|
||||||
|
private var _trendsLiveData : MutableLiveData<List<MediaResult>> = MutableLiveData()
|
||||||
|
fun getTrendsLiveData() : MutableLiveData<List<MediaResult>> = _trendsLiveData
|
||||||
|
|
||||||
|
private var _popularMoviesLiveData : MutableLiveData<List<MediaResult>> = MutableLiveData()
|
||||||
|
fun getPopularMoviesLiveData() : MutableLiveData<List<MediaResult>> = _popularMoviesLiveData
|
||||||
|
|
||||||
|
private var _popularTvShowsLiveData : MutableLiveData<List<MediaResult>> = MutableLiveData()
|
||||||
|
fun getPopularTvShowsLiveData() : MutableLiveData<List<MediaResult>> = _popularTvShowsLiveData
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_trendsLiveData.postValue(repository.getTrends())
|
||||||
|
_popularMoviesLiveData.postValue(repository.getPopularMovies())
|
||||||
|
_popularTvShowsLiveData.postValue(repository.getPopularTvShows())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package fr.iut.pm.movieapplication.ui.viewmodel
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
|
||||||
|
class SearchResultVM(private var query : String) : ViewModel() {
|
||||||
|
private var _queryLiveData : MutableLiveData<String> = MutableLiveData()
|
||||||
|
fun getQueryLiveData() : LiveData<String> = _queryLiveData
|
||||||
|
|
||||||
|
init {
|
||||||
|
_queryLiveData.postValue(query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchResultVMFactory(private var query : String) : ViewModelProvider.Factory
|
||||||
|
{
|
||||||
|
override fun<T:ViewModel>create(modelClass:Class<T>) : T
|
||||||
|
{
|
||||||
|
return SearchResultVM(query) as T
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
<?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="searchResultsVM"
|
||||||
|
type="fr.iut.pm.movieapplication.ui.viewmodel.SearchResultVM" />
|
||||||
|
|
||||||
|
</data>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/search_results_item_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginBottom="@dimen/default_margin"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||||
|
app:spanCount="3"
|
||||||
|
tools:listitem="@layout/item_vertical_fragment" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</layout>
|
@ -1,45 +1,51 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<variable
|
||||||
|
name="mediaResult"
|
||||||
|
type="fr.iut.pm.movieapplication.model.media.MediaResult" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="150dp"
|
android:layout_width="150dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="10dp">
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
android:id="@+id/cardView"
|
android:id="@+id/cardView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="150dp"
|
||||||
android:layout_height="200dp"
|
android:layout_height="match_parent"
|
||||||
app:cardCornerRadius="5dp"
|
app:cardCornerRadius="5dp">
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/item_image"
|
android:id="@+id/item_image"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="210dp"
|
||||||
android:background="@color/black"
|
android:background="@color/black"
|
||||||
android:scaleType="centerCrop" />
|
android:scaleType="centerCrop"
|
||||||
|
android:contentDescription="description" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/item_name"
|
android:id="@+id/item_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="20dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_gravity="center"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:textAlignment="center"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/cardView" />
|
android:text="@{mediaResult.title}"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/item_date"
|
android:id="@+id/item_date"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="20dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_gravity="center"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:textAlignment="center"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/item_name" />
|
android:text="@{mediaResult.releaseDate}"/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</LinearLayout>
|
||||||
|
</layout>
|
Loading…
Reference in new issue