Skip to content
Permalink
Browse files

Isolate RxJava to just data layer

  • Loading branch information...
chrisbanes committed Aug 1, 2019
1 parent 71d668c commit 376b3bcc7c8d7c0e1c66014eff535f36c7df18ab
Showing with 183 additions and 467 deletions.
  1. +0 −11 app/build.gradle
  2. +0 −31 app/src/main/java/app/tivi/appinitializers/RxAndroidInitializer.kt
  3. +14 −9 app/src/main/java/app/tivi/home/HomeActivityViewModel.kt
  4. +18 −15 app/src/main/java/app/tivi/home/search/SearchViewModel.kt
  5. +3 −15 app/src/main/java/app/tivi/inject/AppModule.kt
  6. +0 −5 app/src/main/java/app/tivi/inject/AppModuleBinds.kt
  7. +14 −0 base-android/src/main/java/app/tivi/extensions/LiveDataExtensions.kt
  8. +0 −75 base-android/src/main/java/app/tivi/util/ObservableLiveData.kt
  9. +0 −1 base/build.gradle
  10. +0 −28 base/src/main/java/app/tivi/extensions/RxExtensions.kt
  11. +0 −25 base/src/main/java/app/tivi/util/AppRxSchedulers.kt
  12. +17 −7 base/src/main/java/app/tivi/util/{RxLoadingCounter.kt → ObservableLoadingCounter.kt}
  13. +2 −7 buildSrc/src/main/java/app/tivi/buildsrc/dependencies.kt
  14. +0 −7 common-entrygrid/build.gradle
  15. +0 −2 common-ui/build.gradle
  16. +0 −1 data-android/build.gradle
  17. +4 −10 data/build.gradle
  18. +2 −8 interactors/build.gradle
  19. +4 −6 interactors/src/main/java/app/tivi/interactors/Interactor.kt
  20. +6 −11 ...ctors/src/main/java/app/tivi/interactors/{ObserveFollowedShows.kt → ObservePagedFollowedShows.kt}
  21. +4 −9 interactors/src/main/java/app/tivi/interactors/ObservePagedPopularShows.kt
  22. +4 −9 interactors/src/main/java/app/tivi/interactors/ObservePagedTrendingShows.kt
  23. +4 −9 interactors/src/main/java/app/tivi/interactors/ObserveWatchedShows.kt
  24. +0 −2 tmdb/build.gradle
  25. +0 −3 trakt-auth/build.gradle
  26. +7 −5 trakt-auth/src/main/java/app/tivi/trakt/TraktAuthModule.kt
  27. +27 −27 trakt-auth/src/main/java/app/tivi/trakt/TraktManager.kt
  28. +1 −11 ui-discover/build.gradle
  29. +10 −5 ui-discover/src/main/java/app/tivi/home/discover/DiscoverViewModel.kt
  30. +0 −12 ui-episodedetails/build.gradle
  31. +0 −12 ui-followed/build.gradle
  32. +24 −24 ui-followed/src/main/java/app/tivi/home/followed/FollowedViewModel.kt
  33. +1 −11 ui-popular/build.gradle
  34. +0 −12 ui-showdetails/build.gradle
  35. +0 −12 ui-trending/build.gradle
  36. +1 −11 ui-watched/build.gradle
  37. +16 −19 ui-watched/src/main/java/app/tivi/home/watched/WatchedViewModel.kt
