Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from titanium-codes/develop
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
Andrew Tomash authored Jan 8, 2019
2 parents 0443661 + 097bd7c commit 8cf551e
Show file tree
Hide file tree
Showing 27 changed files with 477 additions and 646 deletions.
59 changes: 24 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,24 @@ allprojects {
**Step 2.** Add the dependency

##### For Android studio 3.0
**Recommended**: This will use all libraries that you defined
**Recommended**: This will use all libraries that you defined
```
dependencies {
implementation 'com.android.support:appcompat-v7:YOUR_SUPPORT_LIBRARY_VERSION'
implementation 'com.android.support:design:YOUR_SUPPORT_LIBRARY_VERSION'
implementation 'io.reactivex.rxjava2:rxandroid:YOUR_RX_ANDROID_VERSION'
implementation 'io.reactivex.rxjava2:rxjava:YOUR_RX_JAVA_2_VERSION'
implementation 'com.google.android.gms:play-services-location:YOUR_GOOGLE_PLAY_VERSION'
implementation ('codes.titanium:locgetter:1.0.3',{
implementation ('codes.titanium:locgetter:1.1.0',{
transitive = false
})
}
```

```
**Not recommended:** This will use all dependencies from library, may increase apk size, increase methods count and lead to compile errors
```
dependencies {
implementation 'codes.titanium:locgetter:1.0.3'
implementation 'codes.titanium:locgetter:1.1.0'
}
```

#### For Android studio 2.3
**Recommended**: This will use all libraries that you defined
```
dependencies {
compile 'com.android.support:appcompat-v7:YOUR_SUPPORT_LIBRARY_VERSION'
compile 'com.android.support:design:YOUR_SUPPORT_LIBRARY_VERSION'
compile 'io.reactivex.rxjava2:rxandroid:YOUR_RX_ANDROID_VERSION'
compile 'io.reactivex.rxjava2:rxjava:YOUR_RX_JAVA_2_VERSION'
compile 'com.google.android.gms:play-services-location:YOUR_GOOGLE_PLAY_VERSION'
compile ('codes.titanium:locgetter:1.0.3',{
transitive = false
})
}
```
**Not recommended:** This will use all dependencies from library, may increase apk size, increase methods count and lead to compile errors
```
dependencies {
compile 'codes.titanium:locgetter:1.0.3'
}
```
```

Basic Usage
-----------
Expand All @@ -83,9 +60,8 @@ All you need is to create **LocationGetter** instance using **LocationGetterBuil

Optional you can add to builder:

* LocationRequest to customize location updates
* GoogleApiClient to use instance of your google api client
* Logger to get logs of everything happening inside LocationGetter
* Accept mock locations behavior

Start getting locations using one of methods for e.g.

Expand All @@ -99,17 +75,30 @@ locationGetter.getLatestLocation()

More examples can be found in sample package with sample app.

Helper activity
Error handling
---------------
You can extend your activity from **BaseLocationActivity** and get access to extended behavior with some features.
All exceptions are handled in library.

In case of no permissions -> user will be asked to give permissions, if user declines -> NoLocationPermission will be thrown

1. Catch exceptions via onLocationError to handle settings and permissions errors
2. Get callbacks with user locations permission granted/revoked and locations settings granted/revoke
3. Show dialog on google api available
In case of turned off location -> user will be asked to turn it on, if user declines -> LocationSettingsException will be thrown

Accept mock locations behavior
---
By default mock locations are accepted.
You can filter all mock locations that are received by location manager. Just set acceptMockLocations to false when you are building location getter.

In case if mock location will be received MockLocationException will be thrown with that mocked location and you can decide what to do with it.

Release notes
-------------
### 1.1.0
> * Major refactor
> * Removed a lot of redundant APIs
> * No more need of activity to handle exceptions
> * Optimizations
> * Feature - mock locations filter
### 1.0.3
> * Updated Readme
> * Updated dependencies bump
Expand Down
55 changes: 55 additions & 0 deletions bintray.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apply plugin: 'com.jfrog.bintray'
apply from: '../deps.gradle'

def mSiteUrl = 'https://github.com/titanium-codes'
def mGitUrl = 'https://github.com/titanium-codes/LocGetter'

tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
tasks.whenTaskAdded { task ->
if (task.name == 'javadoc') {
task.configure {
failOnError false
}
}
}
android {
compileSdkVersion versions.compileSdkVersion
}
ext {
bintrayRepo = 'Android'
bintrayName = versions.artifact

publishedGroupId = 'codes.titanium'
libraryName = versions.artifact
artifact = versions.artifact

libraryDescription = 'Android library for getting user current location'

// Your github repo link
siteUrl = mSiteUrl
gitUrl = mGitUrl
githubRepository = 'titanium-codes/LocGetter'

libraryVersion = versions.publishVersion

developerId = 'blainepwnz'
developerName = 'Andrew Tomash'
developerEmail = 'andrew.tomash@titanium-soft.com'
licenseName = 'MIT'
licenseUrl = 'https://opensource.org/licenses/MIT'
allLicenses = ["MIT"]
}
bintray {
pkg {
userOrg = "titanium-codes"
}
}
apply from: 'https://raw.githubusercontent.com/nisrulz/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nisrulz/JCenter/master/bintrayv1.gradle'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
apply from: 'deps.gradle'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion"
}

}
Expand All @@ -20,7 +21,6 @@ plugins {
id "com.jfrog.bintray" version "1.7.3"
}


