Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxJava3 support #685

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions docs/rxjava3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Mavericks + RxJava3

[//]: # (TODO refine the documentation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you planning to address this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently in the process of building an rxjava demo app, and as part of that, I had intended to create comprehensive documentation that includes various examples taken directly from the demo itself, However, I apologize for not including it at this time. I'll also add a guide on migration from rxjava2 to rxjava3.


MvRx 1.x was designed to work well with RxJava 2.

However, Mavericks now uses coroutines internally.

RxJava 3 compatibility is available via the `mavericks-rxjava3` artifact.

To use it, use `BaseMvRxViewModel` instead of `MavericksViewModel`. Doing so will give you access to `execute` extensions on `Single<T>` and `Observable<T>` as well as all other MvRx 1.x APIs.
2 changes: 1 addition & 1 deletion gradle/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Mostly from https://nolambda.stream/posts/jacoco-setup-for-multi-module-project/
def coveredProjectNames = ["mvrx", "mvrx-compose", "mvrx-mocking", "mvrx-navigation", "mvrx-hilt", "mvrx-rxjava2"]
def coveredProjectNames = ["mvrx", "mvrx-compose", "mvrx-mocking", "mvrx-navigation", "mvrx-hilt", "mvrx-rxjava2", "mvrx-rxjava3"]
def coveredProjects = subprojects.findAll( project -> {
coveredProjectNames.contains(project.name)
})
Expand Down
12 changes: 9 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ activity = "androidx.activity:activity:_"
activityCompose = "androidx.activity:activity-compose:_"
appcompat = "androidx.appcompat:appcompat:_"
cardview = "androidx.cardview:cardview:_"
material = "com.google.android.material:material:_"
constraintlayout = "androidx.constraintlayout:constraintlayout:_"
coordinatorLayout = "androidx.coordinatorlayout:coordinatorlayout:_"
coreKtx = "androidx.core:core-ktx:_"
Expand Down Expand Up @@ -59,12 +60,17 @@ picasso = "com.squareup.picasso:picasso:_"
recyclerview = "androidx.recyclerview:recyclerview:_"
retrofit = "com.squareup.retrofit2:retrofit:_"
retrofitMoshi = "com.squareup.retrofit2:converter-moshi:_"
retrofitRxJava = "com.squareup.retrofit2:adapter-rxjava2:_"
retrofitRxJava2 = "com.squareup.retrofit2:adapter-rxjava2:_"
retrofitRxJava3 = "com.squareup.retrofit2:adapter-rxjava3:_"
coil = "io.coil-kt:coil:_"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add coil?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one I added as part of rxjava demo, which is still in progress


roomRuntime = "androidx.room:room-runtime:_"
roomRxJava = "androidx.room:room-rxjava2:_"
runtimeKtx = "androidx.lifecycle:lifecycle-runtime-ktx:_"
rxAndroid = "io.reactivex.rxjava2:rxandroid:_"
rxJava = "io.reactivex.rxjava2:rxjava:_"
rxJava2 = "io.reactivex.rxjava2:rxjava:_"
rxAndroid2 = "io.reactivex.rxjava2:rxandroid:_"
rxJava3 = "io.reactivex.rxjava3:rxjava:_"
rxAndroid3 = "io.reactivex.rxjava3:rxandroid:_"
viewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:_"
viewModelCompose = "androidx.lifecycle:lifecycle-viewmodel-compose:_"
viewModelSavedState = "androidx.lifecycle:lifecycle-viewmodel-savedstate:_"
Expand Down
2 changes: 1 addition & 1 deletion mvrx-rxjava2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {

dependencies {
api project(':mvrx')
api libs.rxJava
api libs.rxJava2

implementation libs.fragment
implementation libs.lifecycleCommon
Expand Down
1 change: 1 addition & 0 deletions mvrx-rxjava3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions mvrx-rxjava3/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "com.vanniktech.maven.publish"

tasks.withType(KotlinCompile).all {
kotlinOptions {
freeCompilerArgs += [
'-opt-in=com.airbnb.mvrx.InternalMavericksApi',
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
'-opt-in=com.airbnb.mvrx.ExperimentalMavericksApi',
]
}
}

android {
resourcePrefix "mvrx_"

testOptions {
unitTests {
includeAndroidResources = true
all {
jacoco {
includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
}
}
}
}

dependencies {
api project(':mvrx')
api libs.rxJava3

implementation libs.fragment
implementation libs.lifecycleCommon
implementation libs.runtimeKtx

testImplementation project(':mvrx-testing')
testImplementation libs.junit
testImplementation libs.appcompat
testImplementation libs.kotlinCoroutinesTest
testImplementation libs.mockito
testImplementation libs.roboeletric
}
4 changes: 4 additions & 0 deletions mvrx-rxjava3/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POM_NAME=Mavericks
POM_ARTIFACT_ID=mavericks-rxjava2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong artifact id

POM_PACKAGING=aar
GROUP=com.airbnb.android
5 changes: 5 additions & 0 deletions mvrx-rxjava3/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<manifest package="com.airbnb.mvrx.rxjava2">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this is needed. declare the package name in the build.gradle file via the namespace property


<application />

</manifest>
12 changes: 12 additions & 0 deletions mvrx-rxjava3/src/main/kotlin/com/airbnb/mvrx/BaseMvRxFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.airbnb.mvrx

import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment

/**
* Make your base Fragment class extend this to get MvRx functionality.
*
* This is necessary for the view model delegates and persistence to work correctly.
*/
@Deprecated("You no longer need a base MvRxFragment. All you need to do is make your Fragment implement MavericksView.")
abstract class BaseMvRxFragment(@LayoutRes contentLayoutId: Int = 0) : Fragment(contentLayoutId), MvRxView
Loading