Prevent generating drawables for empty folders

This commit is contained in:
Ensar Sarajčić 2023-09-21 12:03:19 +02:00
parent f46b6fcc2c
commit 6766e46c37
1 changed files with 7 additions and 2 deletions

View File

@ -1502,13 +1502,18 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
return null return null
} }
val items = getItems()
val itemsCount = getItems().count()
if (itemsCount == 0) {
return null
}
val bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888) val bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap) val canvas = Canvas(bitmap)
val circlePath = Path().apply { addCircle((iconSize / 2).toFloat(), (iconSize / 2).toFloat(), (iconSize / 2).toFloat(), Path.Direction.CCW) } val circlePath = Path().apply { addCircle((iconSize / 2).toFloat(), (iconSize / 2).toFloat(), (iconSize / 2).toFloat(), Path.Direction.CCW) }
canvas.clipPath(circlePath) canvas.clipPath(circlePath)
canvas.drawPaint(folderIconBackgroundPaint) canvas.drawPaint(folderIconBackgroundPaint)
val items = getItems()
val itemsCount = getItems().count()
val folderColumnCount = ceil(sqrt(itemsCount.toDouble())).roundToInt() val folderColumnCount = ceil(sqrt(itemsCount.toDouble())).roundToInt()
val folderRowCount = ceil(itemsCount.toFloat() / folderColumnCount).roundToInt() val folderRowCount = ceil(itemsCount.toFloat() / folderColumnCount).roundToInt()
val scaledCellSize = (iconSize.toFloat() / folderColumnCount) val scaledCellSize = (iconSize.toFloat() / folderColumnCount)