Hotfix last known location error

This commit is contained in:
Tommaso Berlose
2020-05-03 21:19:53 +02:00
parent 5b9ef9abc7
commit 739c273c91
40 changed files with 228 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package com.tommasoberlose.anotherwidget.helpers
import android.Manifest
import android.content.Context
import com.google.android.gms.location.LocationServices
import com.kwabenaberko.openweathermaplib.constants.Units
@ -10,6 +11,7 @@ import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.network.WeatherNetworkApi
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
/**
@ -22,12 +24,17 @@ object WeatherHelper {
val networkApi = WeatherNetworkApi(context)
if (Preferences.customLocationAdd != "") {
networkApi.updateWeather()
} else {
LocationServices.getFusedLocationProviderClient(context).lastLocation.addOnSuccessListener {
Preferences.customLocationLat = it.latitude.toString()
Preferences.customLocationLon = it.longitude.toString()
} else if (context.checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
LocationServices.getFusedLocationProviderClient(context).lastLocation.addOnCompleteListener { task ->
if (task.isSuccessful) {
val location = task.result
if (location != null) {
Preferences.customLocationLat = location.latitude.toString()
Preferences.customLocationLon = location.longitude.toString()
networkApi.updateWeather()
networkApi.updateWeather()
}
}
}
}
}

View File

@ -176,7 +176,7 @@ class CalendarSettingsFragment : Fragment() {
cal1.accountName == cal1.name -> {
-1
}
cal2.accountName == cal2.accountName -> {
cal2.accountName == cal2.name -> {
1
}
else -> {