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

Commit 9cb8280

Browse files
authored
Merge pull request #86 from amardeshbd/add-related-movies
[ADDED] Enhancement on the movie details page by adding related contents.
2 parents 8f4df3f + 4cfd57a commit 9cb8280

File tree

12 files changed

+164
-9
lines changed

12 files changed

+164
-9
lines changed

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

Lines changed: 12 additions & 0 deletions
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) {
Lines changed: 56 additions & 0 deletions
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+
}
147 KB
Loading
174 KB
Loading
176 KB
Loading
178 KB
Loading
137 KB
Loading
63.2 KB
Loading
123 KB
Loading
Lines changed: 27 additions & 0 deletions
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>

0 commit comments

Comments
 (0)