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

rxlifecycle-kotlin module added with bind() syntax #78

Merged
merged 2 commits into from
Feb 16, 2016
Merged
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public class MyActivity extends NaviActivity {
}
```

If you want some kotlin goodness, you can use bind() syntax

```java
myObservable
.bindToLifecycle(myView)
.subscribe { }

```

```java
myObservable
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just make this a single example instead of two.

Copy link
Contributor

Choose a reason for hiding this comment

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

Eh, can deal with this post-merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You want me to create example android project?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah. I was just saying that this is two separate code samples but could just be wrapped into one.

.bindUntilEvent(myRxActivity, STOP)
.subscribe { }

Copy link
Contributor

Choose a reason for hiding this comment

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

Exatra newline here.

```

## Unsubscription

RxLifecycle does not actually unsubscribe the sequence. It terminates it by emitting `onCompleted()`, which ends the
Expand All @@ -91,6 +107,9 @@ compile 'com.trello:rxlifecycle-components:0.4.0'

// If you want to use Navi for providers
compile 'com.trello:rxlifecycle-navi:0.4.0'

// If you wat to use Kotlin syntax
compile 'com.trello:rxlifecycle-kotlin:0.4.0'
```

## License
Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
buildscript {
ext {
//version here to share between build script and projects
//todo https://github.com/JetBrains/kotlin/pull/775 : remove if it will be merged
verKotlin = '1.0.0'
}
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$verKotlin"
}
}

Expand All @@ -22,6 +28,7 @@ ext {
rxJava = 'io.reactivex:rxjava:1.0.16'
rxBinding = 'com.jakewharton.rxbinding:rxbinding:0.3.0'
navi = 'com.trello:navi:0.1.3'
kotlinStdlib = "org.jetbrains.kotlin:kotlin-stdlib:$verKotlin"
appCompat = 'com.android.support:appcompat-v7:23.1.1'
junit = 'junit:junit:4.12'
mockito = 'org.mockito:mockito-core:1.10.19'
Expand Down
23 changes: 23 additions & 0 deletions rxlifecycle-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
}
}

repositories {
mavenCentral()
}

dependencies {
compile kotlinStdlib
compile project(':rxlifecycle')
}

apply from: "$rootDir/gradle/artifacts.gradle"
apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
4 changes: 4 additions & 0 deletions rxlifecycle-kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POM_NAME=RxLifecycle-kotlin
POM_DESCRIPTION=RxLifecycle-kotlin
POM_ARTIFACT_ID=rxlifecycle-kotlin
POM_PACKAGING=aar
13 changes: 13 additions & 0 deletions rxlifecycle-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest package="com.trello.rxlifecycle.kotlin" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trello.rxlifecycle.kotlin
Copy link
Contributor

Choose a reason for hiding this comment

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

Should have copyright at top of file.


import android.view.View
import com.trello.rxlifecycle.*
import rx.Observable

fun <T> Observable<T>.bindToLifecycle(activity: ActivityLifecycleProvider): Observable<T> = this.compose<T>(activity.bindToLifecycle<T>())

fun <T> Observable<T>.bindUntilEvent(activity: ActivityLifecycleProvider, event: ActivityEvent): Observable<T> = this.compose<T>(activity.bindUntilEvent(event))

fun <T> Observable<T>.bindToLifecycle(fragment: FragmentLifecycleProvider): Observable<T> = this.compose<T>(fragment.bindToLifecycle<T>())

fun <T> Observable<T>.bindUntilEvent(fragment: FragmentLifecycleProvider, event: FragmentEvent): Observable<T> = this.compose<T>(fragment.bindUntilEvent(event))

fun <T> Observable<T>.bindToLifecycle(view: View): Observable<T> = this.compose<T>(RxLifecycle.bindView(view))
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include ':rxlifecycle'
include ':rxlifecycle-components'
include ':rxlifecycle-navi'
include ':rxlifecycle-kotlin'
include ':rxlifecycle-sample'