-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Singles instead of Observables if only one item is emitted. Obser…
…vables, which previously returned a List/Map, now emit the items/values of these Collections. Removed unnecessary CheckConnectionObservable.
- Loading branch information
Showing
37 changed files
with
775 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
## Version 1.1.0 | ||
|
||
* BREAKING CHANGE: The lib now uses Singles instead of Observables if only one item is emitted. | ||
* BREAKING CHANGE: Removed unnecessary `getRemoteNodes()`. | ||
* BREAKING CHANGE: Observables, which previously returned a List/Map, now emit the items/values of these Collections. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.patloew.rxwear; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.google.android.gms.common.api.Api; | ||
import com.google.android.gms.common.api.GoogleApiClient; | ||
import com.google.android.gms.common.api.PendingResult; | ||
import com.google.android.gms.common.api.Result; | ||
import com.google.android.gms.common.api.ResultCallback; | ||
import com.google.android.gms.common.api.Scope; | ||
import com.google.android.gms.wearable.Wearable; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/* Copyright (C) 2015 Michał Charmas (http://blog.charmas.pl) | ||
* | ||
* 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. | ||
* | ||
* --------------- | ||
* | ||
* FILE MODIFIED by Patrick Löwenstein, 2016 | ||
* | ||
*/ | ||
public 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.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(); | ||
} | ||
} | ||
|
||
protected BaseRx(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes) { | ||
this.ctx = ctx; | ||
this.services = services; | ||
this.scopes = scopes; | ||
timeoutTime = null; | ||
timeoutUnit = null; | ||
} | ||
|
||
protected final <T extends Result> void setupWearPendingResult(PendingResult<T> pendingResult, ResultCallback<? super T> resultCallback) { | ||
if(timeoutTime != null && timeoutUnit != null) { | ||
pendingResult.setResultCallback(resultCallback, timeoutTime, timeoutUnit); | ||
} else { | ||
pendingResult.setResultCallback(resultCallback); | ||
} | ||
} | ||
|
||
protected final GoogleApiClient createApiClient(ApiClientConnectionCallbacks apiClientConnectionCallbacks) { | ||
|
||
GoogleApiClient.Builder apiClientBuilder = new GoogleApiClient.Builder(ctx); | ||
|
||
|
||
for (Api<? extends Api.ApiOptions.NotRequiredOptions> service : services) { | ||
apiClientBuilder.addApi(service); | ||
} | ||
|
||
if(scopes != null) { | ||
for (Scope scope : scopes) { | ||
apiClientBuilder.addScope(scope); | ||
} | ||
} | ||
|
||
apiClientBuilder.addConnectionCallbacks(apiClientConnectionCallbacks); | ||
apiClientBuilder.addOnConnectionFailedListener(apiClientConnectionCallbacks); | ||
|
||
GoogleApiClient apiClient = apiClientBuilder.build(); | ||
|
||
apiClientConnectionCallbacks.setClient(apiClient); | ||
|
||
return apiClient; | ||
} | ||
|
||
protected void onUnsubscribed(GoogleApiClient locationClient) { } | ||
|
||
protected abstract class ApiClientConnectionCallbacks implements | ||
GoogleApiClient.ConnectionCallbacks, | ||
GoogleApiClient.OnConnectionFailedListener { | ||
|
||
protected GoogleApiClient apiClient; | ||
|
||
protected ApiClientConnectionCallbacks() { } | ||
|
||
public void setClient(GoogleApiClient client) { | ||
this.apiClient = client; | ||
} | ||
} | ||
} |
Oops, something went wrong.