Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 4cfd57a

Browse files
committed
[ADDED] Enhancement on the movie details page by adding related contents.
1 parent 8f4df3f commit 4cfd57a

12 files changed

+164
-9
lines changed

app/src/main/java/com/hossainkhan/android/demo/ui/functionaldemo/MovieDetailsPreviewActivity.kt

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import android.widget.ImageView
3030
import androidx.annotation.ColorRes
3131
import androidx.core.content.ContextCompat
3232
import androidx.core.widget.ImageViewCompat
33+
import androidx.recyclerview.widget.LinearLayoutManager
34+
import androidx.recyclerview.widget.RecyclerView
3335

3436
/**
3537
* Activity showcasing how visibility GONE affects constraints.
@@ -49,6 +51,8 @@ class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
4951
}
5052

5153

54+
private lateinit var recyclerView: RecyclerView
55+
5256
override fun onCreate(savedInstanceState: Bundle?) {
5357
super.onCreate(savedInstanceState)
5458

@@ -66,6 +70,14 @@ class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
6670
val youtubeTrailerUrl = "https://www.youtube.com/watch?v=g4Hbz2jLxvQ"
6771
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(youtubeTrailerUrl)))
6872
}
73+
74+
recyclerView = findViewById(R.id.movie_related_contents)
75+
76+
recyclerView.apply {
77+
setHasFixedSize(true)
78+
layoutManager = LinearLayoutManager(this@MovieDetailsPreviewActivity, LinearLayoutManager.HORIZONTAL, false)
79+
adapter = MoviePosterAdapter()
80+
}
6981
}
7082

7183
private fun applyToastListener(vararg views: View) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2019 Hossain Khan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hossainkhan.android.demo.ui.functionaldemo
18+
19+
import android.view.LayoutInflater
20+
import android.view.ViewGroup
21+
import android.widget.ImageView
22+
import androidx.recyclerview.widget.RecyclerView
23+
import com.hossainkhan.android.demo.R
24+
25+
/**
26+
* A simple adapter container movie poster images.
27+
*/
28+
class MoviePosterAdapter : RecyclerView.Adapter<MoviePosterAdapter.PosterViewHolder>() {
29+
private val posterImageResourceIds = listOf(
30+
R.drawable.poster_lego_batman,
31+
R.drawable.poster_i2,
32+
R.drawable.poster_angry_birds,
33+
R.drawable.poster_lego_movie,
34+
R.drawable.poster_wreckit_ralph,
35+
R.drawable.poster_dragon3
36+
)
37+
38+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PosterViewHolder {
39+
// create a new view
40+
val posterView = LayoutInflater.from(parent.context)
41+
.inflate(R.layout.list_item_poster, parent, false) as ImageView
42+
43+
return PosterViewHolder(posterView)
44+
}
45+
46+
override fun getItemCount(): Int {
47+
return posterImageResourceIds.size
48+
}
49+
50+
override fun onBindViewHolder(holder: PosterViewHolder, position: Int) {
51+
holder.posterView.setImageResource(posterImageResourceIds[position])
52+
}
53+
54+
// Provide a reference to the views for each data item
55+
class PosterViewHolder(val posterView: ImageView) : RecyclerView.ViewHolder(posterView)
56+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--
2+
~ Copyright (c) 2019 Hossain Khan
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="18dp"
19+
android:height="18dp"
20+
android:alpha="0.9"
21+
android:tint="#666666"
22+
android:viewportWidth="24"
23+
android:viewportHeight="24">
24+
<path
25+
android:fillColor="#FF000000"
26+
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM12,13.5h-1L11,15L9.5,15v-1.5h-3L6.5,9L8,9v3h1.5L9.5,9L11,9v3h1v1.5zM18,15h-1.75l-1.75,-2.25L14.5,15L13,15L13,9h1.5v2.25L16.25,9L18,9l-2.25,3L18,15z" />
27+
</vector>

app/src/main/res/layout/demo_movie_details.xml

+40-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8"?><!--
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
24
~ Copyright (c) 2019 Hossain Khan
35
~
46
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -48,7 +50,6 @@
4850
<!-- ================ Begin top section with background, poster and meta info ================ -->
4951

5052

51-
5253
<ImageView
5354
android:id="@+id/thumbnail"
5455
android:layout_width="0dp"
@@ -79,21 +80,21 @@
7980
android:id="@+id/poster"
8081
android:layout_width="wrap_content"
8182
android:layout_height="wrap_content"
82-
android:src="@drawable/spider_verse_poster"
83+
android:src="@drawable/poster_spider_verse_detail"
8384
app:layout_constraintBottom_toBottomOf="@+id/thumbnail"
8485
app:layout_constraintStart_toStartOf="@+id/guideline_vertical_start"
85-
app:layout_constraintTop_toBottomOf="@+id/movie_trailer" />
86+
app:layout_constraintTop_toTopOf="@+id/thumbnail" />
8687

8788
<TextView
8889
android:id="@+id/movie_title"
8990
style="@style/TextAppearance.AppCompat.Title.Inverse"
9091
android:layout_width="0dp"
9192
android:layout_height="wrap_content"
92-
android:layout_marginStart="8dp"
93+
android:layout_marginStart="16dp"
9394
android:text="Spider-Man: Into The Spider-Verse"
9495
app:layout_constraintEnd_toEndOf="@id/guideline_vertical_end"
9596
app:layout_constraintStart_toEndOf="@+id/poster"
96-
app:layout_constraintTop_toTopOf="@+id/poster" />
97+
app:layout_constraintTop_toBottomOf="@+id/movie_trailer" />
9798

9899
<TextView
99100
android:id="@+id/movie_rating_and_time"
@@ -125,7 +126,8 @@
125126
android:layout_gravity="center"
126127
android:layout_marginStart="16dp"
127128
android:drawableStart="@drawable/ic_people_black_18dp"
128-
android:drawablePadding="3dp"
129+
android:drawablePadding="5dp"
130+
android:drawableEnd="@drawable/ic_baseline_4k_18dp"
129131
android:drawableTint="@android:color/white"
130132
android:text="93%"
131133
app:layout_constraintLeft_toRightOf="@+id/user_rating"
@@ -208,6 +210,35 @@
208210

209211
<!-- =========================== End Chained Button =========================== -->
210212

213+
<!-- ======================= BEGIN Recycler view with related movies ======================== -->
214+
215+
<TextView
216+
android:id="@+id/movie_related_title"
217+
style="@style/TextAppearance.AppCompat.Title.Inverse"
218+
android:layout_width="0dp"
219+
android:layout_height="wrap_content"
220+
android:layout_marginTop="16dp"
221+
android:text="Similar Movies"
222+
app:layout_constraintLeft_toLeftOf="@+id/guideline_vertical_start"
223+
app:layout_constraintRight_toRightOf="@+id/guideline_vertical_end"
224+
app:layout_constraintTop_toBottomOf="@+id/button_rent" />
225+
226+
<androidx.recyclerview.widget.RecyclerView
227+
android:id="@+id/movie_related_contents"
228+
android:layout_width="0dp"
229+
android:layout_height="wrap_content"
230+
android:layout_marginTop="16dp"
231+
app:layout_constraintLeft_toLeftOf="parent"
232+
app:layout_constraintRight_toRightOf="parent"
233+
app:layout_constraintTop_toBottomOf="@+id/movie_related_title"
234+
tools:background="@color/md_pink_100"
235+
tools:itemCount="4"
236+
tools:layoutManager="LinearLayoutManager"
237+
tools:listitem="@layout/list_item_poster"
238+
tools:orientation="horizontal" />
239+
240+
<!-- ======================= END Recycler view - similar movies ======================== -->
241+
211242

212243
<!-- ======================= BEGIN More info block with lots of text info ======================== -->
213244

@@ -216,11 +247,11 @@
216247
style="@style/TextAppearance.AppCompat.Title.Inverse"
217248
android:layout_width="0dp"
218249
android:layout_height="wrap_content"
219-
android:layout_marginTop="16dp"
250+
android:layout_marginTop="24dp"
220251
android:text="More Information"
221252
app:layout_constraintLeft_toLeftOf="@+id/guideline_vertical_start"
222253
app:layout_constraintRight_toRightOf="@+id/guideline_vertical_end"
223-
app:layout_constraintTop_toBottomOf="@+id/button_rent" />
254+
app:layout_constraintTop_toBottomOf="@+id/movie_related_contents" />
224255

225256
<TextView
226257
android:id="@+id/info_audio_language_label"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
~ Copyright (c) 2019 Hossain Khan
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:app="http://schemas.android.com/apk/res-auto"
21+
xmlns:tools="http://schemas.android.com/tools"
22+
android:id="@+id/poster_view"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:paddingStart="16dp"
26+
android:paddingEnd="0dp"
27+
android:src="@drawable/poster_angry_birds"
28+
tools:background="@color/md_pink_300"
29+
tools:ignore="ContentDescription" />

0 commit comments

Comments
 (0)