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

Commit cf6c9971 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Fix issues

parent 1dd1a1e3
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.util.Log;

import androidx.annotation.Nullable;

import foundation.e.blisslauncher.core.Preferences;
import foundation.e.blisslauncher.features.weather.worker.ForceWeatherRequestWorker;
import foundation.e.blisslauncher.features.weather.worker.OneShotWeatherRequestWorker;

@@ -34,6 +35,9 @@ public class WeatherUpdateService extends Service {
        mHandler = new Handler(mHandlerThread.getLooper());

        executePeriodicRequest();

        Preferences.setLastWeatherUpdateTimestamp(this, 0);
        Preferences.setLastWeatherUpdateTryTimestamp(this, 0);
    }

    @Override
+3 −1
Original line number Diff line number Diff line
@@ -80,8 +80,9 @@ public class ForceWeatherRequestWorker extends WeatherRequestWorker {
            mGpsLocation = location;
        } else if (location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
            mNetworkLocation = location;
            requestWeatherUpdate(getApplicationContext(), getMostRecentLocation());
        }

        requestWeatherUpdate(getApplicationContext(), getMostRecentLocation());
    }

    private Location getMostRecentLocation() {
@@ -104,6 +105,7 @@ public class ForceWeatherRequestWorker extends WeatherRequestWorker {

    private static Boolean isWeatherForceRequestAllowed(Context context) {
        long elapsedTime = SystemClock.elapsedRealtime() - Preferences.lastWeatherUpdateTryTimestamp(context);
        Log.i(TAG, "elapstedTime=" + elapsedTime + " vs refreshPeriod=" + WEATHER_REQUEST_PERIOD_TRY_IN_MS);
        boolean isRequestAllowed = elapsedTime >= WEATHER_REQUEST_PERIOD_TRY_IN_MS;

        if (isRequestAllowed) {
+8 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package foundation.e.blisslauncher.features.weather.worker;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.SystemClock;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.ExistingWorkPolicy;
@@ -44,6 +45,12 @@ public class OneShotWeatherRequestWorker extends WeatherRequestWorker {
        long refreshPeriod = Preferences.weatherRefreshIntervalInMs(context);
        long elapsedTime = SystemClock.elapsedRealtime() - Preferences.lastWeatherUpdateTimestamp(context);

        return refreshPeriod != 0 && elapsedTime >= refreshPeriod;
        Log.i(TAG, "elapstedTime=" + elapsedTime + " vs refreshPeriod=" + refreshPeriod);
        boolean isRequestAllowed = refreshPeriod != 0 && elapsedTime >= refreshPeriod;
        if (isRequestAllowed) {
            Preferences.setLastWeatherUpdateTimestamp(context, SystemClock.elapsedRealtime());
        }

        return isRequestAllowed;
    }
}