From fe5262301a9fda1395aae6ec719b90ad92c5ea4f Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Mon, 4 Feb 2019 17:05:38 +0100 Subject: [PATCH] Fixes #79, also fixes that widgets that are added and removed without closing the WidgetsActivity in between are added anyways and can't be removed. --- .../features/launcher/LauncherActivity.java | 5 ++++- .../e/blisslauncher/features/widgets/WidgetManager.java | 9 +++++++++ .../blisslauncher/features/widgets/WidgetsActivity.java | 5 ++++- 3 files changed, 17 insertions(+), 2 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 8c8c95c758..d82d51e46e 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 @@ -71,6 +71,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Comparator; import java.util.HashSet; @@ -1318,7 +1319,9 @@ public class LauncherActivity extends AppCompatActivity implements } // [[END]] - for (int id : mAppWidgetHost.getAppWidgetIds()) { + int[] widgetIds = mAppWidgetHost.getAppWidgetIds(); + Arrays.sort(widgetIds); + for (int id : widgetIds) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(id); if(appWidgetInfo != null){ RoundedWidgetView hostView = (RoundedWidgetView) mAppWidgetHost.createView( diff --git a/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetManager.java b/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetManager.java index 8e4fb017ad..27385e374c 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetManager.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetManager.java @@ -1,5 +1,6 @@ package foundation.e.blisslauncher.features.widgets; +import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; @@ -19,6 +20,14 @@ public class WidgetManager { } public void enqueueRemoveId(int id){ + // If the widget is not yet created but scheduled to be created we have to prevent the creation, too. + Iterator it = addWidgetViews.iterator(); + while(it.hasNext()){ + RoundedWidgetView view = it.next(); + if(id == view.getAppWidgetId()){ + addWidgetViews.remove(view); + } + } removeWidgetIds.add(id); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetsActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetsActivity.java index ea1e688953..9de4de3018 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetsActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetsActivity.java @@ -14,6 +14,7 @@ import foundation.e.blisslauncher.core.customviews.RoundedWidgetView; import foundation.e.blisslauncher.core.customviews.WidgetHost; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import foundation.e.blisslauncher.BlissLauncher; @@ -60,7 +61,9 @@ public class WidgetsActivity extends Activity implements AddedWidgetsAdapter.OnA private void refreshRecyclerView() { List widgets = new ArrayList<>(); - for (int id : mAppWidgetHost.getAppWidgetIds()) { + int[] widgetIds = mAppWidgetHost.getAppWidgetIds(); + Arrays.sort(widgetIds); + for (int id : widgetIds) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(id); if (appWidgetInfo != null) { Widget widget = new Widget(); -- GitLab