|
| 1 | +package com.patloew.rxfit; |
| 2 | + |
| 3 | +import android.app.PendingIntent; |
| 4 | + |
| 5 | +import com.google.android.gms.common.api.GoogleApiClient; |
| 6 | +import com.google.android.gms.common.api.ResultCallback; |
| 7 | +import com.google.android.gms.common.api.Status; |
| 8 | +import com.google.android.gms.fitness.Fitness; |
| 9 | +import com.google.android.gms.fitness.data.DataSource; |
| 10 | +import com.google.android.gms.fitness.data.DataType; |
| 11 | +import com.google.android.gms.fitness.request.DataUpdateListenerRegistrationRequest; |
| 12 | + |
| 13 | +import java.util.concurrent.TimeUnit; |
| 14 | + |
| 15 | +import rx.SingleSubscriber; |
| 16 | + |
| 17 | +/* Copyright 2016 Patrick Löwenstein |
| 18 | + * |
| 19 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 20 | + * you may not use this file except in compliance with the License. |
| 21 | + * You may obtain a copy of the License at |
| 22 | + * |
| 23 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 24 | + * |
| 25 | + * Unless required by applicable law or agreed to in writing, software |
| 26 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 27 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 28 | + * See the License for the specific language governing permissions and |
| 29 | + * limitations under the License. */ |
| 30 | +public class HistoryRegisterDataUpdateListenerSingle extends BaseSingle<Status> { |
| 31 | + |
| 32 | + private final DataUpdateListenerRegistrationRequest request; |
| 33 | + |
| 34 | + HistoryRegisterDataUpdateListenerSingle(RxFit rxFit, PendingIntent pendingIntent, DataSource dataSource, DataType dataType, Long timeout, TimeUnit timeUnit) { |
| 35 | + super(rxFit, timeout, timeUnit); |
| 36 | + |
| 37 | + DataUpdateListenerRegistrationRequest.Builder builder = new DataUpdateListenerRegistrationRequest.Builder(); |
| 38 | + builder.setPendingIntent(pendingIntent); |
| 39 | + if(dataSource != null) { builder.setDataSource(dataSource); } |
| 40 | + if(dataType != null) { builder.setDataType(dataType); } |
| 41 | + |
| 42 | + request = builder.build(); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + protected void onGoogleApiClientReady(GoogleApiClient apiClient, final SingleSubscriber<? super Status> subscriber) { |
| 47 | + ResultCallback<Status> resultCallback = new StatusResultCallBack(subscriber); |
| 48 | + |
| 49 | + setupFitnessPendingResult(Fitness.HistoryApi.registerDataUpdateListener(apiClient, request), resultCallback); |
| 50 | + } |
| 51 | +} |
0 commit comments