From 1e3140795bc92a8bdcb3981237ea9e551dd27a50 Mon Sep 17 00:00:00 2001 From: mayokunthefirst Date: Mon, 4 May 2020 07:22:41 +0100 Subject: [PATCH] Chore: add air location dependency --- .idea/inspectionProfiles/Project_Default.xml | 6 ++ app/build.gradle | 3 + .../instantweather/utils/LocationLiveData.kt | 71 ------------------- build.gradle | 1 + 4 files changed, 10 insertions(+), 71 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 app/src/main/java/com/mayokunadeniyi/instantweather/utils/LocationLiveData.kt diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..053b7aa --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index f306a0b..dcd5467 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -149,4 +149,7 @@ dependencies { //Elastic view implementation "com.github.skydoves:elasticviews:$elastic_version" + + //Air Location + implementation "com.github.mumayank:AirLocation:$air_location_version" } diff --git a/app/src/main/java/com/mayokunadeniyi/instantweather/utils/LocationLiveData.kt b/app/src/main/java/com/mayokunadeniyi/instantweather/utils/LocationLiveData.kt deleted file mode 100644 index 4f325c7..0000000 --- a/app/src/main/java/com/mayokunadeniyi/instantweather/utils/LocationLiveData.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.mayokunadeniyi.instantweather.utils - -import android.annotation.SuppressLint -import android.content.Context -import android.location.Location -import androidx.lifecycle.LiveData -import com.mayokunadeniyi.instantweather.data.model.LocationModel -import com.google.android.gms.location.LocationCallback -import com.google.android.gms.location.LocationRequest -import com.google.android.gms.location.LocationResult -import com.google.android.gms.location.LocationServices -import java.util.concurrent.TimeUnit - -class LocationLiveData(context: Context) : LiveData() { - - private var fusedLocationClient = LocationServices.getFusedLocationProviderClient(context) - - override fun onInactive() { - super.onInactive() - fusedLocationClient.removeLocationUpdates(locationCallback) - } - - - @SuppressLint("MissingPermission") - override fun onActive() { - super.onActive() - fusedLocationClient.lastLocation - .addOnSuccessListener { location: Location? -> - location?.also { - setLocationData(it) - } - } - startLocationUpdates() - } - - @SuppressLint("MissingPermission") - private fun startLocationUpdates() { - fusedLocationClient.requestLocationUpdates( - locationRequest, - locationCallback, - null - ) - } - - private val locationCallback = object : LocationCallback() { - override fun onLocationResult(locationResult: LocationResult?) { - locationResult ?: return - for (location in locationResult.locations) { - setLocationData(location) - } - } - } - - private fun setLocationData(location: Location) { - value = LocationModel( - longitude = location.longitude, - latitude = location.latitude - ) - } - - companion object { - val locationRequest: LocationRequest = LocationRequest.create().apply { - interval = TimeUnit.SECONDS.toMillis(60) - fastestInterval = TimeUnit.SECONDS.toMillis(30) - maxWaitTime = TimeUnit.MINUTES.toMillis(2) - priority = LocationRequest.PRIORITY_HIGH_ACCURACY - } - } -} - - diff --git a/build.gradle b/build.gradle index 34bc223..c1ecf2d 100644 --- a/build.gradle +++ b/build.gradle @@ -57,4 +57,5 @@ ext { algolia_version = '2.3.1' paging_version = '2.1.2' elastic_version = '2.0.7' + air_location_version = '1.3.1' } \ No newline at end of file