Permalink
Browse files

Inject WatchedEpoxyController

  • Loading branch information...
chrisbanes committed Feb 8, 2019
1 parent b3093ca commit 33c34feb52c0f9af93efb8d6fdd315d9fcc38233
@@ -16,13 +16,19 @@

package app.tivi.home

import android.content.Context
import app.tivi.AppNavigator
import app.tivi.TiviAppActivityNavigator
import app.tivi.inject.PerActivity
import dagger.Module
import dagger.Provides

@Module
class HomeModule {
@Provides
@PerActivity
fun provideActivity(activity: HomeActivity): Context = activity

@Provides
fun provideAppNavigator(activity: HomeActivity): AppNavigator {
return TiviAppActivityNavigator(activity)
@@ -21,9 +21,13 @@ import androidx.core.text.buildSpannedString
import androidx.core.text.inSpans
import app.tivi.R
import app.tivi.data.entities.TiviShow
import app.tivi.inject.PerActivity
import app.tivi.ui.text.textAppearanceSpanForAttribute
import javax.inject.Inject

class LibraryTextCreator(private val context: Context) {
class LibraryTextCreator @Inject constructor(
@PerActivity private val context: Context
) {
fun showTitle(show: TiviShow): CharSequence = buildSpannedString {
append(show.title)

@@ -29,9 +29,9 @@ import app.tivi.ui.epoxy.TotalSpanOverride
import app.tivi.util.TiviDateFormatter
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.paging.PagedListEpoxyController
import javax.inject.Inject

class WatchedEpoxyController(
private val callbacks: Callbacks,
class WatchedEpoxyController @Inject constructor(
private val textCreator: LibraryTextCreator,
private val dateFormatter: TiviDateFormatter
) : PagedListEpoxyController<WatchedShowEntryWithShow>(
@@ -40,6 +40,8 @@ class WatchedEpoxyController(
var tmdbImageUrlProvider by EpoxyModelProperty { TmdbImageUrlProvider() }
var isEmpty by EpoxyModelProperty { false }

var callbacks: Callbacks? = null

override fun addModels(models: List<EpoxyModel<*>>) {
if (isEmpty) {
emptyState {
@@ -58,7 +60,7 @@ class WatchedEpoxyController(
tiviShow(item.show)
posterTransitionName("show_${item.show.homepage}")
clickListener(View.OnClickListener {
callbacks.onItemClicked(item)
callbacks?.onItemClicked(item)
})
} else {
id("item_placeholder_$currentPosition")
@@ -26,10 +26,8 @@ import app.tivi.data.resultentities.WatchedShowEntryWithShow
import app.tivi.databinding.FragmentLibraryWatchedBinding
import app.tivi.home.HomeNavigator
import app.tivi.home.HomeNavigatorViewModel
import app.tivi.home.library.LibraryTextCreator
import app.tivi.ui.ListItemSharedElementHelper
import app.tivi.ui.SpacingItemDecorator
import app.tivi.util.TiviDateFormatter
import app.tivi.util.TiviMvRxFragment
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@@ -39,19 +37,16 @@ class WatchedFragment : TiviMvRxFragment() {

private lateinit var homeNavigator: HomeNavigator
private lateinit var binding: FragmentLibraryWatchedBinding
private lateinit var textCreator: LibraryTextCreator

private val viewModel: WatchedViewModel by fragmentViewModel()
@Inject lateinit var watchedViewModelFactory: WatchedViewModel.Factory

@Inject lateinit var dateFormatter: TiviDateFormatter
@Inject lateinit var controller: WatchedEpoxyController

private val listItemSharedElementHelper by lazy(LazyThreadSafetyMode.NONE) {
ListItemSharedElementHelper(binding.watchedRv) { it.findViewById(R.id.show_poster) }
}

private lateinit var controller: WatchedEpoxyController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
homeNavigator = ViewModelProviders.of(requireActivity(), viewModelFactory)
@@ -68,15 +63,13 @@ class WatchedFragment : TiviMvRxFragment() {
super.onViewCreated(view, savedInstanceState)
postponeEnterTransition()

textCreator = LibraryTextCreator(requireContext())

controller = WatchedEpoxyController(object : WatchedEpoxyController.Callbacks {
controller.callbacks = object : WatchedEpoxyController.Callbacks {
override fun onItemClicked(item: WatchedShowEntryWithShow) {
viewModel.onItemPostedClicked(homeNavigator, item.show,
listItemSharedElementHelper.createForItem(item, "poster")
)
}
}, textCreator, dateFormatter)
}

binding.watchedRv.apply {
addItemDecoration(SpacingItemDecorator(paddingLeft))
@@ -41,4 +41,14 @@ annotation class MediumDateTime
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
@MustBeDocumented
annotation class ShortDate
annotation class ShortDate

@Retention(AnnotationRetention.RUNTIME)
@Qualifier
@MustBeDocumented
annotation class PerActivity

@Retention(AnnotationRetention.RUNTIME)
@Qualifier
@MustBeDocumented
annotation class PerApplication

0 comments on commit 33c34fe

Please sign in to comment.