Add home page with different series and movie proposals such as the most popular and the best ratedmaster
parent
3e10b69996
commit
f3c8ca074f
@ -0,0 +1,97 @@
|
||||
package com.example.cinapp.model.navigation
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.example.cinapp.R
|
||||
import com.example.cinapp.Request.MediaAdapter
|
||||
import com.example.cinapp.Request.MediaApi
|
||||
import com.example.cinapp.model.Media
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private const val ARG_PARAM1 = "param1"
|
||||
private const val ARG_PARAM2 = "param2"
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* Use the [HomeFragment.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class HomeFragment : Fragment() {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
param1 = it.getString(ARG_PARAM1)
|
||||
param2 = it.getString(ARG_PARAM2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
//getPopularMovies
|
||||
// Inflate the layout for this fragment
|
||||
val rootView = inflater.inflate(R.layout.fragment_home, container, false)
|
||||
val apiKey = "e53e59cf1e29b9afff93d9ca1208f0cf"
|
||||
|
||||
MediaApi().getPopularMovies(apiKey) { listMedia ->
|
||||
val recyclerView = rootView.findViewById<RecyclerView>(R.id.rc_popular_movies)
|
||||
addMediaToRecyclerView(listMedia, recyclerView)
|
||||
}
|
||||
|
||||
MediaApi().getPopularSeries(apiKey) { listMedia ->
|
||||
val recyclerView = rootView.findViewById<RecyclerView>(R.id.rc_popular_series)
|
||||
addMediaToRecyclerView(listMedia, recyclerView)
|
||||
}
|
||||
|
||||
MediaApi().getTopRatedMovie(apiKey) { listMedia ->
|
||||
val recyclerView = rootView.findViewById<RecyclerView>(R.id.rc_top_rated_movies)
|
||||
addMediaToRecyclerView(listMedia, recyclerView)
|
||||
}
|
||||
|
||||
MediaApi().getTopRatedSerie(apiKey) { listMedia ->
|
||||
val recyclerView = rootView.findViewById<RecyclerView>(R.id.rc_top_rated_series)
|
||||
addMediaToRecyclerView(listMedia, recyclerView)
|
||||
}
|
||||
|
||||
return rootView
|
||||
}
|
||||
|
||||
fun addMediaToRecyclerView(listMedia: List<Media>, recyclerView: RecyclerView) {
|
||||
val layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL)
|
||||
recyclerView.layoutManager = layoutManager
|
||||
val adapter = MediaAdapter(listMedia)
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment HomeFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
@JvmStatic
|
||||
fun newInstance(param1: String, param2: String) =
|
||||
HomeFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_PARAM1, param1)
|
||||
putString(ARG_PARAM2, param2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||
</vector>
|
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".model.navigation.HomeFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="414dp"
|
||||
android:layout_height="24dp"
|
||||
android:text="@string/current_popular_movies"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:layout_editor_absoluteX="-3dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rc_popular_movies"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/purple_200"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="414dp"
|
||||
android:layout_height="24dp"
|
||||
android:text="@string/current_popular_serie"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rc_popular_movies"
|
||||
tools:layout_editor_absoluteX="0dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rc_popular_series"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/purple_200"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView4" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
android:layout_width="414dp"
|
||||
android:layout_height="24dp"
|
||||
android:text="@string/movies_top_rated"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rc_popular_series"
|
||||
tools:layout_editor_absoluteX="-3dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rc_top_rated_movies"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/purple_200"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView6" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="414dp"
|
||||
android:layout_height="24dp"
|
||||
android:text="@string/movies_top_rated"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rc_top_rated_movies"
|
||||
tools:layout_editor_absoluteX="0dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rc_top_rated_series"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/purple_200"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView5" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
@ -1,5 +1,12 @@
|
||||
<resources>
|
||||
<string name="app_name">Cin\'app</string>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="current_popular_movies">Current popular movies</string>
|
||||
<string name="current_popular_serie">Current popular serie</string>
|
||||
<string name="movies_in_theaters">Movies in theaters</string>
|
||||
<string name="series_on_the_air">Series on the air</string>
|
||||
<string name="movies_upcoming">Upcoming movies</string>
|
||||
<string name="series_airing_today">Series airing today</string>
|
||||
<string name="movies_top_rated">Top rated movies</string>
|
||||
<string name="series_top_rated">Top rated series</string>
|
||||
</resources>
|
Loading…
Reference in new issue