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 1 commit
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public class MyActivity extends NaviActivity {
}
```

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

```java
myObservable
.bind(myView) //bind(myRxActivity or myRxFragment)
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment seems unnecessary.

.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 +100,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-rc-1036'
Copy link
Contributor

Choose a reason for hiding this comment

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

Kotlin 1.0 final got released, should update here.

}
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
31 changes: 31 additions & 0 deletions rxlifecycle-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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')

compile rootProject.ext.rxJava

compile rootProject.ext.appCompat

testCompile rootProject.ext.junit
testCompile rootProject.ext.mockito
testCompile rootProject.ext.robolectric
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this part of the project really need all these dependencies? I'm guessing it only needs the top two.

}

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
Copy link
Contributor

Choose a reason for hiding this comment

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

No capital 'k' here.

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,13 @@
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.ActivityLifecycleProvider
import com.trello.rxlifecycle.FragmentLifecycleProvider
import com.trello.rxlifecycle.RxLifecycle
import rx.Observable

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

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

fun <T> Observable<T>.bind(view: View): Observable<T> = this.compose<T>(RxLifecycle.bindView(view))
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be both bindToLifecycle() and bindUntilEvent() for these.

2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include ':rxlifecycle'
include ':rxlifecycle', ':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.

Could this be on a newline to match the rest of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course!
And since kotlin just released, i have to upgrade it

include ':rxlifecycle-components'
include ':rxlifecycle-navi'
include ':rxlifecycle-sample'