Commit 3b0f0c24 authored by Suphon Thanakornpakapong's avatar Suphon Thanakornpakapong
Browse files

Don't add widget if it already exists

parent 9f9e27f9
Pipeline #184174 failed with stage
in 2 minutes and 21 seconds
......@@ -420,22 +420,30 @@ public class LauncherActivity extends AppCompatActivity implements
}
private void addDefaultWidgets() {
int[] widgetIds = mAppWidgetHost.getAppWidgetIds();
Set<ComponentName> 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);
}
}
......
......@@ -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());
}
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)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment