Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade #14

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ orbs:

jobs:
build:
executor: android/android
docker:
- image: cimg/android:2023.08

steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 19 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 33
buildToolsVersion "33.0.2"
namespace "com.jintin.fancylocation.app"

defaultConfig {

applicationId "com.jintin.fancylocation.app"
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand All @@ -25,29 +27,29 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
}

dependencies {
implementation project(':lib')

// implementation 'com.github.jintin:FancyLocationProvider:1.0'
implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'androidx.activity:activity-ktx:1.1.0'
implementation "org.permissionsdispatcher:permissionsdispatcher:4.8.0"
kapt "org.permissionsdispatcher:permissionsdispatcher-processor:4.8.0"
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation "com.github.permissions-dispatcher:permissionsdispatcher:4.8.0"
kapt "com.github.permissions-dispatcher:permissionsdispatcher-processor:4.8.0"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jintin.fancylocation.app">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:allowBackup="true"
Expand All @@ -11,7 +11,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FancyLocation">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MainActivity : AppCompatActivity() {

private val viewModel by viewModels<MainViewModel>()

private val type = TYPE_STATEFLOW
private val type = TYPE_FLOW

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -37,7 +37,10 @@ class MainActivity : AppCompatActivity() {
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) = onRequestPermissionsResult(requestCode, grantResults)
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
onRequestPermissionsResult(requestCode, grantResults)
}

@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
@RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])
Expand All @@ -52,7 +55,6 @@ class MainActivity : AppCompatActivity() {
@RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])
private fun flowObserve() {
lifecycleScope.launch {
@Suppress("EXPERIMENTAL_API_USAGE")
viewModel.locationFlow.get().collect(::updateUI)
}
}
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/jintin/fancylocation/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package com.jintin.fancylocation.app
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.Priority
import com.jintin.fancylocation.*
import kotlinx.coroutines.ExperimentalCoroutinesApi

class MainViewModel(application: Application) : AndroidViewModel(application) {
private val locationRequest =
LocationRequest.create()
.setInterval(3000)
.setFastestInterval(3000)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)

LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 3000)
.setWaitForAccurateLocation(false)
.setMinUpdateIntervalMillis(3000)
.setMaxUpdateDelayMillis(3000)
.build()

// @ExperimentalCoroutinesApi
// val locationFlow = LocationFlow(application, locationRequest)
Expand Down
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
ext.kotlin_version = "1.9.0"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.android.tools.build:gradle:8.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -17,7 +16,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Expand Down
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Nov 14 08:28:06 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
26 changes: 12 additions & 14 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'com.github.dcendents.android-maven'
}

group = 'com.github.jintin'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 33
buildToolsVersion "33.0.2"
namespace "com.jintin.fancylocation"

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand All @@ -27,21 +25,21 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
}

dependencies {

implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
7 changes: 4 additions & 3 deletions lib/src/main/java/com/jintin/fancylocation/LocationFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.google.android.gms.location.LocationRequest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.sendBlocking
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow

Expand All @@ -23,14 +24,14 @@ class LocationFlow(

@RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])
fun get(): Flow<LocationData> = channelFlow {
channel.sendBlocking(LocationData.Loading)
channel.trySendBlocking(LocationData.Loading)
locationProvider.requestLocationUpdates(object : ILocationObserver {
override fun onLocationResult(location: Location) {
channel.sendBlocking(LocationData.Success(location))
channel.trySendBlocking(LocationData.Success(location))
}

override fun onLocationFailed() {
channel.sendBlocking(LocationData.Fail)
channel.trySendBlocking(LocationData.Fail)
}
})
awaitClose {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class LocationProvider(
private class LocationListener : LocationCallback() {
var locationObserver: ILocationObserver? = null

override fun onLocationResult(result: LocationResult?) {
result?.lastLocation?.let {
override fun onLocationResult(result: LocationResult) {
result.lastLocation?.let {
locationObserver?.onLocationResult(it)
}
}

override fun onLocationAvailability(availability: LocationAvailability?) {
if (availability?.isLocationAvailable == false) {
override fun onLocationAvailability(availability: LocationAvailability) {
if (!availability.isLocationAvailable) {
locationObserver?.onLocationFailed()
}
}
Expand Down