From ad75cf6a879b94393215805625d70a15b9834a8c Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Thu, 10 Nov 2022 20:34:38 +0000 Subject: [PATCH 1/5] Remove widgets when an application is uninstalled --- .../features/launcher/LauncherActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 14b7a12517..1462e8adfb 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -629,6 +629,7 @@ public class LauncherActivity extends AppCompatActivity forceRefreshSuggestedApps = true; removePackageFromLauncher(appRemoveEvent.getPackageName(), appRemoveEvent.getUserHandle()); DatabaseManager.getManager(this).saveLayouts(pages, mDock); + rebindAllWidgets(); } public void onAppChangeEvent(AppChangeEvent appChangeEvent) { @@ -1468,12 +1469,23 @@ public class LauncherActivity extends AppCompatActivity } // [[END]] + rebindWidgetHost(); + } + + private void rebindWidgetHost() { int[] widgetIds = mAppWidgetHost.getAppWidgetIds(); getCompositeDisposable().add(DatabaseManager.getManager(this).getWidgets(widgetIds) .subscribeOn(Schedulers.from(AppExecutors.getInstance().diskIO())) .observeOn(AndroidSchedulers.mainThread()).subscribe(this::bindWidgets)); } + public void rebindAllWidgets() { + if (widgetsPage != null) { + widgetContainer.removeAllViewsInLayout(); + rebindWidgetHost(); + } + } + private void bindWidgets(List widgets) { for (WidgetItem widget : widgets) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widget.id); -- GitLab From e24498ea5ecf7ed83808ada73cd9ecf1ee4489a7 Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Fri, 11 Nov 2022 12:23:56 +0530 Subject: [PATCH 2/5] Hide new libre office icon from bliss launcher --- .../e/blisslauncher/features/launcher/AppProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java index ff011c80a8..04069a7b8b 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java @@ -72,6 +72,7 @@ public class AppProvider { private static final String PDF_VIEWER_PACKAGE = "foundation.e.pdfviewer"; private static final String OPENKEYCHAIN_PACKAGE = "org.sufficientlysecure.keychain"; private static final String LIBREOFFICE_PACKAGE = "org.documentfoundation.libreoffice"; + private static final String LIBREOFFICE_PACKAGE2 = "org.example.libreoffice"; private static final String SIM_TOOLKIT = "com.android.stk"; public static HashSet DISABLED_PACKAGES = new HashSet<>(); @@ -84,6 +85,7 @@ public class AppProvider { DISABLED_PACKAGES.add(PDF_VIEWER_PACKAGE); DISABLED_PACKAGES.add(OPENKEYCHAIN_PACKAGE); DISABLED_PACKAGES.add(LIBREOFFICE_PACKAGE); + DISABLED_PACKAGES.add(LIBREOFFICE_PACKAGE2); DISABLED_PACKAGES.add(SIM_TOOLKIT); } -- GitLab From 76462b15e8831dee0e6c100c15381ab4b7d69041 Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Fri, 11 Nov 2022 09:28:11 +0000 Subject: [PATCH 3/5] Fix weather widget refresh icon not changing colors --- app/src/main/res/drawable/ic_refresh_white_24dp.xml | 9 +++++---- app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/styles.xml | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/app/src/main/res/drawable/ic_refresh_white_24dp.xml index a8175c316a..c04dc77559 100644 --- a/app/src/main/res/drawable/ic_refresh_white_24dp.xml +++ b/app/src/main/res/drawable/ic_refresh_white_24dp.xml @@ -1,8 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:tint="?widgetRefreshIconColor" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 8ed965e7c8..94bb8a510e 100755 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -48,6 +48,7 @@ + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 664806fd25..f503f9dc3b 100755 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -43,6 +43,7 @@ @color/on_surface_high_emphasis @color/on_surface_medium_emphasis ?widgetPrimaryTextColor + ?widgetPrimaryTextColor @color/on_surface_high_emphasis @color/colorAccent @color/colorAccent @@ -56,6 +57,7 @@ #99000000 #61000000 #61000000 + #61000000 #BD000000 @color/colorAccent @color/colorAccent -- GitLab From 829a06551e8bb3534e5a731d1577476db19da76a Mon Sep 17 00:00:00 2001 From: Edoardo Regni Date: Sat, 12 Nov 2022 21:22:04 +0000 Subject: [PATCH 4/5] Translated using Weblate (Dutch) Currently translated at 100.0% (149 of 149 strings) Translation: /e//BlissLauncher Translate-URL: https://i18n.e.foundation/projects/e/blisslauncher/nl/ --- app/src/main/res/values-nl/strings.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 1885d6d9b0..23cc85ff18 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -144,4 +144,8 @@ Achtergrond vervagen mislukt Stel een locatie in voor de Weer opties. Toestemming geweigerd - + Negeer + Toestaan + Om notificatie bolletjes op app iconen te zien moet je launcher notificatie toegang geven. + Toestemming vereist + \ No newline at end of file -- GitLab From caded9abc09e77d619bceec1ae62b6bd73c81faf Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 10 Nov 2022 12:20:54 +0100 Subject: [PATCH 5/5] Introduce WeatherUpdater instead of workers Launching a Worker seems to trigger a PACKAGE_UPDATED intent associated to foundation.e.blisslauncher (which is really weird). I created a WeatherUpdater singleton to replace the 2 weather workers. --- app/build.gradle.kts | 3 - .../e/blisslauncher/core/utils/Constants.java | 1 + .../features/weather/WeatherInfoView.java | 3 +- .../weather/WeatherUpdateService.java | 10 +- .../features/weather/WeatherUpdater.java | 161 ++++++++++++++++++ .../worker/ForceWeatherRequestWorker.java | 99 ----------- .../worker/OneShotWeatherRequestWorker.java | 49 ------ .../weather/worker/WeatherRequestWorker.java | 71 -------- app/src/main/res/values-nl/strings.xml | 2 +- gradle/libs.versions.toml | 1 - 10 files changed, 169 insertions(+), 231 deletions(-) create mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java delete mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/worker/ForceWeatherRequestWorker.java delete mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/worker/OneShotWeatherRequestWorker.java delete mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/worker/WeatherRequestWorker.java diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e76842bdcf..98661227b6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -161,7 +161,4 @@ dependencies { // elib implementation(libs.elib) - - // workmanager - implementation(libs.workmanager) } diff --git a/app/src/main/java/foundation/e/blisslauncher/core/utils/Constants.java b/app/src/main/java/foundation/e/blisslauncher/core/utils/Constants.java index 0399bfdc10..926f8a9bb5 100755 --- a/app/src/main/java/foundation/e/blisslauncher/core/utils/Constants.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/utils/Constants.java @@ -36,6 +36,7 @@ public class Constants { // other shared pref entries public static final String WEATHER_LAST_UPDATE = "last_weather_update"; + public static final String WEATHER_LAST_TRY = "last_weather_try"; public static final String WEATHER_DATA = "weather_data"; // First run is used to hide the initial no-weather message for a better OOBE 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 245f731f79..a28add39ef 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 @@ -12,7 +12,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; import foundation.e.blisslauncher.R; import foundation.e.blisslauncher.core.Preferences; import foundation.e.blisslauncher.features.launcher.LauncherActivity; -import foundation.e.blisslauncher.features.weather.worker.ForceWeatherRequestWorker; public class WeatherInfoView extends LinearLayout { @@ -54,7 +53,7 @@ public class WeatherInfoView extends LinearLayout { }); findViewById(R.id.weather_setting_imageview).setOnClickListener(v -> startWeatherPreferences()); findViewById(R.id.weather_refresh_imageview).setOnClickListener(v -> { - ForceWeatherRequestWorker.start(mContext); + WeatherUpdater.getInstance(mContext).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 fe932f5167..c88c7ca632 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 @@ -10,9 +10,6 @@ import android.util.Log; import androidx.annotation.Nullable; -import foundation.e.blisslauncher.features.weather.worker.ForceWeatherRequestWorker; -import foundation.e.blisslauncher.features.weather.worker.OneShotWeatherRequestWorker; - public class WeatherUpdateService extends Service { private static final String TAG = "WeatherUpdateService"; @@ -23,6 +20,7 @@ public class WeatherUpdateService extends Service { private HandlerThread mHandlerThread; private Handler mHandler; + private WeatherUpdater mWeatherUpdater; @SuppressLint("MissingPermission") @Override @@ -33,20 +31,22 @@ public class WeatherUpdateService extends Service { mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); + mWeatherUpdater = WeatherUpdater.getInstance(this); + executePeriodicRequest(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && ACTION_FORCE_UPDATE.equals(intent.getAction())) { - ForceWeatherRequestWorker.start(this); + WeatherUpdater.getInstance(this).forceWeatherRequest(); } return START_STICKY; } private void executePeriodicRequest() { - OneShotWeatherRequestWorker.start(this); + mWeatherUpdater.checkWeatherRequest(); mHandler.removeCallbacksAndMessages(null); mHandler.postDelayed(this::executePeriodicRequest, UPDATE_PERIOD_IN_MS); } 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 new file mode 100644 index 0000000000..cfbe275515 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java @@ -0,0 +1,161 @@ +package foundation.e.blisslauncher.features.weather; + +import android.Manifest.permission; +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Location; +import android.location.LocationManager; +import android.os.SystemClock; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.location.LocationManagerCompat; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + +import java.lang.ref.WeakReference; +import java.util.concurrent.Executors; + +import foundation.e.blisslauncher.core.Preferences; +import lineageos.weather.LineageWeatherManager; +import lineageos.weather.WeatherInfo; +import lineageos.weather.WeatherLocation; + +public class WeatherUpdater { + + private static final String TAG = "WeatherUpdater"; + private final LocationManager mLocationManager; + private final WeakReference mWeakContext; + private Location mGpsLocation; + private Location mNetworkLocation; + + private static WeatherUpdater mInstance = null; + + public static WeatherUpdater getInstance(@NonNull Context context) { + if (mInstance == null) { + mInstance = new WeatherUpdater(context); + } + + return mInstance; + } + + private WeatherUpdater(@NonNull Context context) { + mWeakContext = new WeakReference<>(context); + mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + } + + public void checkWeatherRequest() { + Context context = mWeakContext.get(); + long refreshPeriod = Preferences.weatherRefreshIntervalInMs(context); + long elapsedTime = Math.abs(SystemClock.elapsedRealtime() - Preferences.lastWeatherUpdateTimestamp(context)); + + Log.i(TAG, "elapsedTime=" + elapsedTime + " vs refreshPeriod=" + refreshPeriod); + + boolean isRequestAllowed = refreshPeriod != 0 && elapsedTime >= refreshPeriod; + if (isRequestAllowed) { + updateWeather(); + } + } + + public void forceWeatherRequest() { + Log.i(TAG, "Forcing weather request"); + updateWeather(); + } + + private void updateWeather() { + Context context = mWeakContext.get(); + Preferences.setLastWeatherUpdateTimestamp(context, SystemClock.elapsedRealtime()); + + if (Preferences.useCustomWeatherLocation(context)) { + requestCustomWeatherUpdate(context, Preferences.getCustomWeatherLocation(context)); + } else { + fetchNewLocation(context); + } + } + + @SuppressLint("MissingPermission") + private void fetchNewLocation(@NonNull Context context) { + if (hasMissingPermissions(context)) { + Log.e(TAG, "Could not fetch location for missing permission"); + return; + } + + LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.GPS_PROVIDER, null, + Executors.newFixedThreadPool(1), this::onNewLocationFetched); + + LocationManagerCompat.getCurrentLocation(mLocationManager, LocationManager.NETWORK_PROVIDER, null, + Executors.newFixedThreadPool(1), this::onNewLocationFetched); + } + + protected static boolean hasMissingPermissions(@NonNull Context context) { + return ActivityCompat.checkSelfPermission(context, + permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(context, + permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED; + } + + protected static void requestWeatherUpdate(@NonNull Context context, @NonNull Location location) { + + Log.i(TAG, "Requesting weather info for location: " + location); + LineageWeatherManager weatherManager = LineageWeatherManager.getInstance(context); + weatherManager.requestWeatherUpdate(location, (status, weatherInfo) -> notifyUi(context, weatherInfo, status)); + } + + protected static void requestCustomWeatherUpdate(@NonNull Context context, @Nullable WeatherLocation location) { + Log.i(TAG, "Requesting weather info for location: " + location); + LineageWeatherManager weatherManager = LineageWeatherManager.getInstance(context); + weatherManager.requestWeatherUpdate(location, (status, weatherInfo) -> notifyUi(context, weatherInfo, status)); + } + + private synchronized void onNewLocationFetched(@Nullable Location location) { + if (location == null) { + return; + } + + Log.i(TAG, "New location fetched:" + location); + + if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { + mGpsLocation = location; + } else if (location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) { + mNetworkLocation = location; + } + + requestWeatherUpdate(mWeakContext.get(), getMostRecentLocation()); + } + + protected static void notifyUi(@NonNull Context context, @Nullable WeatherInfo weatherInfo, int status) { + + if (weatherInfo == null) { + Log.i(TAG, "WeatherInfo is null. Status reported: " + status); + return; + } + + Log.i(TAG, "WeatherInfo=" + weatherInfo); + long now = SystemClock.elapsedRealtime(); + Preferences.setCachedWeatherInfo(context, now, weatherInfo); + Preferences.setLastWeatherUpdateTimestamp(context, now); + Intent updateIntent = new Intent(WeatherUpdateService.ACTION_UPDATE_FINISHED); + LocalBroadcastManager.getInstance(context).sendBroadcast(updateIntent); + } + + 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; + } +} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/ForceWeatherRequestWorker.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/ForceWeatherRequestWorker.java deleted file mode 100644 index 779216de8e..0000000000 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/ForceWeatherRequestWorker.java +++ /dev/null @@ -1,99 +0,0 @@ -package foundation.e.blisslauncher.features.weather.worker; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.location.Location; -import android.location.LocationManager; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.core.location.LocationManagerCompat; -import androidx.work.ExistingWorkPolicy; -import androidx.work.OneTimeWorkRequest; -import androidx.work.WorkManager; -import androidx.work.WorkerParameters; - -import java.util.concurrent.Executors; - -import foundation.e.blisslauncher.core.Preferences; - -public class ForceWeatherRequestWorker extends WeatherRequestWorker { - - private static final String TAG = "ForceWeatherRequestWorker"; - - private Location mGpsLocation; - private Location mNetworkLocation; - - public ForceWeatherRequestWorker(@NonNull Context context, @NonNull WorkerParameters params) { - super(context, params); - } - - public static void start(Context context) { - OneTimeWorkRequest weatherUpdateWorkRequest = new OneTimeWorkRequest.Builder(ForceWeatherRequestWorker.class) - .build(); - - WorkManager.getInstance(context).enqueueUniqueWork(TAG, ExistingWorkPolicy.KEEP, weatherUpdateWorkRequest); - } - - @NonNull - @Override - public Result doWork() { - - Context context = getApplicationContext(); - - if (Preferences.useCustomWeatherLocation(context)) { - requestCustomWeatherUpdate(context, Preferences.getCustomWeatherLocation(context)); - } else { - fetchNewLocation(context); - } - - return Result.success(); - } - - @SuppressLint("MissingPermission") - private void fetchNewLocation(Context context) { - if (hasMissingPermissions(context)) { - Log.e(TAG, "Could not fetch location for missing permission"); - return; - } - - LocationManagerCompat.getCurrentLocation(locationManager, LocationManager.GPS_PROVIDER, null, - Executors.newFixedThreadPool(1), this::onNewLocationFetched); - - LocationManagerCompat.getCurrentLocation(locationManager, LocationManager.NETWORK_PROVIDER, null, - Executors.newFixedThreadPool(1), this::onNewLocationFetched); - } - - private synchronized void onNewLocationFetched(Location location) { - if (location == null) { - return; - } - - Log.i(TAG, "New location fetched:" + location); - - if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { - mGpsLocation = location; - } else if (location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) { - mNetworkLocation = location; - requestWeatherUpdate(getApplicationContext(), getMostRecentLocation()); - } - } - - 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; - } -} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/OneShotWeatherRequestWorker.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/OneShotWeatherRequestWorker.java deleted file mode 100644 index ef0de8732c..0000000000 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/OneShotWeatherRequestWorker.java +++ /dev/null @@ -1,49 +0,0 @@ -package foundation.e.blisslauncher.features.weather.worker; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.os.SystemClock; - -import androidx.annotation.NonNull; -import androidx.work.ExistingWorkPolicy; -import androidx.work.OneTimeWorkRequest; -import androidx.work.WorkManager; -import androidx.work.WorkerParameters; - -import foundation.e.blisslauncher.core.Preferences; - -public class OneShotWeatherRequestWorker extends WeatherRequestWorker { - - public static final String TAG = "OneShotWeatherRequestWorker"; - - public OneShotWeatherRequestWorker(@NonNull Context context, @NonNull WorkerParameters params) { - super(context, params); - } - - public static void start(Context context) { - OneTimeWorkRequest weatherUpdateWorkRequest = new OneTimeWorkRequest.Builder(OneShotWeatherRequestWorker.class) - .build(); - - WorkManager.getInstance(context).enqueueUniqueWork(TAG, ExistingWorkPolicy.KEEP, weatherUpdateWorkRequest); - } - - @NonNull - @SuppressLint("MissingPermission") - @Override - public Result doWork() { - Context context = getApplicationContext(); - - if (isWeatherRequestAllowed(context)) { - ForceWeatherRequestWorker.start(context); - } - - return Result.success(); - } - - private static Boolean isWeatherRequestAllowed(Context context) { - long refreshPeriod = Preferences.weatherRefreshIntervalInMs(context); - long elapsedTime = SystemClock.elapsedRealtime() - Preferences.lastWeatherUpdateTimestamp(context); - - return refreshPeriod != 0 && elapsedTime >= refreshPeriod; - } -} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/WeatherRequestWorker.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/WeatherRequestWorker.java deleted file mode 100644 index c24fe758e8..0000000000 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/worker/WeatherRequestWorker.java +++ /dev/null @@ -1,71 +0,0 @@ -package foundation.e.blisslauncher.features.weather.worker; - -import android.Manifest.permission; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.location.Location; -import android.location.LocationManager; -import android.os.SystemClock; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.app.ActivityCompat; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.work.Worker; -import androidx.work.WorkerParameters; - -import foundation.e.blisslauncher.core.Preferences; -import foundation.e.blisslauncher.features.weather.WeatherUpdateService; -import lineageos.weather.LineageWeatherManager; -import lineageos.weather.WeatherInfo; -import lineageos.weather.WeatherLocation; - -public abstract class WeatherRequestWorker extends Worker { - - private static final String TAG = "WeatherRequestWorker"; - - protected final LocationManager locationManager; - - public WeatherRequestWorker(@NonNull Context context, @NonNull WorkerParameters params) { - super(context, params); - locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - } - - @NonNull - public abstract Result doWork(); - - 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, (status, weatherInfo) -> notifyUi(context, weatherInfo, status)); - } - - 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, (status, weatherInfo) -> notifyUi(context, weatherInfo, status)); - } - - protected static void notifyUi(@NonNull Context context, @Nullable WeatherInfo weatherInfo, int status) { - if (weatherInfo == null) { - Log.i(TAG, "WeatherInfo is null. Status reported: " + status); - return; - } - - Log.i(TAG, "WeatherInfo=" + weatherInfo); - long now = SystemClock.elapsedRealtime(); - Preferences.setCachedWeatherInfo(context, now, weatherInfo); - Preferences.setLastWeatherUpdateTimestamp(context, now); - Intent updateIntent = new Intent(WeatherUpdateService.ACTION_UPDATE_FINISHED); - LocalBroadcastManager.getInstance(context).sendBroadcast(updateIntent); - } - - protected static boolean hasMissingPermissions(Context context) { - 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/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 23cc85ff18..57359aea95 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -148,4 +148,4 @@ Toestaan Om notificatie bolletjes op app iconen te zien moet je launcher notificatie toegang geven. Toestemming vereist - \ No newline at end of file + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b14b7dedde..44ad957c70 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -62,7 +62,6 @@ tools-desugar = "com.android.tools:desugar_jdk_libs:1.1.5" timber = "com.jakewharton.timber:timber:4.7.1" restriction-bypass = "com.github.ChickenHook:RestrictionBypass:2.2" elib = "foundation.e:elib:0.0.1-alpha11" -workmanager = "androidx.work:work-runtime:2.7.1" [plugins] android-application = { id = "com.android.application", version.ref = "agp" } -- GitLab