Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43e9855f authored by Jonathan Klee's avatar Jonathan Klee
Browse files

FIx

parent 9f27f5df
Loading
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -75,16 +75,11 @@ public class ForceWeatherRequestWorker extends WeatherRequestWorker {
            mGpsLocation = location;
        } else if (location.getProvider().equals("network")) {
            mNetworkLocation = location;
        }

        try {
            requestWeatherUpdate(getApplicationContext(), getMostRecentLocation());
        } catch (IllegalStateException exception) {
            Log.e(TAG, "Illegal state has been faced. Could not update location.");
        }
    }

    private Location getMostRecentLocation() throws IllegalStateException {
    private Location getMostRecentLocation() {
        if (mNetworkLocation == null && mGpsLocation == null) {
            throw new IllegalStateException();
        }
+5 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.location.Location;
import android.location.LocationManager;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -39,17 +40,18 @@ public abstract class WeatherRequestWorker extends Worker {
    protected static void requestWeatherUpdate(Context context, Location location) {
        Log.i(TAG, "Requesting weather info for location: " + location);
        LineageWeatherManager weatherManager = LineageWeatherManager.getInstance(context);
        weatherManager.requestWeatherUpdate(location, (info, weatherInfo) -> notifyUi(context, weatherInfo));
        weatherManager.requestWeatherUpdate(location, (info, weatherInfo) -> notifyUi(context, weatherInfo, info));
    }

    protected static void requestCustomWeatherUpdate(Context context, WeatherLocation location) {
        Log.i(TAG, "Requesting weather info for location: " + location);
        LineageWeatherManager weatherManager = LineageWeatherManager.getInstance(context);
        weatherManager.requestWeatherUpdate(location, (info, weatherInfo) -> notifyUi(context, weatherInfo));
        weatherManager.requestWeatherUpdate(location, (info, weatherInfo) -> notifyUi(context, weatherInfo, info));
    }

    protected static void notifyUi(@NonNull Context context, @Nullable WeatherInfo weatherInfo) {
    protected static void notifyUi(@NonNull Context context, @Nullable WeatherInfo weatherInfo, int info) {
        if (weatherInfo == null) {
            Toast.makeText(context, "Weather API returned an error: " + info, Toast.LENGTH_SHORT).show();
            return;
        }