Skip to content

Commit

Permalink
RxWear methods are now non-static for better testability. Dependency …
Browse files Browse the repository at this point in the history
…updates. Use Retrolambda to simplify code. Refactoring.
  • Loading branch information
patloew committed Oct 29, 2016
1 parent 74fa072 commit 4889d0e
Show file tree
Hide file tree
Showing 51 changed files with 1,467 additions and 1,504 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ android:
- tools

# The BuildTools version used by your project
- build-tools-23.0.2
- build-tools-25.0.0

# The SDK version used to compile your project
- android-23
- android-25

# Additional components
- extra-google-google_play_services
Expand All @@ -23,8 +23,13 @@ android:
before_install:
- export JAVA8_HOME=/usr/lib/jvm/java-8-oracle
- export JAVA_HOME=$JAVA8_HOME
after_success:
- bash <(curl -s https://codecov.io/bash)
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
script:
- ./gradlew build jacocoTestReport assembleAndroidTest
- ./gradlew connectedCheck
cache:
directories:
- $HOME/.gradle/caches/
Expand Down
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.2.2'

classpath 'me.tatarka:gradle-retrolambda:3.3.0-beta4'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
classpath 'me.tatarka:gradle-retrolambda:3.3.1'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.3"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"

classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
34 changes: 23 additions & 11 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'jacoco-android'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.patloew.rxwear'
version = '1.2.0'
version = '1.3.0'
project.archivesBaseName = 'rxwear'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 3
versionName "1.2.0"
targetSdkVersion 25
versionCode 4
versionName "1.3.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
}

retrolambda {
javaVersion JavaVersion.VERSION_1_6
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
compile 'io.reactivex:rxjava:1.2.1'
compile 'com.google.android.gms:play-services-wearable:9.8.0'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile "org.powermock:powermock-module-junit4:1.6.4"
testCompile "org.powermock:powermock-module-junit4-rule:1.6.4"
testCompile "org.powermock:powermock-api-mockito:1.6.4"
testCompile "org.powermock:powermock-module-junit4:1.6.5"
testCompile "org.powermock:powermock-api-mockito:1.6.5"
}

