Skip to content

Commit

Permalink
Rx Extensions added
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszWolkowicz committed Aug 12, 2019
1 parent c14b3f1 commit c715811
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
15 changes: 12 additions & 3 deletions androidextensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'

// Reactive extensions
implementation "io.reactivex.rxjava2:rxjava:$rx_java"
implementation "io.reactivex.rxjava2:rxandroid:$rx_java_android"

// KTX
implementation "androidx.core:core-ktx:$android_core_ktx"
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_reactivestreams_ktx"
implementation "androidx.collection:collection-ktx:$collection_ktx"
implementation "androidx.fragment:fragment-ktx:$fragment_ktx"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
compile "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wolkowiczmateusz.androidextensions

import androidx.lifecycle.LiveData
import io.reactivex.BackpressureStrategy
import io.reactivex.Observable
import io.reactivex.Single
import androidx.lifecycle.LiveDataReactiveStreams

fun <T> Observable<T>.toLiveData(backPressureStrategy: BackpressureStrategy = BackpressureStrategy.BUFFER): LiveData<T> {
return LiveDataReactiveStreams.fromPublisher(this.toFlowable(backPressureStrategy))
}

fun <T> Single<T>.toLiveData(): LiveData<T> {
return LiveDataReactiveStreams.fromPublisher(this.toFlowable()) // toFlowable 230ms
}
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation "androidx.core:core-ktx:$android_core_ktx"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.41'
ext {
kotlin_version = '1.3.41'
rx_java = '2.2.9'
rx_java_android = '2.1.1'
android_core_ktx = '1.0.2'
collection_ktx = '1.0.0'
fragment_ktx = '1.0.0'
lifecycle_reactivestreams_ktx = '2.1.0-rc01'
}
repositories {
google()
jcenter()
Expand Down

0 comments on commit c715811

Please sign in to comment.