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 1906f4852ef2eb50ac6888ea9da4083210da97c9..7d5b99b7a313269f29dffe3ee4cbb9ce44261f99 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; @@ -420,22 +419,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 8643eac04096b4a9946ea245eb98de7f485c9c3c..29bccfb05cb85dc23ff8a5ce7a6765acfed9309c 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 67ec3b898f4b91e6676331f931da13ecf9e55433..62d66603b42f4b09792d758e347c42a647b5f5a3 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) }