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 #11 from Zellius/min_version
Browse files Browse the repository at this point in the history
1.1.2
  • Loading branch information
Zellius committed Apr 10, 2017
2 parents 8260433 + 19ab600 commit 93cc07c
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 225 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,10 +1,11 @@
language: android
jdk: oraclejdk8
android:
components:
- tools
- platform-tools
- build-tools-23.0.2
- android-23
- build-tools-25.0.2
- android-25
- extra-android-m2repository
before_install:
- chmod +x gradlew
Expand Down
32 changes: 24 additions & 8 deletions README.md
Expand Up @@ -50,29 +50,45 @@ locationRequestBuilder.addLastLocation(LocationManager.NETWORK_PROVIDER, new Loc
.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
>```java
```java
locationRequestBuilder.setReturnDefaultLocationOnError(false)
```

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

Maven:

```xml
<dependency>
<groupId>com.github.zellius</groupId>
<artifactId>rxlocationmanager</artifactId>
<version>0.1.1</version>
<type>pom</type>
<version>0.1.2</version>
</dependency>
```
#####Gradle

######Java
Gradle:

```gradle
compile 'com.github.zellius:rxlocationmanager:0.1.1'
compile 'com.github.zellius:rxlocationmanager:0.1.2'
```
######Kotlin
**Kotlin**

Maven:

```xml
<dependency>
<groupId>com.github.zellius</groupId>
<artifactId>rxlocationmanager.kotlin</artifactId>
<version>0.1.1</version>
</dependency>
```

Gradle:

```gradle
compile 'com.github.zellius:rxlocationmanager.kotlin:0.1.0'
compile 'com.github.zellius:rxlocationmanager.kotlin:0.1.1'
```

## License
Expand Down
61 changes: 45 additions & 16 deletions build.gradle
@@ -1,17 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'jacoco'

buildscript {
repositories {
jcenter()
mavenCentral()
}
ext.kotlin_version = '1.0.0'
ext.kotlin_version = '1.1.1'
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.novoda:bintray-release:0.3.4'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.novoda:bintray-release:0.4.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -25,10 +23,48 @@ allprojects {
}
}
subprojects {
if (!project.name.contains('sample')) {
if (!name.contains('sample')) {
apply plugin: 'jacoco'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 9
targetSdkVersion 25
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'io.reactivex:rxjava:1.2.9'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.android.support:support-annotations:25.3.1'

testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.3.2'
testCompile 'org.mockito:mockito-core:2.7.21'
}

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
Expand All @@ -53,15 +89,6 @@ subprojects {
}
}
}
project(':kotlin') {
android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
Expand All @@ -71,6 +98,7 @@ def validSubprojects = subprojects.findAll {
!it.name.contains('sample')
}

apply plugin: 'jacoco'
task jacocoRootReport(type: JacocoReport, group: 'Coverage reports', description: 'Generates an aggregate report from all subprojects') {
dependsOn = validSubprojects.jacocoTestReport

Expand All @@ -85,6 +113,7 @@ task jacocoRootReport(type: JacocoReport, group: 'Coverage reports', description
}
}

apply plugin: 'com.github.kt3k.coveralls'
coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
sourceDirs = validSubprojects.android.sourceSets.main.java.srcDirs.flatten()
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Tue Apr 12 00:03:45 MSK 2016
#Tue Apr 04 23:21:59 MSK 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
29 changes: 5 additions & 24 deletions kotlin/build.gradle
@@ -1,40 +1,21 @@
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:1.1.0'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.mockito:mockito-core:1.10.19'
}

publish {
groupId = 'com.github.zellius'
artifactId = 'rxlocationmanager.kotlin'
publishVersion = '0.1.0'
publishVersion = '0.1.1'
desc = 'Android library written on Kotlin that helps to get location using standart LocationManager and RxJava'
licences = ['MIT']
website = 'https://github.com/Zellius/RxLocationManager'
Expand Down
Expand Up @@ -8,11 +8,11 @@ import android.location.LocationManager
import android.os.Build
import android.os.Bundle
import android.os.SystemClock
import rx.Emitter
import rx.Observable
import rx.Scheduler
import rx.Subscriber
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.functions.Action1
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException

Expand All @@ -29,22 +29,16 @@ class RxLocationManager internal constructor(private val locationManager: Locati
* @see ElderLocationException
*/
fun getLastLocation(provider: String, howOldCanBe: LocationTime? = null) =
Observable.create<Location> {
try {
it.onNext(locationManager.getLastKnownLocation(provider))
it.onCompleted()
} catch(ex: SecurityException) {
it.onError(ex)
}
}.compose {
if (howOldCanBe == null) it else it.map {
if (it != null && !isLocationNotOld(it, howOldCanBe)) {
throw ElderLocationException(it)
}

it
}
}.compose(applySchedulers())
Observable.fromCallable<Location> { locationManager.getLastKnownLocation(provider) }
.compose {
if (howOldCanBe == null) it else it.map {
if (it != null && !isLocationNotOld(it, howOldCanBe)) {
throw ElderLocationException(it)
}

it
}
}.compose(applySchedulers())

/**
* Try to get current location by specific provider.
Expand All @@ -57,10 +51,11 @@ class RxLocationManager internal constructor(private val locationManager: Locati
* @see TimeoutException
* @see ProviderDisabledException
*/
fun requestLocation(provider: String, timeOut: LocationTime? = null) = requestLocation(provider, timeOut, true)
fun requestLocation(provider: String, timeOut: LocationTime? = null): Observable<Location>
= requestLocation(provider, timeOut, true)

internal fun requestLocation(provider: String, timeOut: LocationTime?, throwExceptionIfDisabled: Boolean) =
Observable.create(RxLocationListener(locationManager, provider, throwExceptionIfDisabled))
Observable.create(RxLocationListener(locationManager, provider, throwExceptionIfDisabled), Emitter.BackpressureMode.NONE)
.compose { if (timeOut != null) it.timeout(timeOut.time, timeOut.timeUnit) else it }
.compose(applySchedulers())

Expand All @@ -81,63 +76,35 @@ class RxLocationManager internal constructor(private val locationManager: Locati
System.currentTimeMillis() - location.time < howOldCanBe.timeUnit.toMillis(howOldCanBe.time)


private class RxLocationListener(val locationManager: LocationManager, val provider: String, val throwExceptionIfDisabled: Boolean) : Observable.OnSubscribe<Location> {
var locationListener: LocationListener? = null
private class RxLocationListener(val locationManager: LocationManager,
val provider: String,
val throwExceptionIfDisabled: Boolean) : Action1<Emitter<Location>> {

override fun call(subscriber: Subscriber<in Location>?) {
override fun call(locationEmitter: Emitter<Location>) {
if (locationManager.isProviderEnabled(provider)) {
locationListener = object : LocationListener {
val locationListener = object : LocationListener {
override fun onLocationChanged(location: Location?) {
if (subscriber != null && !subscriber.isUnsubscribed) {
subscriber.onNext(location)
subscriber.onCompleted()
}
}

override fun onProviderDisabled(p0: String?) {

locationEmitter.onNext(location)
locationEmitter.onCompleted()
}

override fun onStatusChanged(p0: String?, p1: Int, p2: Bundle?) {
override fun onProviderDisabled(p0: String?) {}

}
override fun onStatusChanged(p0: String?, p1: Int, p2: Bundle?) {}

override fun onProviderEnabled(p0: String?) {
if (provider.equals(p0)) {
subscriber!!.onError(ProviderDisabledException(provider))
if (provider == p0) {
locationEmitter.onError(ProviderDisabledException(provider))
}
}
}

try {
locationManager.requestSingleUpdate(provider, locationListener, null)
} catch (ex: SecurityException) {
subscriber!!.onError(ex)
}
locationManager.requestSingleUpdate(provider, locationListener, null)

subscriber!!.add(object : Subscription {
override fun isUnsubscribed() = subscriber.isUnsubscribed
locationEmitter.setCancellation({ locationManager.removeUpdates(locationListener) })

override fun unsubscribe() {
if (!subscriber.isUnsubscribed) {
subscriber.unsubscribe()
}

try {
removeUpdates()
} catch(ex: SecurityException) {
subscriber.onError(ex)
}
}
})
} else {
if (throwExceptionIfDisabled) subscriber!!.onError(ProviderDisabledException(provider)) else subscriber!!.onCompleted()
}
}

private fun removeUpdates() {
if (locationListener != null) {
locationManager.removeUpdates(locationListener)
if (throwExceptionIfDisabled) locationEmitter.onError(ProviderDisabledException(provider)) else locationEmitter.onCompleted()
}
}
}
Expand Down

0 comments on commit 93cc07c

Please sign in to comment.