Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from Zellius/master
Browse files Browse the repository at this point in the history
1.0.0 to dev
  • Loading branch information
Zellius committed May 24, 2017
2 parents c74c719 + 2003dbc commit ff9b304
Show file tree
Hide file tree
Showing 151 changed files with 16,577 additions and 1,510 deletions.
22 changes: 18 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- build-tools-25.0.3
- android-25
- extra-android-m2repository
before_install:
- chmod +x gradlew
script:
- ./gradlew clean build -PdisablePreDex --continue --stacktrace
- ./gradlew clean build jacocoRootReport coveralls -PdisablePreDex --continue --stacktrace
env:
- GRADLE_OPTS="-Xmx512m -XX:MaxPermSize=512m"
branches:
only:
- master
- dev
after_success:
- ./gradlew clean jacocoRootReport coveralls
- /^v\d+\.\d+\.\d+$/
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
deploy:
provider: script
script: ./gradlew :rxlocationmanager:bintrayUpload :rxlocationmanager-rxjava2:bintrayUpload -PdryRun=false
skip_cleanup: true
on:
tags: true
branch: /^v\d+\.\d+\.\d+$/
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## [1.0.0] - 2017-05-19
### Added
- RxJava2 support! Please look at rxlocationmanager-rxjava2 project.
- Samples.
### Changed
- Both libraries (RxJava1 and RxJava2 implementations) rewritten to [Kotlin](https://kotlinlang.org/).
But you still can use it in your Java projects.
### Removed
- There is no location _uses-permission_. You need to add them to your app manifest.
- There is no setReturnDefaultLocationOnError method in the LocationRequestBuilder.
You can use a "transformer" property in any method to ignore errors (e.g. by **IgnoreErrorTransformer**).
122 changes: 68 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,116 @@
RxLocationManager
-----------------
# RxLocationManager
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RxLocationManager-orange.svg?style=flat)](http://android-arsenal.com/details/1/3291) [![Build Status](https://travis-ci.org/Zellius/RxLocationManager.svg?branch=master)](https://travis-ci.org/Zellius/RxLocationManager) [![Coverage Status](https://coveralls.io/repos/github/Zellius/RxLocationManager/badge.svg?branch=master&bust=1)](https://coveralls.io/github/Zellius/RxLocationManager?branch=master) ![Android Version](https://img.shields.io/badge/android-9+-blue.svg)

Android library that helps to get location using standart LocationManager and RxJava. It does not use the Google Play Services and it's easier to use.
Android library that helps to get location using standart LocationManager, [RxJava](https://github.com/ReactiveX/RxJava) (1 and 2) and [Kotlin](https://kotlinlang.org/). It does not use the Google Play Services and it's easier to use.

Features
-----------------
## Features
* The library have rxJava and rxJava2 implementations. It is writen in Kotlin, so you can use it in your projects with full language support.
* Get last known device location from any location provider. You can specify how old Location can be. For example you want only those locations that have been received up to 30 minutes ago.
* Request current device location. You can specify how long the request will continue. After that Observable will be unsubscribed automatically.
* You can use LocationRequestBuilder to build sequence of location requests.
* All methods will return an rxJava objects (Single, Maybe, etc.), so you can perform transofrm/map... etc methods on it.
* No need to check is Google Play Services valid or installed on device.

- Get last known device location from any location provider. You can specify how long the location could be obtained. For example you want only those locations that have been received up to 30 minutes ago.
- Request current device location. You can specify request time out or you can wait until observable will emit any value or error.
- You can use LocationRequestBuilder to build sequence of location requests.
- All methods will return an rxJava Observable, so you can perform transofrm/map... etc methods on it.
- No need to check is Google Play Services valid or installed on device.
## Samples
Both rxJava and rxJava2 implementations have same interface but have some differences (like rxJava2 implementation can't emil _null_ value).

Samples
-----------------
If you want to know how to use it on Java/Kotlin Android project with rxJava/rxJava2 support, please look at any **sample** projects.

#### Get last known location
###### rxJava1:
* [Single](http://reactivex.io/RxJava/1.x/javadoc/rx/Single.html);
* It will emit null if there is no last location;
* It can emit ElderLocationException if location is too old.
###### rxJava2:
* [Maybe](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html);
* It will not emit any value if there is no last location;
* It can emit ElderLocationException if location is too old.

**Get last known location**
```java
/*
get last known location from network provider.
It will emit only those locations that have been received up to hour ago
It will emit ElderLocationException if location is too old
/**
* Get last known location from network provider (You can set any other).
* It will emit only those locations that have been received up to hour ago
*/
final RxLocationManager rxLocationManager = new RxLocationManager(this);
rxLocationManager.getLastLocation(LocationManager.NETWORK_PROVIDER, LocationTime.OneHour()).subscribe();
```
**Request location**
#### Request location
###### rxJava1:
* [Single](http://reactivex.io/RxJava/1.x/javadoc/rx/Single.html)
###### rxJava2:
* [Single](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html)

```java
/*
Request current location with timeout.
It will emit ProviderDisabledException in case of timeout
/**
*Request current location with timeout.
*It can emit ProviderDisabledException in case of timeout.
*/
final RxLocationManager rxLocationManager = new RxLocationManager(this);
rxLocationManager.requestLocation(LocationManager.NETWORK_PROVIDER, new LocationTime(10, TimeUnit.SECONDS)).subscribe();
```

**LocationRequestBuilder**
#### LocationRequestBuilder
###### rxJava1:
* [Single](http://reactivex.io/RxJava/1.x/javadoc/rx/Single.html)
* It will emit _null_ if a result is empty and the defaultLocations is _null_ too.
###### rxJava2:
* [Maybe](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html);
* It will not emit any value if a result is empty and the defaultLocations is _null_.
```java
/*
1. Try to get valid last known location
2. If last known location is not valid, try to get current location from GPS
3. Emit a default location if no location was emitted.
/**
* 1. Try to get valid last known location
* 2. If last known location is not valid, try to get current location from GPS
* 3. Emit a default location if no location was emitted.
*/
final LocationRequestBuilder locationRequestBuilder = new LocationRequestBuilder(this);
locationRequestBuilder.addLastLocation(LocationManager.NETWORK_PROVIDER, new LocationTime(30, TimeUnit.SECONDS), false)
.addRequestLocation(LocationManager.GPS_PROVIDER, new LocationTime(10, TimeUnit.SECONDS))
.setDefaultLocation(new Location(LocationManager.PASSIVE_PROVIDER))
.create().subscribe();
.create()
.subscribe();
```
> **Note:** For default the LocationRequestBuilder will emit a default location in case of any exceptions. If you want to receive any exceptions you should use
> **Note:** By default the LocationRequestBuilder will ignore any library exceptions, but will throw any other. You can use a transformer to change it. The code below will ignore any error.
```java
locationRequestBuilder.setReturnDefaultLocationOnError(false)
addLastLocation(LocationManager.NETWORK_PROVIDER, new LocationTime(30, TimeUnit.MINUTES), new IgnoreErrorTransformer(null))
```

Download
-----------------
**Java**

Maven:

## Download
##### rxJava1
###### Maven:
```xml
<dependency>
<groupId>com.github.zellius</groupId>
<artifactId>rxlocationmanager</artifactId>
<version>0.1.2</version>
<version>x.y.z</version>
</dependency>
```

Gradle:

###### Gradle:
```gradle
compile 'com.github.zellius:rxlocationmanager:0.1.2'
compile 'com.github.zellius:rxlocationmanager:x.y.z'
```
**Kotlin**

Maven:

##### rxJava2
###### Maven:
```xml
<dependency>
<groupId>com.github.zellius</groupId>
<artifactId>rxlocationmanager.kotlin</artifactId>
<version>0.1.1</version>
<artifactId>rxlocationmanager-rxjava2</artifactId>
<version>x.y.z</version>
</dependency>
```

Gradle:

###### Gradle:
```gradle
compile 'com.github.zellius:rxlocationmanager.kotlin:0.1.1'
compile 'com.github.zellius:rxlocationmanager-rxjava2:x.y.z'
```
## Setup
Add the necessary permissions to your app manifest.xml.
```xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
```

## License

```
The MIT License (MIT)
Copyright (c) 2016 Sergey Solodovnikov
Copyright (c) 2017 Sergey Solodovnikov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 36 additions & 0 deletions base_project.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 9
targetSdkVersion 25

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

//for tests
testCompile 'junit:junit:4.12'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile 'org.robolectric:robolectric:3.3.2'
testCompile 'org.mockito:mockito-core:2.7.22'
}
Loading

0 comments on commit ff9b304

Please sign in to comment.