@@ -76,7 +76,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
7676 private var draggedItem: HomeScreenGridItem ? = null
7777 private var resizedWidget: HomeScreenGridItem ? = null
7878 private var isFirstDraw = true
79- private var redrawWidgets = false
8079 private var iconSize = 0
8180
8281 private val pager = AnimatedGridPager (
@@ -212,7 +211,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
212211 cells.clear()
213212 gridCenters.clear()
214213 iconMargin = (context.resources.getDimension(R .dimen.icon_side_margin) * 5 / columnCount).toInt()
215- redrawWidgets = true
214+ isFirstDraw = true
215+ gridItems.filter { it.type == ITEM_TYPE_WIDGET }.forEach {
216+ appWidgetHost.deleteAppWidgetId(it.widgetId)
217+ }
218+ widgetViews.forEach { removeView(it) }
219+ widgetViews.clear()
216220 redrawGrid()
217221 }
218222 }
@@ -835,6 +839,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
835839 }
836840
837841 private fun bindWidget (item : HomeScreenGridItem , isInitialDrawAfterLaunch : Boolean ) {
842+ if (item.outOfBounds()) {
843+ return
844+ }
845+
838846 val activity = context as MainActivity
839847 val appWidgetProviderInfo = item.providerInfo ? : appWidgetManager!! .installedProviders.firstOrNull { it.provider.className == item.className }
840848 if (appWidgetProviderInfo != null ) {
@@ -1298,7 +1306,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
12981306 }
12991307
13001308 private fun HomeScreenGridItem.outOfBounds (): Boolean {
1301- return (left >= columnCount || right >= columnCount || (! docked && (top >= rowCount - 1 || bottom >= rowCount - 1 )))
1309+ return (left >= columnCount
1310+ || right >= columnCount
1311+ || (! docked && (top >= rowCount - 1 || bottom >= rowCount - 1 ))
1312+ || (type == ITEM_TYPE_WIDGET && (bottom - top > rowCount - 1 || right - left > columnCount - 1 ))
1313+ )
13021314 }
13031315
13041316 private inner class HomeScreenGridTouchHelper (host : View ) : ExploreByTouchHelper(host) {
0 commit comments