diff --git a/README.md b/README.md index 3b4100f..62a99de 100644 --- a/README.md +++ b/README.md @@ -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 ----------- @@ -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. @@ -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 diff --git a/bintray.gradle b/bintray.gradle new file mode 100644 index 0000000..3d9ba49 --- /dev/null +++ b/bintray.gradle @@ -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' + diff --git a/build.gradle b/build.gradle index 5fd1068..41a6105 100644 --- a/build.gradle +++ b/build.gradle @@ -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" } } @@ -20,7 +21,6 @@ plugins { id "com.jfrog.bintray" version "1.7.3" } - allprojects { repositories { jcenter() diff --git a/deps.gradle b/deps.gradle new file mode 100644 index 0000000..3f01a66 --- /dev/null +++ b/deps.gradle @@ -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', +] \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d9e4c6e..73388ee 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/locgetter-sample/build.gradle b/locgetter-sample/build.gradle index 2fc309f..e8671b1 100644 --- a/locgetter-sample/build.gradle +++ b/locgetter-sample/build.gradle @@ -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 @@ -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') } diff --git a/locgetter-sample/src/main/java/codes/titanium/locgetter_sample/MainActivity.java b/locgetter-sample/src/main/java/codes/titanium/locgetter_sample/MainActivity.java index 00ce212..a557efd 100644 --- a/locgetter-sample/src/main/java/codes/titanium/locgetter_sample/MainActivity.java +++ b/locgetter-sample/src/main/java/codes/titanium/locgetter_sample/MainActivity.java @@ -1,6 +1,8 @@ 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; @@ -8,14 +10,16 @@ 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; @@ -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); } @@ -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() { @@ -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(); - } - } diff --git a/locgetter-sample/src/main/res/layout/activity_main.xml b/locgetter-sample/src/main/res/layout/activity_main.xml index e7091b3..c97f4aa 100644 --- a/locgetter-sample/src/main/res/layout/activity_main.xml +++ b/locgetter-sample/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ - + android:layout_height="300dp" /> + android:text="Latest location = " /> + android:orientation="horizontal">