From 360f7e774b8019ccb1dc3f5a700ac38c859102c1 Mon Sep 17 00:00:00 2001 From: Ptitg <105381847+Ptitg@users.noreply.github.com> Date: Sat, 14 May 2022 16:34:15 +0200 Subject: [PATCH] [FIX] Widgets disappear randomly and reappear on their own or eventually long tapping on their original place --- .../openlauncher/widget/WidgetContainer.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/benny/openlauncher/widget/WidgetContainer.java b/app/src/main/java/com/benny/openlauncher/widget/WidgetContainer.java index 660caeeda..4186d9db0 100644 --- a/app/src/main/java/com/benny/openlauncher/widget/WidgetContainer.java +++ b/app/src/main/java/com/benny/openlauncher/widget/WidgetContainer.java @@ -125,11 +125,19 @@ public void scaleWidget(View view, Item item) { } public void updateWidgetOption(Item item) { + int cellWidth = HomeActivity.Companion.getLauncher().getDesktop().getCurrentPage().getCellWidth(); + int cellHeight = HomeActivity.Companion.getLauncher().getDesktop().getCurrentPage().getCellHeight(); + + if (cellWidth < 1 || cellHeight < 1) { + // desktop isn't laid out + return; + } + Bundle newOps = new Bundle(); - newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, item.getSpanX() * HomeActivity.Companion.getLauncher().getDesktop().getCurrentPage().getCellWidth()); - newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, item.getSpanX() * HomeActivity.Companion.getLauncher().getDesktop().getCurrentPage().getCellWidth()); - newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, item.getSpanY() * HomeActivity.Companion.getLauncher().getDesktop().getCurrentPage().getCellHeight()); - newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, item.getSpanY() * HomeActivity.Companion.getLauncher().getDesktop().getCurrentPage().getCellHeight()); + newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, item.getSpanX() * cellWidth); + newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, item.getSpanX() * cellWidth); + newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, item.getSpanY() * cellHeight); + newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, item.getSpanY() * cellHeight); HomeActivity._appWidgetManager.updateAppWidgetOptions(item.getWidgetValue(), newOps); } }