@@ -182,13 +182,9 @@ dependencies {
implementation project(":ui-trending")

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.Paging.rxjava2

implementation Libs.AndroidX.appcompat
implementation Libs.AndroidX.browser
implementation Libs.AndroidX.palette
@@ -208,15 +204,10 @@ dependencies {

implementation Libs.timber

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

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

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

implementation Libs.Dagger.androidSupport
@@ -235,8 +226,6 @@ dependencies {

implementation Libs.gravitySnapHelper

debugImplementation Libs.rxLint

implementation Libs.Google.firebaseCore
implementation Libs.Google.crashlytics

This file was deleted.

@@ -28,6 +28,8 @@ import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import net.openid.appauth.AuthorizationException
import net.openid.appauth.AuthorizationResponse
@@ -48,16 +50,19 @@ class HomeActivityViewModel @AssistedInject constructor(
observeUserDetails(ObserveUserDetails.Params("me"))
}

traktManager.state
.distinctUntilChanged()
.doOnNext {
if (it == TraktAuthState.LOGGED_IN) {
viewModelScope.launchInteractor(updateUserDetails,
UpdateUserDetails.Params("me", false))
viewModelScope.launch {
traktManager.state
.distinctUntilChanged()
.onEach {
if (it == TraktAuthState.LOGGED_IN) {
viewModelScope.launchInteractor(updateUserDetails,
UpdateUserDetails.Params("me", false))
}
}
.execute {
copy(authState = it() ?: TraktAuthState.LOGGED_OUT)
}
}.execute {
copy(authState = it() ?: TraktAuthState.LOGGED_OUT)
}
}
}

fun onAuthResponse(
@@ -26,42 +26,45 @@ import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import io.reactivex.subjects.BehaviorSubject
import hu.akarnokd.kotlin.flow.PublishSubject
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch
import java.util.concurrent.TimeUnit

class SearchViewModel @AssistedInject constructor(
@Assisted initialState: SearchViewState,
private val searchShows: SearchShows,
tmdbManager: TmdbManager
) : TiviMvRxViewModel<SearchViewState>(initialState) {
private val searchQuery = BehaviorSubject.create<String>()
private val searchQuery = PublishSubject<String>()

init {
searchQuery.debounce(300, TimeUnit.MILLISECONDS)
.subscribe({
viewModelScope.launchInteractor(searchShows, SearchShows.Params(it))
}, {
// TODO: onError
}).disposeOnClear()
viewModelScope.launch {
searchQuery.debounce(300)
.collect {
viewModelScope.launchInteractor(searchShows, SearchShows.Params(it))
}
}

viewModelScope.launch {
tmdbManager.imageProviderFlow
.execute { copy(tmdbImageUrlProvider = it() ?: tmdbImageUrlProvider) }
}

searchShows.observe().execute {
copy(searchResults = it())
viewModelScope.launch {
searchShows.observe().execute {
copy(searchResults = it())
}
}
}

fun setSearchQuery(query: String) {
searchQuery.onNext(query)
viewModelScope.launch {
searchQuery.emit(query)
}
}

fun clearQuery() {
searchQuery.onNext("")
}
fun clearQuery() = setSearchQuery("")

@AssistedInject.Factory
interface Factory {
@@ -22,14 +22,10 @@ import androidx.preference.PreferenceManager
import app.tivi.BuildConfig
import app.tivi.TiviApplication
import app.tivi.util.AppCoroutineDispatchers
import app.tivi.util.AppRxSchedulers
import dagger.Module
import dagger.Provides
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.rx2.asCoroutineDispatcher
import org.threeten.bp.ZoneId
import org.threeten.bp.format.DateTimeFormatter
import java.io.File
@@ -50,17 +46,9 @@ class AppModule {

@Singleton
@Provides
fun provideRxSchedulers(): AppRxSchedulers = AppRxSchedulers(
io = Schedulers.io(),
computation = Schedulers.computation(),
main = AndroidSchedulers.mainThread()
)

@Singleton
@Provides
fun provideCoroutineDispatchers(schedulers: AppRxSchedulers) = AppCoroutineDispatchers(
io = schedulers.io.asCoroutineDispatcher(),
computation = schedulers.computation.asCoroutineDispatcher(),
fun provideCoroutineDispatchers() = AppCoroutineDispatchers(
io = Dispatchers.IO,
computation = Dispatchers.Default,
main = Dispatchers.Main
)

@@ -24,7 +24,6 @@ import app.tivi.appinitializers.AppInitializer
import app.tivi.appinitializers.EmojiInitializer
import app.tivi.appinitializers.EpoxyInitializer
import app.tivi.appinitializers.PreferencesInitializer
import app.tivi.appinitializers.RxAndroidInitializer
import app.tivi.appinitializers.ThreeTenBpInitializer
import app.tivi.appinitializers.TimberInitializer
import app.tivi.settings.TiviPreferences
@@ -63,10 +62,6 @@ abstract class AppModuleBinds {
@IntoSet
abstract fun provideEpoxyInitializer(bind: EpoxyInitializer): AppInitializer

@Binds
@IntoSet
abstract fun provideRxAndroidInitializer(bind: RxAndroidInitializer): AppInitializer

@Binds
@IntoSet
abstract fun provideThreeTenAbpInitializer(bind: ThreeTenBpInitializer): AppInitializer
@@ -19,11 +19,25 @@ package app.tivi.extensions
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow

inline fun <T> LiveData<T>.observeK(owner: LifecycleOwner, crossinline observer: (T?) -> Unit) {
this.observe(owner, Observer { observer(it) })
}

inline fun <T> LiveData<T>.observeNotNull(owner: LifecycleOwner, crossinline observer: (T) -> Unit) {
this.observe(owner, Observer { it?.run(observer) })
}

fun <T> LiveData<T>.asFlow(): Flow<T> {
return channelFlow {
value?.also { send(it) }
val observer = Observer<T> { v -> offer(v) }
observeForever(observer)
awaitClose {
removeObserver(observer)
}
}
}

This file was deleted.

@@ -23,7 +23,6 @@ dependencies {
api Libs.Kotlin.stdlib

api Libs.Coroutines.core
api Libs.Coroutines.rx2
api Libs.kotlinFlowExtensions

api Libs.Dagger.dagger

This file was deleted.

This file was deleted.

0 comments on commit 376b3bc

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