Skip to content
Permalink
Browse files

Fix episode detail badge holder

  • Loading branch information...
chrisbanes committed Nov 7, 2019
1 parent d72f561 commit ed4d99980cc4bf62fc38aa0f93593207d6beb516
@@ -17,10 +17,10 @@
package app.tivi.episodedetails

import android.content.Context
import app.tivi.common.layouts.DetailsBadgeBindingModel_
import app.tivi.common.layouts.detailsHeader
import app.tivi.inject.PerActivity
import app.tivi.util.TiviDateFormatter
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.EpoxyModelGroup
import com.airbnb.epoxy.TypedEpoxyController
import javax.inject.Inject
@@ -35,9 +35,9 @@ class EpisodeDetailsEpoxyController @Inject constructor(
if (viewState.episode != null) {
val episode = viewState.episode

val badges = ArrayList<DetailsBadgeBindingModel_>()
val badges = ArrayList<EpoxyModel<*>>()
episode.traktRating?.also { rating ->
badges += DetailsBadgeBindingModel_().apply {
badges += EpisodeDetailsBadgeBindingModel_().apply {
val ratingOutOfOneHundred = (rating * 10).roundToInt()
id("rating")
label(context.getString(R.string.percentage_format, ratingOutOfOneHundred))
@@ -47,7 +47,7 @@ class EpisodeDetailsEpoxyController @Inject constructor(
}
}
episode.firstAired?.also { firstAired ->
badges += DetailsBadgeBindingModel_().apply {
badges += EpisodeDetailsBadgeBindingModel_().apply {
id("aired")
label(dateFormatter.formatShortRelativeTime(firstAired))
icon(R.drawable.ic_details_date)
@@ -57,7 +57,7 @@ class EpisodeDetailsEpoxyController @Inject constructor(
EpoxyModelGroup(R.layout.layout_badge_holder, badges).addTo(this)
}

epDetailsSummary {
episodeDetailsSummary {
id("episode_summary")
episode(episode)
}
@@ -70,7 +70,7 @@ class EpisodeDetailsEpoxyController @Inject constructor(
title(R.string.episode_watches)
}
watches.forEach { entry ->
epDetailsWatchItem {
episodeDetailsWatchItem {
id("watch_${entry.id}")
dateTimeFormatter(dateFormatter)
watch(entry)
@@ -72,22 +72,20 @@ class EpisodeDetailsFragment : TiviFragmentWithBinding<FragmentEpisodeDetailsBin
}

val context = requireContext()
val swipeCallback = object : SwipeAwayCallbacks<EpDetailsWatchItemBindingModel_>(
val swipeCallback = object : SwipeAwayCallbacks<EpisodeDetailsWatchItemBindingModel_>(
context.getDrawable(R.drawable.ic_eye_off_24dp)!!,
context.resources.getDimensionPixelSize(R.dimen.spacing_large),
context.getColor(R.color.swipe_away_background),
context.resolveThemeColor(R.attr.colorSecondary)
) {
override fun onSwipeCompleted(
model: EpDetailsWatchItemBindingModel_,
model: EpisodeDetailsWatchItemBindingModel_,
itemView: View,
position: Int,
direction: Int
) {
model.watch().also(viewModel::removeWatchEntry)
}
) = viewModel.removeWatchEntry(model.watch())

override fun isSwipeEnabledForModel(model: EpDetailsWatchItemBindingModel_): Boolean {
override fun isSwipeEnabledForModel(model: EpisodeDetailsWatchItemBindingModel_): Boolean {
return model.watch() != null
}
}
@@ -100,7 +98,7 @@ class EpisodeDetailsFragment : TiviFragmentWithBinding<FragmentEpisodeDetailsBin
it.left()
}
}
.withTarget(EpDetailsWatchItemBindingModel_::class.java)
.withTarget(EpisodeDetailsWatchItemBindingModel_::class.java)
.andCallbacks(swipeCallback)
}

@@ -0,0 +1,23 @@
<?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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_normal"
android:animateLayoutChanges="true"
android:orientation="horizontal" />
@@ -36,6 +36,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@{contentDescription}"
android:transitionGroup="true">

@@ -135,7 +135,7 @@ class ShowDetailsEpoxyController @Inject constructor(
}
}
if (badges.isNotEmpty()) {
EpoxyModelGroup(R.layout.layout_badge_holder, badges)
EpoxyModelGroup(R.layout.layout_show_details_info_holder, badges)
.addTo(this)
}

0 comments on commit ed4d999

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