task generateSourcesJar(type: Jar) {
Expand Down
14 changes: 5 additions & 9 deletions library/src/main/java/com/patloew/rxwear/BaseObservable.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import rx.Observable;
import rx.Subscriber;
import rx.functions.Action0;
import rx.subscriptions.Subscriptions;

/* Copyright (C) 2015 Michał Charmas (http://blog.charmas.pl)
Expand All @@ -32,7 +31,7 @@
* FILE MODIFIED by Patrick Löwenstein, 2016
*
*/
public abstract class BaseObservable<T> extends BaseRx<T> implements Observable.OnSubscribe<T> {
abstract class BaseObservable<T> extends BaseRx<T> implements Observable.OnSubscribe<T> {

protected BaseObservable(@NonNull RxWear rxWear, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand All @@ -48,13 +47,10 @@ public final void call(Subscriber<? super T> subscriber) {
subscriber.onError(ex);
}

subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
subscriber.add(Subscriptions.create(() -> {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
}));
}
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/java/com/patloew/rxwear/BaseRx.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
* FILE MODIFIED by Patrick Löwenstein, 2016
*
*/
public abstract class BaseRx<T> {
abstract class BaseRx<T> {
private final Context ctx;
private final Api<? extends Api.ApiOptions.NotRequiredOptions>[] services;
private final Scope[] scopes;
private final Long timeoutTime;
private final TimeUnit timeoutUnit;

protected BaseRx(@NonNull RxWear rxWear, Long timeout, TimeUnit timeUnit) {
this.ctx = rxWear.getContext();
this.ctx = rxWear.ctx;
this.services = new Api[] {Wearable.API };
this.scopes = null;

if(timeout != null && timeUnit != null) {
this.timeoutTime = timeout;
this.timeoutUnit = timeUnit;
} else {
this.timeoutTime = RxWear.getDefaultTimeout();
this.timeoutUnit = RxWear.getDefaultTimeoutUnit();
this.timeoutTime = rxWear.timeoutTime;
this.timeoutUnit = rxWear.timeoutUnit;
}
}

Expand Down
14 changes: 5 additions & 9 deletions library/src/main/java/com/patloew/rxwear/BaseSingle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import rx.Single;
import rx.SingleSubscriber;
import rx.functions.Action0;
import rx.subscriptions.Subscriptions;

/* Copyright (C) 2015 Michał Charmas (http://blog.charmas.pl)
Expand All @@ -35,7 +34,7 @@
* FILE MODIFIED by Patrick Löwenstein, 2016
*
*/
public abstract class BaseSingle<T> extends BaseRx<T> implements Single.OnSubscribe<T> {
abstract class BaseSingle<T> extends BaseRx<T> implements Single.OnSubscribe<T> {

protected BaseSingle(@NonNull RxWear rxWear, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand All @@ -55,13 +54,10 @@ public final void call(SingleSubscriber<? super T> subscriber) {
subscriber.onError(ex);
}

subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
subscriber.add(Subscriptions.create(() -> {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
}));
}
Expand Down
113 changes: 113 additions & 0 deletions library/src/main/java/com/patloew/rxwear/Capability.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.patloew.rxwear;

import android.net.Uri;
import android.support.annotation.NonNull;

import com.google.android.gms.common.api.Status;
import com.google.android.gms.wearable.CapabilityInfo;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Single;

/* Copyright 2016 Patrick Löwenstein
*
* 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. */
public class Capability {

private final RxWear rxWear;

Capability(RxWear rxWear) {
this.rxWear = rxWear;
}

// listen

public Observable<CapabilityInfo> listen(@NonNull String capability) {
return listenInternal(capability, null, null, null, null);
}

public Observable<CapabilityInfo> listen(@NonNull String capability, long timeout, @NonNull TimeUnit timeUnit) {
return listenInternal(capability, null, null, timeout, timeUnit);
}

public Observable<CapabilityInfo> listen(@NonNull Uri uri, int filterType) {
return listenInternal(null, uri, filterType, null, null);
}

public Observable<CapabilityInfo> listen(@NonNull Uri uri, int filterType, long timeout, @NonNull TimeUnit timeUnit) {
return listenInternal(null, uri, filterType, timeout, timeUnit);
}

private Observable<CapabilityInfo> listenInternal(String capability, Uri uri, Integer filterType, Long timeout, TimeUnit timeUnit) {
return Observable.create(new CapabilityListenerObservable(rxWear, capability, uri, filterType, timeout, timeUnit));
}

// getAll

public Observable<CapabilityInfo> getAll(int nodeFilter) {
return getAllInternal(nodeFilter, null, null);
}

public Observable<CapabilityInfo> getAll(int nodeFilter, long timeout, @NonNull TimeUnit timeUnit) {
return getAllInternal(nodeFilter, timeout, timeUnit);
}

private Observable<CapabilityInfo> getAllInternal(int nodeFilter, Long timeout, TimeUnit timeUnit) {
return Single.create(new CapabilityGetAllSingle(rxWear, nodeFilter, timeout, timeUnit))
.flatMapObservable(capabilityInfoMap -> Observable.from(capabilityInfoMap.values()));
}

// get

public Single<CapabilityInfo> get(@NonNull String capability, int nodeFilter) {
return getInternal(capability, nodeFilter, null, null);
}

public Single<CapabilityInfo> get(@NonNull String capability, int nodeFilter, long timeout, @NonNull TimeUnit timeUnit) {
return getInternal(capability, nodeFilter, timeout, timeUnit);
}

private Single<CapabilityInfo> getInternal(String capability, int nodeFilter, Long timeout, TimeUnit timeUnit) {
return Single.create(new CapabilityGetSingle(rxWear, capability, nodeFilter, timeout, timeUnit));
}

// addLocal

public Single<Status> addLocal(@NonNull String capability) {
return addLocalInternal(capability, null, null);
}

public Single<Status> addLocal(@NonNull String capability, long timeout, @NonNull TimeUnit timeUnit) {
return addLocalInternal(capability, timeout, timeUnit);
}

private Single<Status> addLocalInternal(String capability, Long timeout, TimeUnit timeUnit) {
return Single.create(new CapabilityAddLocalSingle(rxWear, capability, timeout, timeUnit));
}

// removeLocal

public Single<Status> removeLocal(@NonNull String capability) {
return removeLocalInternal(capability, null, null);
}

public Single<Status> removeLocal(@NonNull String capability, long timeout, @NonNull TimeUnit timeUnit) {
return removeLocalInternal(capability, timeout, timeUnit);
}

private Single<Status> removeLocalInternal(String capability, Long timeout, TimeUnit timeUnit) {
return Single.create(new CapabilityRemoveLocalSingle(rxWear, capability, timeout, timeUnit));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.patloew.rxwear;

import android.support.annotation.NonNull;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.wearable.CapabilityApi;
import com.google.android.gms.wearable.Wearable;
Expand All @@ -25,7 +22,7 @@
* 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. */
public class CapabilityAddLocalSingle extends BaseSingle<Status> {
class CapabilityAddLocalSingle extends BaseSingle<Status> {

private final String capability;

Expand All @@ -36,15 +33,9 @@ public class CapabilityAddLocalSingle extends BaseSingle<Status> {

@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final SingleSubscriber<? super Status> subscriber) {
setupWearPendingResult(Wearable.CapabilityApi.addLocalCapability(apiClient, capability), new ResultCallback<CapabilityApi.AddLocalCapabilityResult>() {
@Override
public void onResult(@NonNull CapabilityApi.AddLocalCapabilityResult addLocalCapabilityResult) {
if (!addLocalCapabilityResult.getStatus().isSuccess()) {
subscriber.onError(new StatusException(addLocalCapabilityResult.getStatus()));
} else {
subscriber.onSuccess(addLocalCapabilityResult.getStatus());
}
}
});
setupWearPendingResult(
Wearable.CapabilityApi.addLocalCapability(apiClient, capability),
SingleResultCallBack.get(subscriber, CapabilityApi.AddLocalCapabilityResult::getStatus)
);
}
}
Loading

0 comments on commit 4889d0e

Please sign in to comment.