From 3b0f0c24de09fdd673fdd50e49bbbd523468e35b Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 9 May 2022 14:56:06 +0700 Subject: [PATCH 1/2] Don't add widget if it already exists --- .../features/launcher/LauncherActivity.java | 14 +++++++++++--- .../features/weather/WeatherAppWidgetProvider.java | 3 +++ .../features/widgets/DefaultWidgets.kt | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) 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 1906f4852e..aed1b3c36a 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 @@ -420,22 +420,30 @@ public class LauncherActivity extends AppCompatActivity implements } private void addDefaultWidgets() { + int[] widgetIds = mAppWidgetHost.getAppWidgetIds(); + Set existingProviders = new HashSet<>(); + for (int widgetId : widgetIds) { + AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(widgetId); + existingProviders.add(info.provider); + } + if (!Preferences.getAddedEcloudWidget(this)) { ComponentName provider = DefaultWidgets.INSTANCE.getEcloudWidget(); - if (allocateAndBindWidget(provider)) { + if (existingProviders.contains(provider) || allocateAndBindWidget(provider)) { Preferences.setAddedEcloudWidget(this); } } if (!Preferences.getAddedPrivacyWidget(this)) { ComponentName provider = DefaultWidgets.INSTANCE.getPrivacyWidget(); - if (allocateAndBindWidget(provider)) { + if (existingProviders.contains(provider) || allocateAndBindWidget(provider)) { Preferences.setAddedPrivacyWidget(this); } } if (!Preferences.getAddedWeatherWidget(this)) { - if (allocateAndBindWidget(WeatherAppWidgetProvider.COMPONENT_NAME)) { + ComponentName provider = DefaultWidgets.INSTANCE.getWeatherWidget(); + if (existingProviders.contains(provider) || allocateAndBindWidget(provider)) { Preferences.setAddedWeatherWidget(this); } } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherAppWidgetProvider.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherAppWidgetProvider.java index 8643eac040..29bccfb05c 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherAppWidgetProvider.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherAppWidgetProvider.java @@ -3,10 +3,13 @@ package foundation.e.blisslauncher.features.weather; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; +import androidx.annotation.NonNull; + import foundation.e.blisslauncher.BuildConfig; public class WeatherAppWidgetProvider extends AppWidgetProvider { + @NonNull public static final ComponentName COMPONENT_NAME = new ComponentName( BuildConfig.APPLICATION_ID, WeatherAppWidgetProvider.class.getName()); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/widgets/DefaultWidgets.kt b/app/src/main/java/foundation/e/blisslauncher/features/widgets/DefaultWidgets.kt index 67ec3b898f..62d66603b4 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/widgets/DefaultWidgets.kt +++ b/app/src/main/java/foundation/e/blisslauncher/features/widgets/DefaultWidgets.kt @@ -1,10 +1,12 @@ package foundation.e.blisslauncher.features.widgets import android.content.ComponentName +import foundation.e.blisslauncher.features.weather.WeatherAppWidgetProvider object DefaultWidgets { val ecloudWidget = ComponentName("foundation.e.drive", "foundation.e.drive.widgets.EDriveWidget") val privacyWidget = ComponentName("foundation.e.advancedprivacy", "foundation.e.privacycentralapp.Widget") + val weatherWidget = WeatherAppWidgetProvider.COMPONENT_NAME val widgets = setOf(ecloudWidget, privacyWidget) } -- GitLab From e2ca2539d22a321281bc59bf6b60cbaeb17cb8ac Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 9 May 2022 15:28:14 +0700 Subject: [PATCH 2/2] Remove unused imports --- .../e/blisslauncher/features/launcher/LauncherActivity.java | 1 - 1 file changed, 1 deletion(-) 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 aed1b3c36a..7d5b99b7a3 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 @@ -143,7 +143,6 @@ 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.WeatherAppWidgetProvider; import foundation.e.blisslauncher.features.weather.WeatherPreferences; import foundation.e.blisslauncher.features.weather.WeatherSourceListenerService; import foundation.e.blisslauncher.features.weather.WeatherUpdateService; -- GitLab