allprojects {
repositories {
jcenter()
Expand Down
14 changes: 14 additions & 0 deletions deps.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ext.versions = [
artifact : 'locgetter',
compileSdkVersion: 28,
minSdk: 16,
buildToolsVersion: '28.0.3',
publishVersion : '1.1.0',
buildCode : 4,
kotlinVersion : '1.3.11',
//libs
playServLocations :'com.google.android.gms:play-services-location:16.0.0',
rxAndroid : 'io.reactivex.rxjava2:rxandroid:2.1.0',
rxJava2 : 'io.reactivex.rxjava2:rxjava:2.2.3',
kotlinStd : 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11',
]
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Nov 02 11:14:02 EET 2017
#Mon Jan 07 17:19:22 EET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
40 changes: 18 additions & 22 deletions locgetter-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
apply plugin: 'com.android.application'
apply from: '../deps.gradle'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion versions.compileSdkVersion
buildToolsVersion versions.buildToolsVersion

defaultConfig {
applicationId "codes.titanium.locgetter_sample"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

minSdkVersion versions.minSdk
targetSdkVersion versions.compileSdkVersion
versionCode versions.buildCode
versionName versions.publishVersion
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -27,18 +27,14 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'com.google.android.gms:play-services-location:11.4.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation versions.rxAndroid
implementation versions.rxJava2
implementation versions.playServLocations
implementation versions.kotlinStd
testImplementation 'junit:junit:4.12'
implementation ('codes.titanium:locgetter:1.0.3',{
transitive = false
})
implementation project(':locgetter')
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package codes.titanium.locgetter_sample;

import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.titanium.locgetter.infra.BaseLocationActivity;
import com.titanium.locgetter.main.LocationGetter;
import com.titanium.locgetter.main.LocationGetterBuilder;

import java.util.concurrent.TimeUnit;

import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

public class MainActivity extends BaseLocationActivity {
public class MainActivity extends FragmentActivity {

private static final String TAG = "MainActivity";
private LocationGetter locationGetter;
Expand All @@ -35,17 +39,22 @@ private void initButtons() {
Button locationsBtn = findViewById(R.id.locations_btn);
locationsBtn.setOnClickListener(v -> onLocationUpdatesClicked(locationsBtn));
findViewById(R.id.latest_location_btn).setOnClickListener(v -> {
Toast.makeText(this, "Latest location = " + locationGetter.getLatestSavedLocation(), Toast.LENGTH_SHORT).show();
Location loc = locationGetter.getLatestSavedLocation();
if (loc != null) {
Toast.makeText(this, loc.toString(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Null latest location", Toast.LENGTH_SHORT).show();
}
});
findViewById(R.id.one_location_btn).setOnClickListener(v -> getOneLocation());
}

private void getOneLocation() {
locationGetter.getLatestLocation()
Single.timer(2, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(location -> {
((TextView) findViewById(R.id.locations_tv)).setText(location.toString());
}, this::onLocationError);
.flatMap(s -> locationGetter.getLatestLocation())
.subscribe(location -> ((TextView) findViewById(R.id.locations_tv)).setText(location.toString()),
Throwable::printStackTrace);
}


Expand All @@ -63,9 +72,7 @@ private synchronized void onLocationUpdatesClicked(Button locationsBtn) {
private void startLocationUpdates() {
locationsDisposable = locationGetter.getLatestLocations()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(location -> adapter.addLocation(location)
, this::onLocationError,
() -> Log.d(TAG, "startLocationUpdates: completed"));
.subscribe(location -> adapter.addLocation(location), throwable -> Log.e(TAG, throwable.getMessage()));
}

private void initRv() {
Expand All @@ -76,19 +83,9 @@ private void initRv() {
}

private void initLocationGetter() {
locationGetter = new LocationGetterBuilder(getApplicationContext())
.setLogger(Log::d)
locationGetter = new LocationGetterBuilder(this)
.acceptMockLocations(false)
.build();
}

@Override
protected void onLocationPermissionResult(boolean granted) {
Toast.makeText(this, "Location permission granted = " + granted, Toast.LENGTH_SHORT).show();
}

@Override
protected void onLocationSettingsResult(boolean granted) {
Toast.makeText(this, "Location settings granted = " + granted, Toast.LENGTH_SHORT).show();
}

}
Loading

0 comments on commit 8cf551e

Please sign in to comment.