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

Commit 0fad0854 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch '0000-s-background-service' into 'master'

Fallback to the previous weather location in background

See merge request !165
parents a0eeee69 b7df3015
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -128,7 +128,6 @@
        </service>

        <service android:name=".features.weather.WeatherUpdateService" />
        <service android:name=".features.weather.DeviceStatusService" />
        <service android:name=".features.weather.WeatherSourceListenerService" />


+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class Preferences {
    }

    public static long weatherRefreshIntervalInMs(Context context) {
        String value = getPrefs(context).getString(Constants.WEATHER_REFRESH_INTERVAL, "60");
        String value = getPrefs(context).getString(Constants.WEATHER_REFRESH_INTERVAL, "15");
        return Long.parseLong(value) * 60L * 1000L;
    }

+0 −7
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ import androidx.core.graphics.ColorUtils;
import androidx.core.view.GestureDetectorCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
@@ -146,7 +145,6 @@ import foundation.e.blisslauncher.features.suggestions.SearchSuggestionUtil;
import foundation.e.blisslauncher.features.suggestions.SuggestionProvider;
import foundation.e.blisslauncher.features.suggestions.SuggestionsResult;
import foundation.e.blisslauncher.features.usagestats.AppUsageStats;
import foundation.e.blisslauncher.features.weather.DeviceStatusService;
import foundation.e.blisslauncher.features.weather.WeatherPreferences;
import foundation.e.blisslauncher.features.weather.WeatherSourceListenerService;
import foundation.e.blisslauncher.features.weather.WeatherUpdateService;
@@ -176,7 +174,6 @@ public class LauncherActivity extends AppCompatActivity
    private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
    private static final int REQUEST_LOCATION_SOURCE_SETTING = 267;
    private static final int STORAGE_PERMISSION_REQUEST_CODE = 586;
    public static final String ACTION_LAUNCHER_RESUME = "foundation.e.blisslauncher.LauncherActivity.LAUNCHER_RESUME";
    public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
    public static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
    public static final String NOTIFICATION_SETTING = "enabled_notification_listeners";
@@ -532,9 +529,6 @@ public class LauncherActivity extends AppCompatActivity
            refreshSuggestedApps(widgetsPage, forceRefreshSuggestedApps);
        }

        final Intent resumeIntent = new Intent(ACTION_LAUNCHER_RESUME);
        LocalBroadcastManager.getInstance(this).sendBroadcast(resumeIntent);

        if (widgetContainer != null) {
            WidgetManager widgetManager = WidgetManager.getInstance();
            Integer id = widgetManager.dequeRemoveId();
@@ -1474,7 +1468,6 @@ public class LauncherActivity extends AppCompatActivity

        if (WeatherUtils.isWeatherServiceAvailable(this)) {
            startService(new Intent(this, WeatherSourceListenerService.class));
            startService(new Intent(this, DeviceStatusService.class));
        }

        if (!Preferences.useCustomWeatherLocation(this)) {
+0 −68
Original line number Diff line number Diff line
package foundation.e.blisslauncher.features.weather;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;
import foundation.e.blisslauncher.core.utils.Constants;
import timber.log.Timber;

public class DeviceStatusService extends Service {

    private static final String TAG = DeviceStatusService.class.getSimpleName();
    private static final boolean D = Constants.DEBUG;

    private BroadcastReceiver mDeviceStatusListenerReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            // Network connection has changed, make sure the weather update service knows
            // about it
            if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
                boolean hasConnection = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);

                if (D)
                    Timber.tag(TAG).d("Got connectivity change, has connection: " + hasConnection);

                Intent i = new Intent(context, WeatherUpdateService.class);
                if (hasConnection) {
                    context.startService(i);
                } else {
                    context.stopService(i);
                }
            }
        }
    };

    @Override
    public void onCreate() {
        IntentFilter deviceStatusFilter = new IntentFilter();
        deviceStatusFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        deviceStatusFilter.addAction(Intent.ACTION_SCREEN_OFF);
        deviceStatusFilter.addAction(Intent.ACTION_SCREEN_ON);
        registerReceiver(mDeviceStatusListenerReceiver, deviceStatusFilter);
    }

    @Override
    public void onDestroy() {
        if (D)
            Timber.tag(TAG).d("Stopping service");
        unregisterReceiver(mDeviceStatusListenerReceiver);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (D)
            Timber.tag(TAG).d("Starting service");
        return START_STICKY;
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
+0 −10
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ import android.widget.TextView;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Preferences;
import foundation.e.blisslauncher.features.launcher.LauncherActivity;
import timber.log.Timber;

public class WeatherInfoView extends LinearLayout {
@@ -37,13 +36,6 @@ public class WeatherInfoView extends LinearLayout {
        }
    };

    private final BroadcastReceiver mResumeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateWeatherPanel();
        }
    };

    public WeatherInfoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
@@ -76,7 +68,6 @@ public class WeatherInfoView extends LinearLayout {
        intentFilter.addAction(WeatherUpdateService.ACTION_UPDATE_CITY_FINISHED);

        broadcastManager.registerReceiver(mWeatherReceiver, intentFilter);
        broadcastManager.registerReceiver(mResumeReceiver, new IntentFilter(LauncherActivity.ACTION_LAUNCHER_RESUME));
        updateWeatherPanel();
    }

@@ -85,7 +76,6 @@ public class WeatherInfoView extends LinearLayout {
        super.onDetachedFromWindow();
        final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
        broadcastManager.unregisterReceiver(mWeatherReceiver);
        broadcastManager.unregisterReceiver(mResumeReceiver);
    }

    private void updateWeatherPanel() {
Loading