Skip to content
Permalink
Browse files

Add rating bar to Show Details

  • Loading branch information
chrisbanes committed Nov 26, 2019
1 parent 996cc55 commit 59d455d553edf03ba2dfd6e25b18e871d86e26f5
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google LLC
~
~ 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.
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android">
<Space
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_micro" />
</layout>
@@ -16,10 +16,7 @@
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android">

<Space
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_small" />

<data />
</layout>
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,10 +16,7 @@
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android">

<Space
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_small" />

<data />
</layout>
@@ -63,7 +63,7 @@
<string name="percentage_format">%1$d%%</string>
<string name="minutes_format">%1$dm</string>

<string name="rating_title">Rating</string>
<string name="trakt_rating_title">Trakt Rating</string>
<string name="network_title">Network</string>
<string name="certificate_title">Certificate</string>
<string name="runtime_title">Length</string>
@@ -25,7 +25,6 @@ import app.tivi.common.epoxy.HalfSpanOverride
import app.tivi.common.epoxy.TotalSpanOverride
import app.tivi.common.epoxy.tiviCarousel
import app.tivi.common.epoxy.withModelsFrom
import app.tivi.common.layouts.DetailsInfoItemBindingModel_
import app.tivi.common.layouts.detailsHeader
import app.tivi.data.entities.ActionDate
import app.tivi.data.entities.Episode
@@ -46,7 +45,6 @@ import com.airbnb.epoxy.EpoxyModelGroup
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Success
import javax.inject.Inject
import kotlin.math.roundToInt

class ShowDetailsEpoxyController @Inject constructor(
@PerActivity private val context: Context,
@@ -103,34 +101,26 @@ class ShowDetailsEpoxyController @Inject constructor(

val show = state.show
val badges = ArrayList<EpoxyModel<*>>()
show.traktRating?.let { rating ->
badges += DetailsInfoItemBindingModel_().apply {
val ratingOutOfOneHundred = (rating * 10).roundToInt()
id("rating")
label(context.getString(R.string.percentage_format, ratingOutOfOneHundred))
title(textCreator.getString(R.string.rating_title))
}
badges += DetailsInfoRatingBindingModel_().apply {
id("rating")
tiviShow(show)
}
show.network?.let { network ->
badges += DetailsInfoItemBindingModel_().apply {
if (show.network != null) {
badges += DetailsInfoNetworkBindingModel_().apply {
id("network")
label(network)
title(textCreator.getString(R.string.network_title))
tiviShow(show)
}
}
show.certification?.let { certificate ->
badges += DetailsInfoItemBindingModel_().apply {
if (show.certification != null) {
badges += DetailsInfoCertBindingModel_().apply {
id("cert")
label(certificate)
title(textCreator.getString(R.string.certificate_title))
tiviShow(show)
}
}
show.runtime?.let { runtime ->
badges += DetailsInfoItemBindingModel_().apply {
val runtimeMinutes = context.getString(R.string.minutes_format, runtime)
if (show.runtime != null) {
badges += DetailsInfoRuntimeBindingModel_().apply {
id("runtime")
label(runtimeMinutes)
title(textCreator.getString(R.string.runtime_title))
tiviShow(show)
}
}
if (badges.isNotEmpty()) {
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2019 Google LLC
~
~ 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.
-->

<layout 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">

<data>
<variable
name="tiviShow"
type="app.tivi.data.entities.TiviShow" />
</data>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:transitionGroup="true"
android:paddingBottom="@dimen/spacing_small">

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_micro"
android:text="@string/certificate_title"
android:textAppearance="?attr/textAppearanceSubtitle2" />

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:text="@{tiviShow.certification}"
android:textAppearance="?attr/textAppearanceBody2"
tools:text="PG" />

</LinearLayout>
</layout>
@@ -19,39 +19,33 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="title"
type="CharSequence" />

<variable
name="label"
type="CharSequence" />
name="tiviShow"
type="app.tivi.data.entities.TiviShow" />
</data>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/spacing_small"
android:transitionGroup="true">
android:transitionGroup="true"
android:paddingBottom="@dimen/spacing_small">

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/network_title"
android:layout_marginBottom="@dimen/spacing_micro"
android:text="@{title}"
android:textAppearance="?attr/textAppearanceSubtitle2"
tools:text="Network" />
android:textAppearance="?attr/textAppearanceSubtitle2" />

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:text="@{label}"
android:text="@{tiviShow.network}"
android:textAppearance="?attr/textAppearanceBody2"
tools:text="HBO" />

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2019 Google LLC
~
~ 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.
-->

<layout 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">

<data>
<variable
name="tiviShow"
type="app.tivi.data.entities.TiviShow" />
</data>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:transitionGroup="true"
android:paddingBottom="@dimen/spacing_small">

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/trakt_rating_title"
android:textAppearance="?attr/textAppearanceSubtitle2"
tools:text="Rating" />

<RatingBar
android:id="@+id/details_info_rating_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.25"
style="?attr/ratingBarStyleIndicator"
app:rating="@{tiviShow.traktRating / 2f}"
tools:rating="3.25" />

</LinearLayout>
</layout>
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2019 Google LLC
~
~ 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.
-->

<layout 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">

<data>
<variable
name="tiviShow"
type="app.tivi.data.entities.TiviShow" />
</data>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:transitionGroup="true"
android:paddingBottom="@dimen/spacing_small">

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/runtime_title"
android:layout_marginBottom="@dimen/spacing_micro"
android:textAppearance="?attr/textAppearanceSubtitle2" />

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/details_info_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:text="@{@string/minutes_format(tiviShow.runtime)}"
android:textAppearance="?attr/textAppearanceBody2"
tools:text="PG" />

</LinearLayout>
</layout>

0 comments on commit 59d455d

Please sign in to comment.
You can’t perform that action at this time.