Skip to content
Permalink
Browse files

Split out entry grid utils to module

  • Loading branch information...
chrisbanes committed Jul 29, 2019
1 parent 687779e commit 65812444ff61e6ff63f3922a46b90fb5b9bebff0
@@ -14,6 +14,7 @@
<option value="$PROJECT_DIR$/base-android" />
<option value="$PROJECT_DIR$/buildSrc" />
<option value="$PROJECT_DIR$/common-databinding" />
<option value="$PROJECT_DIR$/common-entrygrid" />
<option value="$PROJECT_DIR$/common-epoxy" />
<option value="$PROJECT_DIR$/common-glide" />
<option value="$PROJECT_DIR$/common-layouts" />
@@ -7,6 +7,7 @@
<module fileurl="file://$PROJECT_DIR$/base-android/base-android.iml" filepath="$PROJECT_DIR$/base-android/base-android.iml" />
<module fileurl="file://$PROJECT_DIR$/buildSrc/buildSrc.iml" filepath="$PROJECT_DIR$/buildSrc/buildSrc.iml" />
<module fileurl="file://$PROJECT_DIR$/common-databinding/common-databinding.iml" filepath="$PROJECT_DIR$/common-databinding/common-databinding.iml" />
<module fileurl="file://$PROJECT_DIR$/common-entrygrid/common-entrygrid.iml" filepath="$PROJECT_DIR$/common-entrygrid/common-entrygrid.iml" />
<module fileurl="file://$PROJECT_DIR$/common-epoxy/common-epoxy.iml" filepath="$PROJECT_DIR$/common-epoxy/common-epoxy.iml" />
<module fileurl="file://$PROJECT_DIR$/common-glide/common-glide.iml" filepath="$PROJECT_DIR$/common-glide/common-glide.iml" />
<module fileurl="file://$PROJECT_DIR$/common-layouts/common-layouts.iml" filepath="$PROJECT_DIR$/common-layouts/common-layouts.iml" />
@@ -165,6 +165,7 @@ dependencies {
implementation project(":common-layouts")
implementation project(":common-glide")
implementation project(":common-databinding")
implementation project(":common-entrygrid")
implementation project(":data")
implementation project(":data-android")
implementation project(":trakt")
@@ -30,7 +30,7 @@ import app.tivi.util.EntryGridFragment
import com.airbnb.epoxy.EpoxyModel

class PopularShowsFragment : EntryGridFragment<PopularEntryWithShow, PopularShowsViewModel>(PopularShowsViewModel::class.java) {
override fun onItemClicked(item: PopularEntryWithShow) {
internal fun onItemClicked(item: PopularEntryWithShow) {
val sharedElements = SharedElementHelper()
binding.gridRecyclerview.findViewHolderForItemId(item.generateStableId()).let {
sharedElements.addSharedElement(it.itemView, "poster")
@@ -53,7 +53,7 @@ class PopularShowsFragment : EntryGridFragment<PopularEntryWithShow, PopularShow
.posterImage(item.images.findHighestRatedPoster())
.tiviShow(item.show)
.transitionName(item.show.homepage)
.clickListener(View.OnClickListener { callbacks?.onItemClicked(item) })
.clickListener(View.OnClickListener { onItemClicked(item) })
}
}
}
@@ -40,19 +40,19 @@ class TrendingShowsFragment : EntryGridFragment<TrendingEntryWithShow, TrendingS
.tiviShow(item.show)
.trendingShow(item.entry)
.transitionName(item.show.homepage)
.clickListener(View.OnClickListener { callbacks?.onItemClicked(item) })
.clickListener(View.OnClickListener { onItemClicked(item) })
}
}
}

