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 interop module #118

Merged
merged 16 commits into from
Oct 22, 2017
Merged

RxLifecycle interop module #118

merged 16 commits into from
Oct 22, 2017

Conversation

bangarharshit
Copy link
Contributor

@bangarharshit bangarharshit commented Oct 21, 2017

RxLifecycle interop module added.

Resolves #82

@CLAassistant
Copy link

CLAassistant commented Oct 21, 2017

CLA assistant check
All committers have signed the CLA.

@bangarharshit
Copy link
Contributor Author

Looks like the build timed out. Looking into the log

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

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

Good start. Just a note for something I noticed in a few places. It should be spelled RxLifecycle, not RXLifeCycle. Please update that in any places I didn't comment on as well


private static final Object DEFAULT_THROWAWAY_OBJECT = new Object();

static <E> ScopeProvider bindLifecycle(final LifecycleProvider<E> provider) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These methods should both be public

Copy link
Collaborator

Choose a reason for hiding this comment

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

On further thinking, I think we should call both of these methods from for consistency with the rest of AutoDispose

* as normal terminal event. There is no mapping to {@link LifecycleEndedException} and in such
* cases the stream is normally disposed </em>
*/
public final class RXLifeCycleInterop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be called RxLifecycleInterop

/**
* Interop class for {@link RxLifecycle}. It provides static utility methods to convert {@link
* LifecycleProvider} to {@link ScopeProvider}
* <p> There are several static utility converter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: new line for the <p>, remove the space after

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quick check - What is the code style? My formatter did it automatically.

Copy link
Collaborator

Choose a reason for hiding this comment

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

code style is basically the square code style - https://github.com/square/java-code-styles

import io.reactivex.Maybe;

/**
* Interop class for {@link RxLifecycle}. It provides static utility methods to convert {@link
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: don't link RxLifecycle since you're talking about the library and not the class. Same with the other link below

* LifecycleProvider#bindToLifecycle()} and {@link #bindUntilEvent(LifecycleProvider, Object)} for
* {@link LifecycleProvider#bindUntilEvent(Object)} </p>
*
* <em>Unlike {@link AutoDispose}, {@link RxLifecycle} treats the {@link OutsideLifecycleException}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: remove the autodispose bit at the beginning

also, only make the beginning emphasized. Do something like:

<em>Note:</em> RxLifecycle treats...


import static com.google.common.truth.Truth.assertThat;

public class RXLifeCycleInteropTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

RxLifecycleInteropTest

}
};

private LifeCycleProviderImpl lifeCycleProvider = new LifeCycleProviderImpl();
Copy link
Collaborator

Choose a reason for hiding this comment

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

lifecycleProvider


@Before
public void setup() {
lifeCycleProvider.onCreate();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's mark this explicitly in each test

settings.gradle Outdated
@@ -25,3 +25,5 @@ include ':autodispose'
include ':autodispose-kotlin'
include ':sample'
include ':test-utils'
include 'autodispose-rxlifecycle-interop'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's call this just autodispose-rxlifecycle, and make the package name com.uber.autodispose.rxlifecycle.

}

@Test
public void bindLifecycle_errorTermination_unsubscribe() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the method name say something about subscribing outside of lifecycle bounds?

@@ -25,7 +25,7 @@ dependencies {
testApt deps.build.nullAway

compile project(':autodispose')
compile 'com.trello.rxlifecycle2:rxlifecycle:2.2.0'
api deps.rx.lifecycle
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be compile as we're still on AGP 2.3.3

@@ -0,0 +1,3 @@
POM_NAME=AutoDispose (RXLifeCycle Interop)
Copy link
Collaborator

Choose a reason for hiding this comment

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

RxLifecycle

@@ -0,0 +1,3 @@
POM_NAME=AutoDispose (RXLifeCycle Interop)
POM_ARTIFACT_ID=autodispose-rxlifecycle-interop
Copy link
Collaborator

Choose a reason for hiding this comment

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

autodispose-rxlifecycle

@@ -57,7 +57,8 @@ def misc = [

def rx = [
android: 'io.reactivex.rxjava2:rxandroid:2.0.1',
java: 'io.reactivex.rxjava2:rxjava:2.1.0'
java: 'io.reactivex.rxjava2:rxjava:2.1.0',
lifecycle: 'com.trello.rxlifecycle2:rxlifecycle:2.2.0'
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be separate, this block is just for reactivex. Probably under misc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed top-level comments - renaming and dependencies.gradle in cbf3e10

@ZacSweers ZacSweers changed the title RX lifecycle interop module added for autodipose RxLifecycle interop module Oct 21, 2017
@ZacSweers
Copy link
Collaborator

FYI for future reference, it's much easier for the reviewer if you address each comment (± group of comments if they go together) in individual commits and link them in a reply, that way it's easy to connect the changes :)

@bangarharshit
Copy link
Contributor Author

Will take care of it from future.

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

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

Almost there!

* methods such as {@link #bindLifecycle(LifecycleProvider)} for {@link
* LifecycleProvider#bindToLifecycle()} and {@link #bindUntilEvent(LifecycleProvider, Object)} for
* {@link LifecycleProvider#bindUntilEvent(Object)} </p>
* Interop class for RxLifecycle. It provides static utility methods to convert {@link
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: remove class

throw new AssertionError("No Instances");
}

private static final Object DEFAULT_THROWAWAY_OBJECT = new Object();

static <E> ScopeProvider bindLifecycle(final LifecycleProvider<E> provider) {
public static <E> ScopeProvider fromBindLifecycle(final LifecycleProvider<E> provider) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant just call them from, not fromBindLifecycle or anything

*/
public final class RXLifeCycleInterop {
public final class RXLifecycleInterop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rx, not RX

import org.junit.Test;

import static com.google.common.truth.Truth.assertThat;

public class RXLifeCycleInteropTest {
public class RXLifecycleInteropTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rx, not RX

* methods such as {@link #fromBindLifecycle(LifecycleProvider)} for {@link
* LifecycleProvider#bindToLifecycle()} and {@link #fromBindUntilEvent(LifecycleProvider, Object)} for
* {@link LifecycleProvider#bindUntilEvent(Object)}.
* </p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this, add a <p> below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - 7c73cc2. Code review in github can be a pain.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Much better than phabricator though! :)

@@ -1,3 +1,3 @@
POM_NAME=AutoDispose (RXLifeCycle Interop)
POM_NAME=AutoDispose (RXLifecycle Interop)
Copy link
Collaborator

Choose a reason for hiding this comment

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

RxLifecycle

@@ -79,7 +79,7 @@ public void bindLifecycle_outsideLifecycleBound_unsubscribe() {
source.onNext(2);
o.assertNoMoreEvents();
assertThat(
source.hasObservers()).isFalse(); // Because RXLifeCycle treats lifecycle ended exception as terminal event.
source.hasObservers()).isFalse(); // Because RXLifecycle treats lifecycle ended exception as terminal event.
Copy link
Collaborator

Choose a reason for hiding this comment

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

RxLifecycle

@@ -52,13 +52,13 @@ def kotlin = [
def misc = [
errorProneAnnotations: "com.google.errorprone:error_prone_annotations:${versions.errorProne}",
javaxExtras: "com.uber.javaxextras:javax-extras:0.1.0",
jsr305: 'com.google.code.findbugs:jsr305:3.0.2'
jsr305: 'com.google.code.findbugs:jsr305:3.0.2',
lifecycle: 'com.trello.rxlifecycle2:rxlifecycle:2.2.0'
Copy link
Collaborator

Choose a reason for hiding this comment

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

rxlifecycle

throw new AssertionError("No Instances");
}

private static final Object DEFAULT_THROWAWAY_OBJECT = new Object();

public static <E> ScopeProvider fromBindLifecycle(final LifecycleProvider<E> provider) {
public static <E> ScopeProvider fromLifecycle(final LifecycleProvider<E> provider) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

from(...). Same with the one below

@@ -28,7 +28,7 @@ private RxLifecycleInterop() {

private static final Object DEFAULT_THROWAWAY_OBJECT = new Object();

public static <E> ScopeProvider fromLifecycle(final LifecycleProvider<E> provider) {
public static <E> ScopeProvider from(final LifecycleProvider<E> provider) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missed this in my earlier comments, but these two methods should each have docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c2e63ff

@@ -40,6 +56,22 @@ private RxLifecycleInterop() {
};
}

/**
* Converter for transforming {@link LifecycleProvider} to {@link ScopeProvider}.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: fix the double space after for in this and the one above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - b373d42

@bangarharshit
Copy link
Contributor Author

bangarharshit commented Oct 21, 2017

For some weird reason - build is getting a timeout at accept license. - raw log. I am not making any change in the .travis.yml file.

Master build on my fork is also facing the same issue.

@ZacSweers
Copy link
Collaborator

ZacSweers commented Oct 21, 2017

Licenses in the sdk seem to have changed. Can you try changing the travis yml file with the following patch?

Index: .travis.yml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- .travis.yml	(revision 32e5c564a2da708566d7ba876eb86d84247789a5)
+++ .travis.yml	(revision )
@@ -12,7 +12,8 @@
 before_install:
   # Install SDK license so Android Gradle plugin can install deps.
   - mkdir "$ANDROID_HOME/licenses" || true
-  - echo "$LICENSES_SHA" > "$ANDROID_HOME/licenses/android-sdk-license"
+  - echo "$LICENSES_HASH" > "$ANDROID_HOME/licenses/android-sdk-license"
+  - echo "$LICENSES_HASH_TWO" >> "$ANDROID_HOME/licenses/android-sdk-license"
   # Install the rest of tools (e.g., avdmanager)
   - sdkmanager tools
   # Install the system image

*/

/**
* Interop for RxLifecycle.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please write a more detailed doc, this is the doc for the entire package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more details and license - e463be6

@ZacSweers
Copy link
Collaborator

Confirmed the above patch fixes it in #119. If you want to just include that in your PR that should fix it, and I'll close out the other one

@ZacSweers
Copy link
Collaborator

Merged that other one, just rebase your changes here

@bangarharshit
Copy link
Contributor Author

Thanks. One quick question - do I need to copy license in each file or is it taken care of while pushing?

@ZacSweers
Copy link
Collaborator

Each file will need a license header yeah. You can install a profile into intelliJ to automatically add them

@@ -15,7 +15,9 @@
*/

/**
* Interop for RxLifecycle.
* Interop for RxLifecycle. It could understand RxLifecycle's
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can phrase this better, doesn't have to be too wordy. Let's do

AutoDispose extensions for interop with RxLifecycle. This namely supports {@link LifecycleProvider}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - 7f3e1a8

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

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

Nice work! Pending CI results now :)

@ZacSweers ZacSweers merged commit 60d95bf into uber:master Oct 22, 2017
@ZacSweers
Copy link
Collaborator

Thanks Harshit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants