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

Commit 0d42a17

Browse files
committed
[ADDED] Trailer button for movie trailer and added some UI responsiveness.
1 parent 16828d0 commit 0d42a17

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import android.widget.ImageButton
2323
import android.widget.Toast
2424
import com.hossainkhan.android.demo.R
2525
import com.hossainkhan.android.demo.ui.layoutpreview.LayoutPreviewBaseActivity
26+
import android.content.Intent
27+
import android.content.res.ColorStateList
28+
import android.net.Uri
29+
import android.widget.ImageView
30+
import androidx.annotation.ColorRes
31+
import androidx.core.content.ContextCompat
32+
import androidx.core.widget.ImageViewCompat
2633

2734
/**
2835
* Activity showcasing how visibility GONE affects constraints.
@@ -32,8 +39,16 @@ import com.hossainkhan.android.demo.ui.layoutpreview.LayoutPreviewBaseActivity
3239
class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
3340
private val generalClickListener = View.OnClickListener { view ->
3441
Toast.makeText(view.context, "You tapped on ${view}", Toast.LENGTH_SHORT).show()
42+
43+
// Some custom logic to make the UI alive!
44+
when (view.id) {
45+
R.id.rating_thumbs_up, R.id.rating_thumbs_down -> {
46+
applyColorTint((view as ImageButton), R.color.white)
47+
}
48+
}
3549
}
3650

51+
3752
override fun onCreate(savedInstanceState: Bundle?) {
3853
super.onCreate(savedInstanceState)
3954

@@ -42,14 +57,26 @@ class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
4257
val addToFav = findViewById<ImageButton>(R.id.rating_add_fav)
4358
val rentButton = findViewById<Button>(R.id.button_rent)
4459
val buyButton = findViewById<Button>(R.id.button_buy)
60+
val trailer = findViewById<Button>(R.id.movie_trailer)
4561

4662
// Apply generic toast listener to touchable views so that user gets feedback when they tap it
4763
applyToastListener(ratingThumbsUp, ratingThumbsDown, addToFav, rentButton, buyButton)
64+
65+
trailer.setOnClickListener {
66+
val youtubeTrailerUrl = "https://www.youtube.com/watch?v=g4Hbz2jLxvQ"
67+
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(youtubeTrailerUrl)))
68+
}
4869
}
4970

5071
private fun applyToastListener(vararg views: View) {
5172
views.forEach {
5273
it.setOnClickListener(generalClickListener)
5374
}
5475
}
76+
77+
private fun applyColorTint(view: ImageView, @ColorRes tintColor: Int) {
78+
ImageViewCompat.setImageTintList(view,
79+
ColorStateList.valueOf(ContextCompat.getColor(this.applicationContext, tintColor))
80+
)
81+
}
5582
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 android:alpha="0.9" android:height="24dp" android:tint="#666666"
18+
android:viewportHeight="24.0" android:viewportWidth="24.0"
19+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
20+
<path android:fillColor="#FF000000" android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
21+
</vector>

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent">
2121

22+
<!--
23+
NOTE: This is a complete demo of a video details view using `ConstraintLayout` and flat view hierarchy.
24+
-->
2225
<androidx.constraintlayout.widget.ConstraintLayout
2326
android:layout_width="match_parent"
2427
android:layout_height="match_parent"
@@ -42,13 +45,32 @@
4245

4346
<!-- ================ END of guidelines =================== -->
4447

48+
<!-- ================ Begin top section with background, poster and meta info ================ -->
49+
50+
51+
4552
<ImageView
4653
android:id="@+id/thumbnail"
4754
android:layout_width="0dp"
4855
android:layout_height="wrap_content"
4956
android:scaleType="centerCrop"
5057
android:src="@drawable/spider_verse_background"
51-
android:tint="#77999999"
58+
android:tint="#99333333"
59+
app:layout_constraintEnd_toEndOf="parent"
60+
app:layout_constraintStart_toStartOf="parent"
61+
app:layout_constraintTop_toTopOf="parent" />
62+
63+
<Button
64+
android:id="@+id/movie_trailer"
65+
style="@style/Widget.AppCompat.Button.Borderless"
66+
android:layout_width="wrap_content"
67+
android:layout_height="wrap_content"
68+
android:layout_marginTop="8dp"
69+
android:drawableStart="@drawable/ic_play_circle_outline_black_24dp"
70+
android:drawablePadding="5dp"
71+
android:drawableTint="@color/md_pink_300"
72+
android:text="Trailer"
73+
android:textColor="@color/md_grey_400"
5274
app:layout_constraintEnd_toEndOf="parent"
5375
app:layout_constraintStart_toStartOf="parent"
5476
app:layout_constraintTop_toTopOf="parent" />
@@ -57,20 +79,17 @@
5779
android:id="@+id/poster"
5880
android:layout_width="wrap_content"
5981
android:layout_height="wrap_content"
60-
android:layout_marginStart="8dp"
61-
android:layout_marginTop="8dp"
6282
android:src="@drawable/spider_verse_poster"
6383
app:layout_constraintBottom_toBottomOf="@+id/thumbnail"
6484
app:layout_constraintStart_toStartOf="@+id/guideline_vertical_start"
65-
app:layout_constraintTop_toTopOf="@+id/thumbnail" />
85+
app:layout_constraintTop_toBottomOf="@+id/movie_trailer" />
6686

6787
<TextView
6888
android:id="@+id/movie_title"
6989
style="@style/TextAppearance.AppCompat.Title.Inverse"
7090
android:layout_width="0dp"
7191
android:layout_height="wrap_content"
7292
android:layout_marginStart="8dp"
73-
android:layout_marginEnd="8dp"
7493
android:text="Spider-Man: Into The Spider-Verse"
7594
app:layout_constraintEnd_toEndOf="@id/guideline_vertical_end"
7695
app:layout_constraintStart_toEndOf="@+id/poster"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
app:layout_constraintTop_toTopOf="parent"
4242
tools:background="@color/md_amber_300"
4343
tools:ignore="ContentDescription"
44-
tools:srcCompat="@drawable/ic_position_center_preview" />
44+
tools:srcCompat="@drawable/thumb_positioning_center" />
4545

4646
<TextView
4747
android:id="@+id/layout_preview_name"

0 commit comments

Comments
 (0)