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

[ADDED] Enhancement on the movie details page by adding related contents. #86

Merged
merged 1 commit into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import android.widget.ImageView
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.core.widget.ImageViewCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

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


private lateinit var recyclerView: RecyclerView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -66,6 +70,14 @@ class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
val youtubeTrailerUrl = "https://www.youtube.com/watch?v=g4Hbz2jLxvQ"
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(youtubeTrailerUrl)))
}

recyclerView = findViewById(R.id.movie_related_contents)

recyclerView.apply {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(this@MovieDetailsPreviewActivity, LinearLayoutManager.HORIZONTAL, false)
adapter = MoviePosterAdapter()
}
}

private fun applyToastListener(vararg views: View) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 Hossain Khan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hossainkhan.android.demo.ui.functionaldemo

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.hossainkhan.android.demo.R

/**
* A simple adapter container movie poster images.
*/
class MoviePosterAdapter : RecyclerView.Adapter<MoviePosterAdapter.PosterViewHolder>() {
private val posterImageResourceIds = listOf(
R.drawable.poster_lego_batman,
R.drawable.poster_i2,
R.drawable.poster_angry_birds,
R.drawable.poster_lego_movie,
R.drawable.poster_wreckit_ralph,
R.drawable.poster_dragon3
)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PosterViewHolder {
// create a new view
val posterView = LayoutInflater.from(parent.context)
.inflate(R.layout.list_item_poster, parent, false) as ImageView

return PosterViewHolder(posterView)
}

override fun getItemCount(): Int {
return posterImageResourceIds.size
}

override fun onBindViewHolder(holder: PosterViewHolder, position: Int) {
holder.posterView.setImageResource(posterImageResourceIds[position])
}

// Provide a reference to the views for each data item
class PosterViewHolder(val posterView: ImageView) : RecyclerView.ViewHolder(posterView)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/poster_i2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_baseline_4k_18dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
~ Copyright (c) 2019 Hossain Khan
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:alpha="0.9"
android:tint="#666666"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
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" />
</vector>
49 changes: 40 additions & 9 deletions app/src/main/res/layout/demo_movie_details.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?><!--
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright (c) 2019 Hossain Khan
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,7 +50,6 @@
<!-- ================ Begin top section with background, poster and meta info ================ -->



<ImageView
android:id="@+id/thumbnail"
android:layout_width="0dp"
Expand Down Expand Up @@ -79,21 +80,21 @@
android:id="@+id/poster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/spider_verse_poster"
android:src="@drawable/poster_spider_verse_detail"
app:layout_constraintBottom_toBottomOf="@+id/thumbnail"
app:layout_constraintStart_toStartOf="@+id/guideline_vertical_start"
app:layout_constraintTop_toBottomOf="@+id/movie_trailer" />
app:layout_constraintTop_toTopOf="@+id/thumbnail" />

<TextView
android:id="@+id/movie_title"
style="@style/TextAppearance.AppCompat.Title.Inverse"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginStart="16dp"
android:text="Spider-Man: Into The Spider-Verse"
app:layout_constraintEnd_toEndOf="@id/guideline_vertical_end"
app:layout_constraintStart_toEndOf="@+id/poster"
app:layout_constraintTop_toTopOf="@+id/poster" />
app:layout_constraintTop_toBottomOf="@+id/movie_trailer" />

<TextView
android:id="@+id/movie_rating_and_time"
Expand Down Expand Up @@ -125,7 +126,8 @@
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:drawableStart="@drawable/ic_people_black_18dp"
android:drawablePadding="3dp"
android:drawablePadding="5dp"
android:drawableEnd="@drawable/ic_baseline_4k_18dp"
android:drawableTint="@android:color/white"
android:text="93%"
app:layout_constraintLeft_toRightOf="@+id/user_rating"
Expand Down Expand Up @@ -208,6 +210,35 @@

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

<!-- ======================= BEGIN Recycler view with related movies ======================== -->

<TextView
android:id="@+id/movie_related_title"
style="@style/TextAppearance.AppCompat.Title.Inverse"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Similar Movies"
app:layout_constraintLeft_toLeftOf="@+id/guideline_vertical_start"
app:layout_constraintRight_toRightOf="@+id/guideline_vertical_end"
app:layout_constraintTop_toBottomOf="@+id/button_rent" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/movie_related_contents"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/movie_related_title"
tools:background="@color/md_pink_100"
tools:itemCount="4"
tools:layoutManager="LinearLayoutManager"
tools:listitem="@layout/list_item_poster"
tools:orientation="horizontal" />

<!-- ======================= END Recycler view - similar movies ======================== -->


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

Expand All @@ -216,11 +247,11 @@
style="@style/TextAppearance.AppCompat.Title.Inverse"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="24dp"
android:text="More Information"
app:layout_constraintLeft_toLeftOf="@+id/guideline_vertical_start"
app:layout_constraintRight_toRightOf="@+id/guideline_vertical_end"
app:layout_constraintTop_toBottomOf="@+id/button_rent" />
app:layout_constraintTop_toBottomOf="@+id/movie_related_contents" />

<TextView
android:id="@+id/info_audio_language_label"
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/list_item_poster.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright (c) 2019 Hossain Khan
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<ImageView 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:id="@+id/poster_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="0dp"
android:src="@drawable/poster_angry_birds"
tools:background="@color/md_pink_300"
tools:ignore="ContentDescription" />