do not allow resizing widgets to the bottom row

This commit is contained in:
tibbi 2022-10-05 11:43:22 +02:00
parent 0f536defce
commit dee6dcdd53

View file

@ -135,18 +135,19 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
frameRect.right - minWidth frameRect.right - minWidth
} }
val closestCellX = roundToClosestMultiplyOfNumber(wantedLeft - sideMargins.left, cellWidth) / cellWidth val wantedLeftCellX = roundToClosestMultiplyOfNumber(wantedLeft - sideMargins.left, cellWidth) / cellWidth
var areAllCellsFree = true var areAllCellsFree = true
for (xCell in closestCellX..cellsRect.right) { for (xCell in wantedLeftCellX..cellsRect.right) {
for (yCell in cellsRect.top..cellsRect.bottom) { for (yCell in cellsRect.top..cellsRect.bottom) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
if (areAllCellsFree && cellsRect.left != closestCellX) { if (areAllCellsFree && cellsRect.left != wantedLeftCellX) {
cellsRect.left = closestCellX cellsRect.left = wantedLeftCellX
cellChanged() cellChanged()
} }
@ -160,18 +161,19 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
frameRect.bottom - minHeight frameRect.bottom - minHeight
} }
val closestCellY = roundToClosestMultiplyOfNumber(wantedTop - sideMargins.top, cellHeight) / cellHeight val wantedTopCellY = roundToClosestMultiplyOfNumber(wantedTop - sideMargins.top, cellHeight) / cellHeight
var areAllCellsFree = true var areAllCellsFree = true
for (xCell in cellsRect.left..cellsRect.right) { for (xCell in cellsRect.left..cellsRect.right) {
for (yCell in closestCellY..cellsRect.bottom) { for (yCell in wantedTopCellY..cellsRect.bottom) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
if (areAllCellsFree && cellsRect.top != closestCellY) { if (areAllCellsFree && cellsRect.top != wantedTopCellY) {
cellsRect.top = closestCellY cellsRect.top = wantedTopCellY
cellChanged() cellChanged()
} }
@ -185,18 +187,19 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
frameRect.left + minWidth frameRect.left + minWidth
} }
val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1 val wantedRightCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1
var areAllCellsFree = true var areAllCellsFree = true
for (xCell in cellsRect.left..closestCellX) { for (xCell in cellsRect.left..wantedRightCellX) {
for (yCell in cellsRect.top..cellsRect.bottom) { for (yCell in cellsRect.top..cellsRect.bottom) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
if (areAllCellsFree && cellsRect.right != closestCellX) { if (areAllCellsFree && cellsRect.right != wantedRightCellX) {
cellsRect.right = closestCellX cellsRect.right = wantedRightCellX
cellChanged() cellChanged()
} }
@ -210,18 +213,23 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
frameRect.top + minHeight frameRect.top + minHeight
} }
val closestCellY = roundToClosestMultiplyOfNumber(wantedBottom - sideMargins.top, cellHeight) / cellHeight - 1 val wantedBottomCellY = roundToClosestMultiplyOfNumber(wantedBottom - sideMargins.top, cellHeight) / cellHeight - 1
var areAllCellsFree = true var areAllCellsFree = true
for (xCell in cellsRect.left..cellsRect.right) { for (xCell in cellsRect.left..cellsRect.right) {
for (yCell in cellsRect.top..closestCellY) { for (yCell in cellsRect.top..wantedBottomCellY) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
if (areAllCellsFree && cellsRect.bottom != closestCellY) { if (wantedBottomCellY == ROW_COUNT - 1) {
cellsRect.bottom = closestCellY areAllCellsFree = false
}
if (areAllCellsFree && cellsRect.bottom != wantedBottomCellY) {
cellsRect.bottom = wantedBottomCellY
cellChanged() cellChanged()
} }
@ -249,6 +257,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
for (yCell in cellsRect.top..cellsRect.bottom) { for (yCell in cellsRect.top..cellsRect.bottom) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
@ -268,6 +277,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
for (yCell in wantedTopCellY..cellsRect.bottom) { for (yCell in wantedTopCellY..cellsRect.bottom) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
@ -287,6 +297,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
for (yCell in cellsRect.top..cellsRect.bottom) { for (yCell in cellsRect.top..cellsRect.bottom) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
@ -306,10 +317,15 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
for (yCell in cellsRect.top..wantedBottomCellY + 1) { for (yCell in cellsRect.top..wantedBottomCellY + 1) {
if (occupiedCells.contains(Pair(xCell, yCell))) { if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false areAllCellsFree = false
break
} }
} }
} }
if (wantedBottomCellY == ROW_COUNT - 1) {
areAllCellsFree = false
}
if (areAllCellsFree) { if (areAllCellsFree) {
frameRect.bottom = wantedBottom + sideMargins.top frameRect.bottom = wantedBottom + sideMargins.top
cellsRect.bottom = wantedBottomCellY cellsRect.bottom = wantedBottomCellY