Skip to content

Commit

Permalink
Move away from jobs for updating shows
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Apr 1, 2018
1 parent 3318285 commit e75b9c2
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 220 deletions.
16 changes: 0 additions & 16 deletions app/src/main/java/me/banes/chris/tivi/actions/TiviActionsImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package me.banes.chris.tivi.actions

import me.banes.chris.tivi.jobs.AddToMyShows
import me.banes.chris.tivi.jobs.RemoveFromMyShows
import me.banes.chris.tivi.jobs.UpdateShowFromTMDb
import me.banes.chris.tivi.jobs.UpdateShowFromTrakt

class TiviActionsImpl : TiviActions {
override fun addShowToMyShows(showId: Long) {
Expand All @@ -35,18 +33,4 @@ class TiviActionsImpl : TiviActions {
.build()
.scheduleAsync()
}

override fun updateShowFromTMDb(tmdbId: Int) {
UpdateShowFromTMDb.buildRequest(tmdbId)
.startNow()
.build()
.scheduleAsync()
}

override fun updateShowFromTrakt(traktId: Int) {
UpdateShowFromTrakt.buildRequest(traktId)
.startNow()
.build()
.scheduleAsync()
}
}
10 changes: 0 additions & 10 deletions app/src/main/java/me/banes/chris/tivi/jobs/JobsCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,4 @@ abstract class JobsCreator {
@IntoMap
@StringKey(RemoveFromMyShows.TAG)
abstract fun bindRemoveFromMyShows(job: RemoveFromMyShows): Job

@Binds
@IntoMap
@StringKey(UpdateShowFromTMDb.TAG)
abstract fun bindUpdateShowFromTMDb(job: UpdateShowFromTMDb): Job

@Binds
@IntoMap
@StringKey(UpdateShowFromTrakt.TAG)
abstract fun bindUpdateShowFromTrakt(job: UpdateShowFromTrakt): Job
}
72 changes: 0 additions & 72 deletions app/src/main/java/me/banes/chris/tivi/jobs/UpdateShowFromTMDb.kt

This file was deleted.

74 changes: 0 additions & 74 deletions app/src/main/java/me/banes/chris/tivi/jobs/UpdateShowFromTrakt.kt

This file was deleted.

4 changes: 2 additions & 2 deletions base-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
implementation project(":base")
implementation "com.android.support:support-fragment:${versions.support_library}"

compile "io.reactivex.rxjava2:rxandroid:2.0.2"
api "io.reactivex.rxjava2:rxandroid:2.0.2"

compile 'com.jakewharton.timber:timber:4.7.0'
api 'com.jakewharton.timber:timber:4.7.0'
}
2 changes: 0 additions & 2 deletions base/src/main/java/me/banes/chris/tivi/actions/TiviActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ package me.banes.chris.tivi.actions
interface TiviActions {
fun addShowToMyShows(showId: Long)
fun removeShowFromMyShows(showId: Long)
fun updateShowFromTMDb(tmdbId: Int)
fun updateShowFromTrakt(traktId: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.uwetrottmann.trakt5.entities.Show
import com.uwetrottmann.trakt5.enums.Extended
import io.reactivex.Maybe
import io.reactivex.Single
import me.banes.chris.tivi.ShowFetcher
import me.banes.chris.tivi.api.ItemWithIndex
import me.banes.chris.tivi.data.DatabaseTxRunner
import me.banes.chris.tivi.data.daos.PopularDao
Expand All @@ -29,15 +30,14 @@ import me.banes.chris.tivi.data.entities.PopularEntry
import me.banes.chris.tivi.data.entities.PopularListItem
import me.banes.chris.tivi.data.entities.TiviShow
import me.banes.chris.tivi.extensions.toRxSingle
import me.banes.chris.tivi.trakt.TraktShowFetcher
import me.banes.chris.tivi.util.AppRxSchedulers
import javax.inject.Inject

class PopularCall @Inject constructor(
databaseTxRunner: DatabaseTxRunner,
showDao: TiviShowDao,
popularDao: PopularDao,
private val traktShowFetcher: TraktShowFetcher,
private val showFetcher: ShowFetcher,
private val trakt: TraktV2,
schedulers: AppRxSchedulers
) : PaginatedEntryCallImpl<ItemWithIndex<Show>, PopularEntry, PopularListItem, PopularDao>(databaseTxRunner, showDao, popularDao, schedulers) {
Expand All @@ -55,6 +55,6 @@ class PopularCall @Inject constructor(
}

override fun loadShow(response: ItemWithIndex<Show>): Maybe<TiviShow> {
return traktShowFetcher.getShow(response.item.ids.trakt, response.item)
return showFetcher.loadShow(response.item.ids.trakt, response.item)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.uwetrottmann.trakt5.TraktV2
import com.uwetrottmann.trakt5.enums.Extended
import io.reactivex.Completable
import io.reactivex.Flowable
import me.banes.chris.tivi.actions.TiviActions
import me.banes.chris.tivi.ShowFetcher
import me.banes.chris.tivi.calls.Call
import me.banes.chris.tivi.data.daos.TiviShowDao
import me.banes.chris.tivi.data.entities.TiviShow
Expand All @@ -32,9 +32,9 @@ import javax.inject.Inject
class RelatedShowsCall @Inject constructor(
private val dao: TiviShowDao,
private val traktState: TraktState,
private val tiviActions: TiviActions,
private val trakt: TraktV2,
private val schedulers: AppRxSchedulers
private val schedulers: AppRxSchedulers,
private val showFetcher: ShowFetcher
) : Call<Long, List<TiviShow>> {
override fun refresh(param: Long): Completable {
return dao.getShowWithIdMaybe(param)
Expand All @@ -54,7 +54,7 @@ class RelatedShowsCall @Inject constructor(
return dao.getShowWithIdMaybe(param)
.subscribeOn(schedulers.database)
.flatMapPublisher { traktState.relatedShowsForTraktId(it.traktId!!) }
.doOnNext { it.forEach(tiviActions::updateShowFromTrakt) }
.doOnNext { it.forEach { showFetcher.loadShowAsync(it) } }
.flatMap(dao::getShowsWithTraktId)
.startWith(Flowable.just(emptyList()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ package me.banes.chris.tivi.trakt.calls

import io.reactivex.Completable
import io.reactivex.Flowable
import me.banes.chris.tivi.ShowFetcher
import me.banes.chris.tivi.calls.Call
import me.banes.chris.tivi.data.daos.TiviShowDao
import me.banes.chris.tivi.data.entities.TiviShow
import me.banes.chris.tivi.trakt.TraktShowFetcher
import me.banes.chris.tivi.util.AppRxSchedulers
import javax.inject.Inject

class ShowDetailsCall @Inject constructor(
private val dao: TiviShowDao,
private val traktShowFetcher: TraktShowFetcher,
private val showFetcher: ShowFetcher,
private val schedulers: AppRxSchedulers
) : Call<Long, TiviShow> {
override fun refresh(param: Long): Completable {
return dao.getShowWithIdMaybe(param)
.subscribeOn(schedulers.database)
.map(TiviShow::traktId)
.flatMapCompletable(traktShowFetcher::updateShow)
.flatMapCompletable(showFetcher::updateShow)
}

override fun data(param: Long): Flowable<TiviShow> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import com.uwetrottmann.trakt5.entities.TrendingShow
import com.uwetrottmann.trakt5.enums.Extended
import io.reactivex.Maybe
import io.reactivex.Single
import me.banes.chris.tivi.ShowFetcher
import me.banes.chris.tivi.data.DatabaseTxRunner
import me.banes.chris.tivi.data.daos.TiviShowDao
import me.banes.chris.tivi.data.daos.TrendingDao
import me.banes.chris.tivi.data.entities.TiviShow
import me.banes.chris.tivi.data.entities.TrendingEntry
import me.banes.chris.tivi.data.entities.TrendingListItem
import me.banes.chris.tivi.extensions.toRxSingle
import me.banes.chris.tivi.trakt.TraktShowFetcher
import me.banes.chris.tivi.util.AppRxSchedulers
import javax.inject.Inject

class TrendingCall @Inject constructor(
databaseTxRunner: DatabaseTxRunner,
showDao: TiviShowDao,
trendingDao: TrendingDao,
private val traktShowFetcher: TraktShowFetcher,
private val showFetcher: ShowFetcher,
private val trakt: TraktV2,
schedulers: AppRxSchedulers
) : PaginatedEntryCallImpl<TrendingShow, TrendingEntry, TrendingListItem, TrendingDao>(databaseTxRunner, showDao, trendingDao, schedulers) {
Expand All @@ -53,6 +53,6 @@ class TrendingCall @Inject constructor(
}

override fun loadShow(response: TrendingShow): Maybe<TiviShow> {
return traktShowFetcher.getShow(response.show.ids.trakt, response.show)
return showFetcher.loadShow(response.show.ids.trakt, response.show)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ import com.uwetrottmann.trakt5.entities.UserSlug
import com.uwetrottmann.trakt5.enums.Extended
import io.reactivex.Completable
import io.reactivex.Flowable
import me.banes.chris.tivi.ShowFetcher
import me.banes.chris.tivi.calls.ListCall
import me.banes.chris.tivi.data.DatabaseTxRunner
import me.banes.chris.tivi.data.daos.WatchedDao
import me.banes.chris.tivi.data.entities.WatchedEntry
import me.banes.chris.tivi.data.entities.WatchedListItem
import me.banes.chris.tivi.extensions.toRxSingle
import me.banes.chris.tivi.trakt.TraktShowFetcher
import me.banes.chris.tivi.util.AppRxSchedulers
import javax.inject.Inject

class WatchedCall @Inject constructor(
private val databaseTxRunner: DatabaseTxRunner,
private val watchDao: WatchedDao,
private val traktShowFetcher: TraktShowFetcher,
private val showFetcher: ShowFetcher,
private val trakt: TraktV2,
private val schedulers: AppRxSchedulers
) : ListCall<Unit, WatchedListItem> {
Expand All @@ -58,8 +58,10 @@ class WatchedCall @Inject constructor(
.toFlowable()
.flatMapIterable { it }
.flatMapMaybe { traktEntry ->
traktShowFetcher.getShow(traktEntry.show.ids.trakt, traktEntry.show)
.map { WatchedEntry(null, it.id!!, traktEntry.last_watched_at) }
showFetcher.loadShow(traktEntry.show.ids.trakt, traktEntry.show)
.map {
WatchedEntry(null, it.id!!, traktEntry.last_watched_at)
}
}
.toList()
.observeOn(schedulers.database)
Expand Down
1 change: 1 addition & 0 deletions show-fetcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ dependencies {
// TODO eventually I want these to be implementation deps
compile project(":trakt-show-fetcher")
compile project(":tmdb-show-fetcher")
implementation project(":data")
implementation project(":base")
}
Loading

0 comments on commit e75b9c2

Please sign in to comment.