All Projects → patloew → Rxfit

patloew / Rxfit

Licence: other
🏃Reactive Fitness API Library for Android and RxJava

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Rxfit

Rxjava3 Android Examples
RxJava 3 Android Examples - Migration From RxJava 2 to RxJava 3 - How to use RxJava 3 in Android
Stars: ✭ 213 (-2.29%)
Mutual labels:  rxjava, rxjava2
Fountain
Android Kotlin paged endpoints made easy
Stars: ✭ 175 (-19.72%)
Mutual labels:  rxjava, rxjava2
Reactivesensors
Android library monitoring device hardware sensors with RxJava
Stars: ✭ 161 (-26.15%)
Mutual labels:  rxjava, rxjava2
Rxble
使用 RxJava 封装的低功耗蓝牙类库
Stars: ✭ 203 (-6.88%)
Mutual labels:  rxjava, rxjava2
Rxbus
Event Bus By RxJava.
Stars: ✭ 2,126 (+875.23%)
Mutual labels:  rxjava, rxjava2
Android Developer Roadmap
Android Developer Roadmap - A complete roadmap to learn Android App Development
Stars: ✭ 2,170 (+895.41%)
Mutual labels:  rxjava, rxjava2
Reactivebeacons
Android library scanning BLE beacons nearby with RxJava
Stars: ✭ 171 (-21.56%)
Mutual labels:  rxjava, rxjava2
Vertx Rx
Reactive Extensions for Vert.x
Stars: ✭ 137 (-37.16%)
Mutual labels:  rxjava, rxjava2
Httprequest
基于Retrofit2+RxJava2+OkHttp3的网络请求框架,可以完美的应用到组件化、MVP模式等项目中
Stars: ✭ 181 (-16.97%)
Mutual labels:  rxjava, rxjava2
Mvvm Architecture Android Beginners
This repository contains a sample app that implements MVVM architecture using Kotlin, ViewModel, LiveData, and etc.
Stars: ✭ 176 (-19.27%)
Mutual labels:  rxjava, rxjava2
Dagger2
Kotlin Dagger2 example project
Stars: ✭ 145 (-33.49%)
Mutual labels:  rxjava, rxjava2
Androidbasemvp
🚀一个快速搭建MVP+RxJava2+Retrofit 基础框架,主要是封装有Http网络请求、日志、缓存、加载等待、toast、页面状态布局管理、权限、RxBus、Glide图片加载等组件,方便快速开发新项目、减少开发成本。
Stars: ✭ 184 (-15.6%)
Mutual labels:  rxjava, rxjava2
Android Clean Architecture Boilerplate
Apply clean architecture on Android
Stars: ✭ 141 (-35.32%)
Mutual labels:  rxjava, rxjava2
Jd Mall Master
一款高仿京东商城的UI,基于MVP的Retrofit2(okhttp3)+rxjava+dagger2+greendao+glide。该项目系仿京东商城,属于独立开发者作品,仅供参考学习,拒绝做一切商业用途,如有侵权,请告知删除
Stars: ✭ 151 (-30.73%)
Mutual labels:  rxjava, rxjava2
Rxjavapriorityscheduler
RxPS - RxJavaPriorityScheduler - A RxJava Priority Scheduler library for Android and Java applications
Stars: ✭ 138 (-36.7%)
Mutual labels:  rxjava, rxjava2
Rxwear
⌚️ Reactive Wearable API Library for Android and RxJava
Stars: ✭ 163 (-25.23%)
Mutual labels:  rxjava, rxjava2
Okhttp Okgo
OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Stars: ✭ 10,407 (+4673.85%)
Mutual labels:  rxjava, rxjava2
Rxlifecycle
Rx binding of stock Android Activities & Fragment Lifecycle, avoiding memory leak
Stars: ✭ 131 (-39.91%)
Mutual labels:  rxjava, rxjava2
Disposer
Easily dispose rxJava streams with Android's Lifecycle
Stars: ✭ 176 (-19.27%)
Mutual labels:  rxjava, rxjava2
Rxpermission
Reactive permissions for Android
Stars: ✭ 182 (-16.51%)
Mutual labels:  rxjava, rxjava2

