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

Commit 7f01bf7d authored by Jonathan Klee's avatar Jonathan Klee
Browse files

fixup! Fix issues

parent 5315b4f3
Loading
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -244,14 +244,6 @@ public class Preferences {
        getPrefs(context).edit().putLong(Constants.WEATHER_LAST_UPDATE, timestamp).apply();
    }

    public static long lastWeatherUpdateTryTimestamp(Context context) {
        return getPrefs(context).getLong(Constants.WEATHER_LAST_TRY, 0);
    }

    public static void setLastWeatherUpdateTryTimestamp(Context context, long timestamp) {
        getPrefs(context).edit().putLong(Constants.WEATHER_LAST_TRY, timestamp).apply();
    }

    public static WeatherInfo getCachedWeatherInfo(Context context) {
        final String cachedInfo = getPrefs(context).getString(Constants.WEATHER_DATA, null);

+0 −4
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ 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;

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

        executePeriodicRequest();

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

    @Override
+1 −17
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.SystemClock;
import android.util.Log;

import androidx.annotation.NonNull;
@@ -22,7 +21,7 @@ public class ForceWeatherRequestWorker extends WeatherRequestWorker {

    private static final String TAG = "ForceWeatherRequestWorker";

    private static final int WEATHER_REQUEST_PERIOD_TRY_IN_MS = 60000;
    public static final int WEATHER_REQUEST_PERIOD_TRY_IN_MS = 60000;

    private Location mGpsLocation;
    private Location mNetworkLocation;
@@ -42,9 +41,6 @@ public class ForceWeatherRequestWorker extends WeatherRequestWorker {
    @Override
    public Result doWork() {
        Context context = getApplicationContext();
        if (!isWeatherForceRequestAllowed(context)) {
            return Result.failure();
        }

        if (Preferences.useCustomWeatherLocation(context)) {
            requestCustomWeatherUpdate(context, Preferences.getCustomWeatherLocation(context));
@@ -102,16 +98,4 @@ public class ForceWeatherRequestWorker extends WeatherRequestWorker {
        long networkTime = mNetworkLocation.getTime();
        return gpsTime >= networkTime ? mGpsLocation : mNetworkLocation;
    }

    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) {
            Preferences.setLastWeatherUpdateTryTimestamp(context, SystemClock.elapsedRealtime());
        }

        return isRequestAllowed;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -43,9 +43,9 @@ public class OneShotWeatherRequestWorker extends WeatherRequestWorker {

    private static Boolean isWeatherRequestAllowed(Context context) {
        long refreshPeriod = Preferences.weatherRefreshIntervalInMs(context);
        long elapsedTime = SystemClock.elapsedRealtime() - Preferences.lastWeatherUpdateTimestamp(context);
        long elapsedTime = Math.abs(SystemClock.elapsedRealtime() - Preferences.lastWeatherUpdateTimestamp(context));

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