override fun onItemClicked(item: TrendingEntryWithShow) {
internal fun onItemClicked(item: TrendingEntryWithShow) {
val sharedElements = SharedElementHelper()
binding.gridRecyclerview.findViewHolderForItemId(item.generateStableId())?.let {
sharedElements.addSharedElement(it.itemView, "poster")
}

findNavController().navigate(
app.tivi.home.followed.R.id.activity_show_details,
R.id.activity_show_details,
bundleOf("show_id" to item.show.id),
null,
sharedElements.toActivityNavigatorExtras(requireActivity())
@@ -20,13 +20,13 @@ import app.tivi.buildsrc.Libs
apply plugin: 'kotlin'

dependencies {
compile Libs.Kotlin.stdlib
api Libs.Kotlin.stdlib

compile Libs.Coroutines.core
compile Libs.Coroutines.rx2
api Libs.Coroutines.core
api Libs.Coroutines.rx2

compile Libs.Dagger.dagger
api Libs.Dagger.dagger

compile Libs.Retrofit.retrofit
compile Libs.OkHttp.loggingInterceptor
api Libs.Retrofit.retrofit
api Libs.OkHttp.loggingInterceptor
}
@@ -0,0 +1,76 @@
/*
* Copyright 2018 Google, Inc.
*
* 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.
*
*/

import app.tivi.buildsrc.Libs

apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'
kapt {
correctErrorTypes = true
useBuildCache = true
}

android {
compileSdkVersion buildConfig.compileSdk

defaultConfig {
minSdkVersion buildConfig.minSdk
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
enabled = true
}
}

dependencies {
implementation project(":base-android")
implementation project(":interactors")
implementation project(":common-ui")
implementation project(":common-epoxy")
implementation project(":common-layouts")
implementation project(":common-databinding")

implementation Libs.AndroidX.Lifecycle.extensions
implementation Libs.AndroidX.Lifecycle.reactive
implementation Libs.AndroidX.Lifecycle.viewmodel
kapt Libs.AndroidX.Lifecycle.compiler

implementation Libs.AndroidX.Paging.runtime

implementation Libs.AndroidX.constraintlayout
implementation Libs.AndroidX.recyclerview
implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.Fragment.fragmentKtx

implementation Libs.RxJava.rxJava
implementation Libs.RxJava.rxKotlin
implementation Libs.RxJava.rxAndroid

implementation Libs.Dagger.androidSupport
kapt Libs.Dagger.compiler
kapt Libs.Dagger.androidProcessor

debugImplementation Libs.rxLint
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 Google, Inc.
~
~ 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.
~
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.tivi.common.entrygrid">

</manifest>
@@ -19,6 +19,8 @@ package app.tivi.util
import android.os.Handler
import android.os.Looper
import androidx.annotation.StringRes
import app.tivi.common.epoxy.EpoxyModelProperty
import app.tivi.common.epoxy.TotalSpanOverride
import app.tivi.common.layouts.HeaderBindingModel_
import app.tivi.common.layouts.PosterGridItemBindingModel_
import app.tivi.common.layouts.emptyState
@@ -27,8 +29,6 @@ import app.tivi.common.layouts.infiniteLoading
import app.tivi.data.Entry
import app.tivi.data.resultentities.EntryWithShow
import app.tivi.tmdb.TmdbImageUrlProvider
import app.tivi.common.epoxy.EpoxyModelProperty
import app.tivi.common.epoxy.TotalSpanOverride
import com.airbnb.epoxy.EpoxyAsyncUtil
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.paging.PagedListEpoxyController
@@ -39,15 +39,9 @@ abstract class EntryGridEpoxyController<LI : EntryWithShow<out Entry>>(
modelBuildingHandler = Handler(Looper.getMainLooper()),
diffingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler()
) {
internal var callbacks: Callbacks<LI>? = null

var isLoading by EpoxyModelProperty { false }
var tmdbImageUrlProvider by EpoxyModelProperty<TmdbImageUrlProvider?> { null }

interface Callbacks<in LI> {
fun onItemClicked(item: LI)
}

@Suppress("UselessCallOnCollection")
override fun addModels(models: List<EpoxyModel<*>>) {
// Need to do this due to https://github.com/airbnb/epoxy/issues/567
@@ -26,9 +26,9 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DefaultItemAnimator
import app.tivi.TiviFragment
import app.tivi.api.Status
import app.tivi.common.entrygrid.databinding.FragmentEntryGridBinding
import app.tivi.data.Entry
import app.tivi.data.resultentities.EntryWithShow
import app.tivi.databinding.FragmentEntryGridBinding
import app.tivi.extensions.observeNotNull
import app.tivi.ui.ProgressTimeLatch
import app.tivi.ui.SpacingItemDecorator
@@ -41,7 +41,7 @@ import javax.inject.Inject
abstract class EntryGridFragment<LI : EntryWithShow<out Entry>, VM : EntryViewModel<LI, *>>(
private val vmClass: Class<VM>
) : TiviFragment() {
protected lateinit var viewModel: VM
private lateinit var viewModel: VM
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory

private lateinit var swipeRefreshLatch: ProgressTimeLatch
@@ -54,11 +54,6 @@ abstract class EntryGridFragment<LI : EntryWithShow<out Entry>, VM : EntryViewMo
viewModel = ViewModelProviders.of(this, viewModelFactory).get(vmClass)

controller = createController()
controller.callbacks = object : EntryGridEpoxyController.Callbacks<LI> {
override fun onItemClicked(item: LI) {
this@EntryGridFragment.onItemClicked(item)
}
}

GridToGridTransitioner.setupSecondFragment(this) {
binding.gridRecyclerview.itemAnimator = DefaultItemAnimator()
@@ -116,7 +111,5 @@ abstract class EntryGridFragment<LI : EntryWithShow<out Entry>, VM : EntryViewMo
}
}

abstract fun onItemClicked(item: LI)

abstract fun createController(): EntryGridEpoxyController<LI>
}
@@ -41,7 +41,7 @@ dependencies {

implementation Libs.AndroidX.coreKtx

implementation Libs.Epoxy.epoxy
implementation Libs.Epoxy.paging
implementation Libs.Epoxy.dataBinding
api Libs.Epoxy.epoxy
api Libs.Epoxy.dataBinding
api Libs.Epoxy.paging
}
@@ -45,44 +45,26 @@ dependencies {
implementation project(":base-android")

implementation Libs.AndroidX.Lifecycle.extensions
implementation Libs.AndroidX.Lifecycle.reactive
implementation Libs.AndroidX.Lifecycle.viewmodel

implementation Libs.AndroidX.Paging.runtime
implementation Libs.AndroidX.Paging.rxjava2

implementation Libs.AndroidX.appcompat
implementation Libs.AndroidX.browser
api Libs.AndroidX.appcompat
implementation Libs.AndroidX.recyclerview
implementation Libs.AndroidX.emoji
implementation Libs.AndroidX.preference
implementation Libs.AndroidX.constraintlayout
implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.Fragment.fragment
implementation Libs.AndroidX.Fragment.fragmentKtx
implementation Libs.AndroidX.Navigation.fragment
implementation Libs.AndroidX.Navigation.ui

implementation Libs.Google.material

implementation Libs.RxJava.rxJava
implementation Libs.RxJava.rxKotlin
implementation Libs.RxJava.rxAndroid
api Libs.Google.material

implementation Libs.Kotlin.stdlib
implementation Libs.Kotlin.reflect

implementation Libs.Coroutines.core
implementation Libs.Coroutines.rx2
implementation Libs.Coroutines.android

implementation Libs.Dagger.androidSupport
kapt Libs.Dagger.compiler
kapt Libs.Dagger.androidProcessor

implementation Libs.mvRx

implementation Libs.gravitySnapHelper
api Libs.mvRx

debugImplementation Libs.rxLint
}
File renamed without changes.
@@ -22,6 +22,7 @@ include ':common-layouts'
include ':common-epoxy'
include ':common-glide'
include ':common-databinding'
include ':common-entrygrid'
include ':data'
include ':data-android'
include ':trakt'

0 comments on commit 6581244

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