From 9da3cf127e62fca6a20fd0cb7d663467457bb554 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 11 Apr 2023 16:50:40 +0200 Subject: [PATCH 1/6] Use fused provider for Android >= 12 --- .../features/weather/WeatherUpdater.java | 48 +++---------- .../location/FusedLocationFetcher.java | 35 ++++++++++ .../weather/location/LocationFetcher.java | 18 +++++ .../location/NetworkGpsLocationFetcher.java | 67 +++++++++++++++++++ 4 files changed, 131 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java create mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java create mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java index 5c9da50655..bf2a4d2d6a 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java @@ -6,13 +6,13 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; -import android.location.LocationManager; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.os.SystemClock; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; -import androidx.core.location.LocationManagerCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.google.gson.JsonArray; @@ -24,10 +24,12 @@ import com.google.gson.JsonSyntaxException; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.Locale; -import java.util.concurrent.Executors; import foundation.e.blisslauncher.R; import foundation.e.blisslauncher.core.Preferences; +import foundation.e.blisslauncher.features.weather.location.FusedLocationFetcher; +import foundation.e.blisslauncher.features.weather.location.LocationFetcher; +import foundation.e.blisslauncher.features.weather.location.NetworkGpsLocationFetcher; import lineageos.weather.LineageWeatherManager; import lineageos.weather.WeatherInfo; import lineageos.weather.WeatherLocation; @@ -44,10 +46,7 @@ public class WeatherUpdater { private static final String TAG = "WeatherUpdater"; private static final long DEFAULT_FORCE_REQUEST_PERIOD_IN_MS = 10L * 1000L; - private final LocationManager mLocationManager; private final WeakReference mWeakContext; - private Location mGpsLocation; - private Location mNetworkLocation; private long mForceRequestPeriodInMs = DEFAULT_FORCE_REQUEST_PERIOD_IN_MS; private static WeatherUpdater mInstance = null; @@ -62,7 +61,6 @@ public class WeatherUpdater { private WeatherUpdater(@NonNull Context context) { mWeakContext = new WeakReference<>(context); - mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); } public void checkWeatherRequest() { @@ -123,11 +121,11 @@ public class WeatherUpdater { return; } - LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.GPS_PROVIDER, null, - Executors.newFixedThreadPool(1), this::onNewLocationFetched); + LocationFetcher locationFetcher = VERSION.SDK_INT >= VERSION_CODES.S + ? new FusedLocationFetcher(mWeakContext.get(), this::onNewLocationFetched) + : new NetworkGpsLocationFetcher(mWeakContext.get(), this::onNewLocationFetched); - LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.NETWORK_PROVIDER, null, - Executors.newFixedThreadPool(1), this::onNewLocationFetched); + locationFetcher.fetchLocation(); } protected boolean hasMissingPermissions() { @@ -166,16 +164,10 @@ public class WeatherUpdater { Timber.tag(TAG).i("New location fetched:%s", location); - if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { - mGpsLocation = location; - } else if (location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) { - mNetworkLocation = location; - } - - requestWeatherUpdate(getMostRecentLocation()); + requestWeatherUpdate(location); if (!Preferences.useCustomWeatherLocation(mWeakContext.get())) { - reverseGeocodeLocation(getMostRecentLocation()); + reverseGeocodeLocation(location); } else { Timber.tag(TAG).w("Do not reverse geocode location. User is using a custom location."); } @@ -198,24 +190,6 @@ public class WeatherUpdater { mForceRequestPeriodInMs = DEFAULT_FORCE_REQUEST_PERIOD_IN_MS; } - private Location getMostRecentLocation() { - if (mNetworkLocation == null && mGpsLocation == null) { - throw new IllegalStateException(); - } - - if (mGpsLocation == null) { - return mNetworkLocation; - } - - if (mNetworkLocation == null) { - return mGpsLocation; - } - - long gpsTime = mGpsLocation.getTime(); - long networkTime = mNetworkLocation.getTime(); - return gpsTime >= networkTime ? mGpsLocation : mNetworkLocation; - } - private void reverseGeocodeLocation(@NonNull Location location) { Timber.tag(TAG).i("Reverse geocoding location %s", location); diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java new file mode 100644 index 0000000000..588c973012 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java @@ -0,0 +1,35 @@ +package foundation.e.blisslauncher.features.weather.location; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.location.Location; +import android.location.LocationManager; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.location.LocationManagerCompat; + +import java.util.concurrent.Executors; + +public class FusedLocationFetcher extends LocationFetcher { + + public FusedLocationFetcher(@NonNull Context context, @NonNull Callback callback) { + mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + mCallback = callback; + } + + @Override + @SuppressLint("MissingPermission") + public void fetchLocation() { + if (VERSION.SDK_INT >= VERSION_CODES.S) { + LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.FUSED_PROVIDER, null, + Executors.newFixedThreadPool(1), this::onLocationFetched); + } + } + + private void onLocationFetched(@Nullable Location location) { + mCallback.onNewLocation(location); + } +} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java new file mode 100644 index 0000000000..1ca1cfb522 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java @@ -0,0 +1,18 @@ +package foundation.e.blisslauncher.features.weather.location; + +import android.location.Location; +import android.location.LocationManager; + +import androidx.annotation.Nullable; + +public abstract class LocationFetcher { + + protected LocationManager mLocationManager; + protected Callback mCallback; + + public interface Callback { + void onNewLocation(@Nullable Location location); + } + + public abstract void fetchLocation(); +} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java new file mode 100644 index 0000000000..0b1348439d --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java @@ -0,0 +1,67 @@ +package foundation.e.blisslauncher.features.weather.location; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.location.Location; +import android.location.LocationManager; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.location.LocationManagerCompat; + +import java.util.concurrent.Executors; + +public class NetworkGpsLocationFetcher extends LocationFetcher { + + private Location gpsLocation; + private Location networkLocation; + + public NetworkGpsLocationFetcher(@NonNull Context context, @NonNull Callback callback) { + mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + mCallback = callback; + } + + @Override + @SuppressLint("MissingPermission") + public void fetchLocation() { + LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.GPS_PROVIDER, null, + Executors.newFixedThreadPool(1), this::onLocationFetched); + + LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.NETWORK_PROVIDER, null, + Executors.newFixedThreadPool(1), this::onLocationFetched); + } + + private void onLocationFetched(@Nullable Location location) { + + if (location == null) { + return; + } + + if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { + gpsLocation = location; + } else if (location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) { + networkLocation = location; + } + + mCallback.onNewLocation(getMostRecentLocation()); + } + + private Location getMostRecentLocation() { + if (networkLocation == null && gpsLocation == null) { + throw new IllegalStateException(); + } + + if (gpsLocation == null) { + return networkLocation; + } + + if (networkLocation == null) { + return gpsLocation; + } + + long gpsTime = gpsLocation.getTime(); + long networkTime = networkLocation.getTime(); + return gpsTime >= networkTime ? gpsLocation : networkLocation; + } + +} -- GitLab From 6c4d754aa0da7848e80eef45401f6a8e3fb6292a Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 12 Apr 2023 17:11:11 +0200 Subject: [PATCH 2/6] Make logs more accurate --- .../e/blisslauncher/features/weather/WeatherUpdater.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java index bf2a4d2d6a..ad404d3977 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java @@ -224,12 +224,13 @@ public class WeatherUpdater { } if (defaultCityName == null) { - Timber.tag(TAG).e("Could not get default city name"); + Timber.tag(TAG).w("Could not get default city name"); return; } if (locales == null) { - Timber.tag(TAG).e("Could not get locales"); + Timber.tag(TAG).i("Could not get locales. Fallbacking to default city name %s", defaultCityName); + notifyUi(defaultCityName); return; } @@ -237,7 +238,9 @@ public class WeatherUpdater { String countryCode = Locale.getDefault().getCountry().toLowerCase(Locale.ROOT); final JsonElement jsonElement = locales.get(countryCode); if (jsonElement == null) { - Timber.tag(TAG).e("Could not get city name in country code: %s", countryCode); + Timber.tag(TAG).i("Could not get city name in country code: %s. Fallbacking to default city name %s", + countryCode, defaultCityName); + notifyUi(defaultCityName); return; } -- GitLab From b44ac717a47878eedd028a1f63954b051f817fcd Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 12 Apr 2023 20:18:25 +0200 Subject: [PATCH 3/6] Fix some NPE exceptions --- .../e/blisslauncher/features/weather/WeatherInfoView.java | 4 +--- .../blisslauncher/features/weather/WeatherUpdateService.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java index c6a56ee597..adf4d32a8f 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java @@ -19,7 +19,6 @@ public class WeatherInfoView extends LinearLayout { private View mWeatherPanel; private View mWeatherSetupTextView; - private Context mContext; private final BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { @Override @@ -47,7 +46,6 @@ public class WeatherInfoView extends LinearLayout { public WeatherInfoView(Context context, AttributeSet attrs) { super(context, attrs); - mContext = context; } @Override @@ -64,7 +62,7 @@ public class WeatherInfoView extends LinearLayout { }); findViewById(R.id.weather_setting_imageview).setOnClickListener(v -> startWeatherPreferences()); findViewById(R.id.weather_refresh_imageview).setOnClickListener(v -> { - WeatherUpdater.getInstance(mContext).forceWeatherRequest(); + WeatherUpdater.getInstance(getContext().getApplicationContext()).forceWeatherRequest(); }); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java index 182169233a..500d2f034a 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java @@ -34,7 +34,7 @@ public class WeatherUpdateService extends Service { mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); - mWeatherUpdater = WeatherUpdater.getInstance(this); + mWeatherUpdater = WeatherUpdater.getInstance(getApplicationContext()); executePeriodicRequest(); } -- GitLab From 4e93eaed91b5785cf7d12650b3b74cbd010951b8 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 12 Apr 2023 20:39:59 +0200 Subject: [PATCH 4/6] Fallback to getLastKnownLocation --- .../features/weather/location/FusedLocationFetcher.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java index 588c973012..b39c18c6a0 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java @@ -9,6 +9,7 @@ import android.os.Build.VERSION_CODES; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import androidx.core.location.LocationManagerCompat; import java.util.concurrent.Executors; @@ -29,7 +30,13 @@ public class FusedLocationFetcher extends LocationFetcher { } } + @RequiresApi(api = VERSION_CODES.S) + @SuppressLint("MissingPermission") private void onLocationFetched(@Nullable Location location) { + if (location == null) { + location = mLocationManager.getLastKnownLocation(LocationManager.FUSED_PROVIDER); + } + mCallback.onNewLocation(location); } } -- GitLab From 5cef0f0d867d3362ce544cc911d2f91c4ca58f83 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 14 Apr 2023 08:32:37 +0200 Subject: [PATCH 5/6] Check location permissions --- .../weather/location/FusedLocationFetcher.java | 17 +++++++++++------ .../weather/location/LocationFetcher.java | 13 +++++++++++++ .../location/NetworkGpsLocationFetcher.java | 10 ++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java index b39c18c6a0..d89401d770 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java @@ -1,6 +1,5 @@ package foundation.e.blisslauncher.features.weather.location; -import android.annotation.SuppressLint; import android.content.Context; import android.location.Location; import android.location.LocationManager; @@ -14,16 +13,23 @@ import androidx.core.location.LocationManagerCompat; import java.util.concurrent.Executors; +import timber.log.Timber; + public class FusedLocationFetcher extends LocationFetcher { public FusedLocationFetcher(@NonNull Context context, @NonNull Callback callback) { - mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + this.context = context; mCallback = callback; + mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); } @Override - @SuppressLint("MissingPermission") public void fetchLocation() { + if (!checkPermission()) { + Timber.w("Could not fetch location. Missing permission."); + return; + } + if (VERSION.SDK_INT >= VERSION_CODES.S) { LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.FUSED_PROVIDER, null, Executors.newFixedThreadPool(1), this::onLocationFetched); @@ -31,12 +37,11 @@ public class FusedLocationFetcher extends LocationFetcher { } @RequiresApi(api = VERSION_CODES.S) - @SuppressLint("MissingPermission") private void onLocationFetched(@Nullable Location location) { - if (location == null) { + if (location == null && checkPermission()) { location = mLocationManager.getLastKnownLocation(LocationManager.FUSED_PROVIDER); } mCallback.onNewLocation(location); } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java index 1ca1cfb522..5e7a466e69 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java @@ -1,18 +1,31 @@ package foundation.e.blisslauncher.features.weather.location; +import android.Manifest.permission; +import android.content.Context; +import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; public abstract class LocationFetcher { protected LocationManager mLocationManager; protected Callback mCallback; + protected Context context; + public interface Callback { void onNewLocation(@Nullable Location location); } public abstract void fetchLocation(); + + protected boolean checkPermission() { + return ActivityCompat.checkSelfPermission(context, + permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED + || ActivityCompat.checkSelfPermission(context, + permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED; + } } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java index 0b1348439d..599b6c152f 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java @@ -1,6 +1,5 @@ package foundation.e.blisslauncher.features.weather.location; -import android.annotation.SuppressLint; import android.content.Context; import android.location.Location; import android.location.LocationManager; @@ -11,19 +10,26 @@ import androidx.core.location.LocationManagerCompat; import java.util.concurrent.Executors; +import timber.log.Timber; + public class NetworkGpsLocationFetcher extends LocationFetcher { private Location gpsLocation; private Location networkLocation; public NetworkGpsLocationFetcher(@NonNull Context context, @NonNull Callback callback) { + this.context = context; mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); mCallback = callback; } @Override - @SuppressLint("MissingPermission") public void fetchLocation() { + if (!checkPermission()) { + Timber.w("Could not fetch location. Missing permission."); + return; + } + LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.GPS_PROVIDER, null, Executors.newFixedThreadPool(1), this::onLocationFetched); -- GitLab From f9f4e7aba3c5f6485bef8e9d197af8fc4f5a1aeb Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 14 Apr 2023 15:04:39 +0200 Subject: [PATCH 6/6] Some renamings --- .../weather/location/FusedLocationFetcher.java | 10 +++++----- .../features/weather/location/LocationFetcher.java | 4 ++-- .../weather/location/NetworkGpsLocationFetcher.java | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java index d89401d770..bf647777a3 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/FusedLocationFetcher.java @@ -19,8 +19,8 @@ public class FusedLocationFetcher extends LocationFetcher { public FusedLocationFetcher(@NonNull Context context, @NonNull Callback callback) { this.context = context; - mCallback = callback; - mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + this.callback = callback; + locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); } @Override @@ -31,7 +31,7 @@ public class FusedLocationFetcher extends LocationFetcher { } if (VERSION.SDK_INT >= VERSION_CODES.S) { - LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.FUSED_PROVIDER, null, + LocationManagerCompat.getCurrentLocation(locationManager, LocationManager.FUSED_PROVIDER, null, Executors.newFixedThreadPool(1), this::onLocationFetched); } } @@ -39,9 +39,9 @@ public class FusedLocationFetcher extends LocationFetcher { @RequiresApi(api = VERSION_CODES.S) private void onLocationFetched(@Nullable Location location) { if (location == null && checkPermission()) { - location = mLocationManager.getLastKnownLocation(LocationManager.FUSED_PROVIDER); + location = locationManager.getLastKnownLocation(LocationManager.FUSED_PROVIDER); } - mCallback.onNewLocation(location); + callback.onNewLocation(location); } } \ No newline at end of file diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java index 5e7a466e69..75fa273856 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/LocationFetcher.java @@ -11,8 +11,8 @@ import androidx.core.app.ActivityCompat; public abstract class LocationFetcher { - protected LocationManager mLocationManager; - protected Callback mCallback; + protected LocationManager locationManager; + protected Callback callback; protected Context context; diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java index 599b6c152f..c2112647a2 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/location/NetworkGpsLocationFetcher.java @@ -19,8 +19,8 @@ public class NetworkGpsLocationFetcher extends LocationFetcher { public NetworkGpsLocationFetcher(@NonNull Context context, @NonNull Callback callback) { this.context = context; - mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - mCallback = callback; + locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + this.callback = callback; } @Override @@ -30,10 +30,10 @@ public class NetworkGpsLocationFetcher extends LocationFetcher { return; } - LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.GPS_PROVIDER, null, + LocationManagerCompat.getCurrentLocation(locationManager, LocationManager.GPS_PROVIDER, null, Executors.newFixedThreadPool(1), this::onLocationFetched); - LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.NETWORK_PROVIDER, null, + LocationManagerCompat.getCurrentLocation(locationManager, LocationManager.NETWORK_PROVIDER, null, Executors.newFixedThreadPool(1), this::onLocationFetched); } @@ -49,7 +49,7 @@ public class NetworkGpsLocationFetcher extends LocationFetcher { networkLocation = location; } - mCallback.onNewLocation(getMostRecentLocation()); + callback.onNewLocation(getMostRecentLocation()); } private Location getMostRecentLocation() { -- GitLab