Reactive Fit API Library for Android

Build Status codecov Download Android Arsenal API

This library wraps the Fit API in RxJava 2 Observables and Singles. No more managing GoogleApiClients! Also, the authorization process for using fitness data is handled by the lib.

See the 1.x branch for a RxJava 1 version of this library.

Usage

Create an RxFit instance once, preferably in your Application's onCreate() or by using a dependency injection framework. Make sure to include all the APIs and Scopes that you need for your app. The RxFit class is very similar to the Fitness class provided by the Fit API. Instead of Fitness.HistoryApi.readData(apiClient, dataReadRequest) you can use rxFit.history().read(dataReadRequest). Make sure to have the Location and Body Sensors permission from Marshmallow on, if they are needed by your Fit API requests. If the user didn’t already authorize your app for using fitness data, the lib handles showing the authorization dialog.

Example:

// Create one instance and share it
RxFit rxfit = new RxFit(
        context,
        new Api[] { Fitness.HISTORY_API },
        new Scope[] { new Scope(Scopes.FITNESS_ACTIVITY_READ) }
);

DataReadRequest dataReadRequest = new DataReadRequest.Builder()
	    .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
	    .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
	    .bucketBySession(1, TimeUnit.MINUTES)
	    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
	    .build();

rxFit.history().read(dataReadRequest)
        .flatMapObservable(dataReadResult -> Observable.from(dataReadResult.getBuckets()))
        .subscribe(bucket -> {
        	/* do something */
        });

An RxFitOnExceptionResumeNext Transformer is available in the lib, which resumes with another Single/Observable when an Exception is thrown, except when the exception was a GoogleAPIConnectionException which was caused by an unresolved resolution.

An optional global default timeout for all Fit API requests made through the library can be set via rxFit.setDefaultTimeout(...). In addition, timeouts can be set when creating a new Observable by providing timeout parameters, e.g. rxFit.history().read(dataReadRequest, 15, TimeUnit.SECONDS). These parameters override the default timeout. When a timeout occurs, a StatusException is provided via onError(). The RxJava timeout operators can be used instead, but these do not cancel the Fit API request immediately.

If you don't want the library to automatically handle resolutions (e.g. for usage in a background service), you can disable this behavior when creating an RxFit instance by passing in false to the handleResolutions parameter: new RxFit(ctx, apiArray, scopeArray, false).

You can also obtain a Single<GoogleApiClient>, which connects on subscribe and disconnects on unsubscribe via GoogleAPIClientSingle.create(...).

The following Exceptions are thrown in the lib and provided via onError():

  • StatusException: When the call to the Fit API was not successful or timed out
  • GoogleAPIConnectionException: When connecting to the GoogleAPIClient was not successful and the resolution (if available) was also not successful (e.g. when the user does not authorize your app to use fitness data). Resolutions are not handled when using GoogleAPIClientObservable.
  • GoogleAPIConnectionSuspendedException: When the GoogleApiClient connection was suspended.
  • SecurityException: When you try to call a Fit API without proper permissions.

Sample

A basic sample app is available in the sample project. You need to create an OAuth 2.0 Client ID for the sample app, see the guide in the Fit API docs.

Setup

The lib is available on jCenter. Add the following to your build.gradle:

dependencies {
    compile 'com.patloew.rxfit:rxfit2:2.0.1'
}

Testing

When unit testing your app's classes, RxFit behavior can be mocked easily. See the MainPresenterTest in the sample project for an example test.

Credits

The code for managing the GoogleApiClient is taken from the Android-ReactiveLocation library by Michał Charmas, which is licensed under the Apache License, Version 2.0.

License

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].