Remove needless extra space for folders
This commit is contained in:
parent
1fcda210b6
commit
e88eb05e00
|
@ -49,12 +49,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
private lateinit var binding: HomeScreenGridBinding
|
private lateinit var binding: HomeScreenGridBinding
|
||||||
private var columnCount = context.config.homeColumnCount
|
private var columnCount = context.config.homeColumnCount
|
||||||
private var rowCount = context.config.homeRowCount
|
private var rowCount = context.config.homeRowCount
|
||||||
private var dockTop = 0
|
private var pageIndicatorsYPos = 0
|
||||||
private val cells = mutableMapOf<Point, Rect>()
|
private val cells = mutableMapOf<Point, Rect>()
|
||||||
|
private var dockCellY = 0
|
||||||
var cellWidth = 0
|
var cellWidth = 0
|
||||||
var cellHeight = 0
|
var cellHeight = 0
|
||||||
private var extraXMargin = 0
|
|
||||||
private var extraYMargin = 0
|
|
||||||
|
|
||||||
private var iconMargin = (context.resources.getDimension(R.dimen.icon_side_margin) * 5 / columnCount).toInt()
|
private var iconMargin = (context.resources.getDimension(R.dimen.icon_side_margin) * 5 / columnCount).toInt()
|
||||||
private var labelSideMargin = context.resources.getDimension(com.simplemobiletools.commons.R.dimen.small_margin).toInt()
|
private var labelSideMargin = context.resources.getDimension(com.simplemobiletools.commons.R.dimen.small_margin).toInt()
|
||||||
|
@ -875,8 +874,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
private fun calculateWidgetPos(topLeft: Point): Point {
|
private fun calculateWidgetPos(topLeft: Point): Point {
|
||||||
val cell = cells[topLeft]!!
|
val cell = cells[topLeft]!!
|
||||||
return Point(
|
return Point(
|
||||||
cell.left + sideMargins.left + extraXMargin,
|
cell.left + sideMargins.left,
|
||||||
cell.top + sideMargins.top + extraYMargin
|
cell.top + sideMargins.top
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,7 +974,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val usableWidth = getFakeWidth()
|
val usableWidth = getFakeWidth()
|
||||||
val pageIndicatorsStart = (usableWidth - pageIndicatorsRequiredWidth) / 2 + sideMargins.left
|
val pageIndicatorsStart = (usableWidth - pageIndicatorsRequiredWidth) / 2 + sideMargins.left
|
||||||
var currentPageIndicatorLeft = pageIndicatorsStart
|
var currentPageIndicatorLeft = pageIndicatorsStart
|
||||||
val pageIndicatorY = dockTop.toFloat() + sideMargins.top + extraYMargin + iconMargin
|
val pageIndicatorY = pageIndicatorsYPos.toFloat() + sideMargins.top + iconMargin
|
||||||
val pageIndicatorStep = pageIndicatorRadius * 2 + pageIndicatorMargin
|
val pageIndicatorStep = pageIndicatorRadius * 2 + pageIndicatorMargin
|
||||||
emptyPageIndicatorPaint.alpha = pager.getPageChangeIndicatorsAlpha()
|
emptyPageIndicatorPaint.alpha = pager.getPageChangeIndicatorsAlpha()
|
||||||
// Draw empty page indicators
|
// Draw empty page indicators
|
||||||
|
@ -995,6 +994,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val items = folder.getItems()
|
val items = folder.getItems()
|
||||||
val folderRect = folder.getDrawingRect()
|
val folderRect = folder.getDrawingRect()
|
||||||
val folderItemsRect = folder.getItemsDrawingRect()
|
val folderItemsRect = folder.getItemsDrawingRect()
|
||||||
|
val cellSize = min(cellWidth, cellHeight)
|
||||||
|
|
||||||
val currentViewPosition = pager.getCurrentViewPositionInFullPageSpace() * width.toFloat()
|
val currentViewPosition = pager.getCurrentViewPositionInFullPageSpace() * width.toFloat()
|
||||||
val rectOffset = width * folder.item.page - currentViewPosition
|
val rectOffset = width * folder.item.page - currentViewPosition
|
||||||
|
@ -1023,13 +1023,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
|
|
||||||
items.forEach { item ->
|
items.forEach { item ->
|
||||||
val (row, column) = folder.getItemPosition(item)
|
val (row, column) = folder.getItemPosition(item)
|
||||||
val left = (folderItemsRect.left + column * cellWidth).roundToInt()
|
val left = (folderItemsRect.left + column * cellSize).roundToInt()
|
||||||
val top = (folderItemsRect.top + row * cellHeight).roundToInt()
|
val top = (folderItemsRect.top + row * cellSize).roundToInt()
|
||||||
val rect = Rect(
|
val rect = Rect(
|
||||||
left,
|
left,
|
||||||
top,
|
top,
|
||||||
left + cellWidth,
|
left + cellSize,
|
||||||
top + cellHeight
|
top + cellSize
|
||||||
)
|
)
|
||||||
canvas.drawItemInCell(item, rect)
|
canvas.drawItemInCell(item, rect)
|
||||||
}
|
}
|
||||||
|
@ -1047,11 +1047,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val center = folder.getItemsGridCenters().minBy {
|
val center = folder.getItemsGridCenters().minBy {
|
||||||
abs(it.second - draggedItemCurrentCoords.first + sideMargins.left) + abs(it.third - draggedItemCurrentCoords.second + sideMargins.top)
|
abs(it.second - draggedItemCurrentCoords.first + sideMargins.left) + abs(it.third - draggedItemCurrentCoords.second + sideMargins.top)
|
||||||
}
|
}
|
||||||
|
val cellSize = min(cellWidth, cellHeight)
|
||||||
|
|
||||||
val shadowX = center.second - cellWidth / 2 + iconMargin + iconSize / 2f + extraXMargin
|
val shadowX = center.second - cellSize / 2 + iconMargin + iconSize / 2f
|
||||||
val shadowY = center.third - cellHeight / 2 + iconMargin + iconSize / 2f + extraYMargin
|
val shadowY = center.third - cellSize / 2 + iconMargin + iconSize / 2
|
||||||
|
|
||||||
canvas.drawCircle(shadowX, shadowY, iconSize / 2f, dragShadowCirclePaint)
|
canvas.drawCircle(shadowX, shadowY.toFloat(), iconSize / 2f, dragShadowCirclePaint)
|
||||||
} else {
|
} else {
|
||||||
// draw a circle under the current cell
|
// draw a circle under the current cell
|
||||||
val center = gridCenters.minBy {
|
val center = gridCenters.minBy {
|
||||||
|
@ -1061,12 +1062,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val gridCells = getClosestGridCells(center)
|
val gridCells = getClosestGridCells(center)
|
||||||
if (gridCells != null) {
|
if (gridCells != null) {
|
||||||
val cell = cells[gridCells]!!
|
val cell = cells[gridCells]!!
|
||||||
val shadowX = cell.left + iconMargin + iconSize / 2f + extraXMargin + sideMargins.left
|
val shadowX = cell.left + iconMargin + iconSize / 2f + sideMargins.left
|
||||||
val shadowY = if (gridCells.y == rowCount - 1) {
|
val shadowY = if (gridCells.y == rowCount - 1) {
|
||||||
cell.top + cellHeight - iconMargin - iconSize / 2f
|
cellHeight - iconMargin - iconSize / 2f
|
||||||
} else {
|
} else {
|
||||||
cell.top + iconMargin + iconSize / 2f + extraYMargin
|
iconMargin + iconSize / 2f
|
||||||
} + sideMargins.top
|
} + sideMargins.top + cell.top
|
||||||
|
|
||||||
canvas.drawCircle(shadowX, shadowY, iconSize / 2f, dragShadowCirclePaint)
|
canvas.drawCircle(shadowX, shadowY, iconSize / 2f, dragShadowCirclePaint)
|
||||||
}
|
}
|
||||||
|
@ -1116,30 +1117,34 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillCellSizes() {
|
private fun fillCellSizes() {
|
||||||
cellWidth = getFakeWidth() / context.config.homeColumnCount
|
cellWidth = getFakeWidth() / columnCount
|
||||||
cellHeight = getFakeHeight() / context.config.homeRowCount
|
cellHeight = getFakeHeight() / rowCount
|
||||||
extraXMargin = if (cellWidth > cellHeight) {
|
val extraXMargin = if (cellWidth > cellHeight) {
|
||||||
(cellWidth - cellHeight) / 2
|
(cellWidth - cellHeight) / 2
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
extraYMargin = if (cellHeight > cellWidth) {
|
val extraYMargin = if (cellHeight > cellWidth) {
|
||||||
(cellHeight - cellWidth) / 2
|
(cellHeight - cellWidth) / 2
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
iconSize = min(cellWidth, cellHeight) - 2 * iconMargin
|
iconSize = min(cellWidth, cellHeight) - 2 * iconMargin
|
||||||
dockTop = (context.config.homeRowCount - 1) * cellHeight
|
pageIndicatorsYPos = (rowCount - 1) * cellHeight + extraYMargin
|
||||||
for (i in 0 until context.config.homeColumnCount) {
|
for (i in 0 until columnCount) {
|
||||||
for (j in 0 until context.config.homeRowCount) {
|
for (j in 0 until rowCount) {
|
||||||
|
val yMarginToAdd = if (j == rowCount - 1) 0 else extraYMargin
|
||||||
val rect = Rect(
|
val rect = Rect(
|
||||||
i * cellWidth,
|
i * cellWidth + extraXMargin,
|
||||||
j * cellHeight,
|
j * cellHeight + yMarginToAdd,
|
||||||
(i + 1) * cellWidth,
|
(i + 1) * cellWidth - extraXMargin,
|
||||||
(j + 1) * cellHeight,
|
(j + 1) * cellHeight - yMarginToAdd,
|
||||||
)
|
)
|
||||||
cells[Point(i, j)] = rect
|
cells[Point(i, j)] = rect
|
||||||
gridCenters.add(Point(rect.centerX(), rect.centerY()))
|
gridCenters.add(Point(rect.centerX(), rect.centerY()))
|
||||||
|
if (j == rowCount - 1) {
|
||||||
|
dockCellY = j * cellHeight
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1169,15 +1174,15 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
if (folder != null && item.parentId == folder.item.id) {
|
if (folder != null && item.parentId == folder.item.id) {
|
||||||
val folderRect = folder.getItemsDrawingRect()
|
val folderRect = folder.getItemsDrawingRect()
|
||||||
val (row, column) = folder.getItemPosition(item)
|
val (row, column) = folder.getItemPosition(item)
|
||||||
clickableLeft = (folderRect.left + column * cellWidth + extraXMargin).toInt()
|
clickableLeft = (folderRect.left + column * cellWidth).toInt()
|
||||||
clickableTop = (folderRect.top + row * cellHeight - iconMargin + extraYMargin).toInt()
|
clickableTop = (folderRect.top + row * cellHeight - iconMargin).toInt()
|
||||||
} else {
|
} else {
|
||||||
val cell = cells[item.getTopLeft()]!!
|
val cell = cells[item.getTopLeft()]!!
|
||||||
clickableLeft = cell.left + sideMargins.left + extraXMargin
|
clickableLeft = cell.left + sideMargins.left
|
||||||
clickableTop = if (item.docked) {
|
clickableTop = if (item.docked) {
|
||||||
dockTop + cellHeight - iconSize - iconMargin
|
dockCellY + cellHeight - iconSize - iconMargin
|
||||||
} else {
|
} else {
|
||||||
cell.top - iconMargin + extraYMargin
|
cell.top - iconMargin
|
||||||
} + sideMargins.top
|
} + sideMargins.top
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1361,7 +1366,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
|
|
||||||
private fun Canvas.drawItemInCell(item: HomeScreenGridItem, cell: Rect) {
|
private fun Canvas.drawItemInCell(item: HomeScreenGridItem, cell: Rect) {
|
||||||
if (item.id != draggedItem?.id) {
|
if (item.id != draggedItem?.id) {
|
||||||
val drawableX = cell.left + iconMargin + extraXMargin
|
val drawableX = cell.left + iconMargin
|
||||||
|
|
||||||
val drawable = if (item.type == ITEM_TYPE_FOLDER) {
|
val drawable = if (item.type == ITEM_TYPE_FOLDER) {
|
||||||
item.toFolder().generateDrawable()
|
item.toFolder().generateDrawable()
|
||||||
|
@ -1370,16 +1375,16 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.docked) {
|
if (item.docked) {
|
||||||
val drawableY = dockTop + cellHeight - iconMargin - iconSize + sideMargins.top
|
val drawableY = dockCellY + cellHeight - iconMargin - iconSize + sideMargins.top
|
||||||
|
|
||||||
drawable?.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
drawable?.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
||||||
} else {
|
} else {
|
||||||
val drawableY = cell.top + iconMargin + extraYMargin
|
val drawableY = cell.top + iconMargin
|
||||||
drawable?.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
drawable?.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
||||||
|
|
||||||
if (item.id != draggedItem?.id && item.title.isNotEmpty()) {
|
if (item.id != draggedItem?.id && item.title.isNotEmpty()) {
|
||||||
val textX = cell.left.toFloat() + labelSideMargin
|
val textX = cell.left.toFloat() + labelSideMargin
|
||||||
val textY = cell.top.toFloat() + iconSize + iconMargin + extraYMargin + labelSideMargin
|
val textY = cell.top.toFloat() + iconSize + iconMargin + labelSideMargin
|
||||||
val textPaintToUse = if (item.parentId == null) {
|
val textPaintToUse = if (item.parentId == null) {
|
||||||
textPaint
|
textPaint
|
||||||
} else {
|
} else {
|
||||||
|
@ -1490,11 +1495,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
val columnsCount = ceil(sqrt(count.toDouble())).toInt()
|
val columnsCount = ceil(sqrt(count.toDouble())).toInt()
|
||||||
val rowsCount = ceil(count.toFloat() / columnsCount).toInt()
|
val rowsCount = ceil(count.toFloat() / columnsCount).toInt()
|
||||||
|
val cellSize = min(cellWidth, cellHeight)
|
||||||
val cell = cells[item.getTopLeft()]!!
|
val cell = cells[item.getTopLeft()]!!
|
||||||
val centerX = sideMargins.left + cell.centerX()
|
val centerX = sideMargins.left + cell.centerX()
|
||||||
val centerY = sideMargins.top + cell.centerY()
|
val centerY = sideMargins.top + cell.centerY()
|
||||||
val folderDialogWidth = columnsCount * cellWidth + 2 * folderPadding
|
val folderDialogWidth = columnsCount * cellSize + 2 * folderPadding
|
||||||
val folderDialogHeight = rowsCount * cellHeight + 3 * folderPadding + folderTitleTextPaint.textSize
|
val folderDialogHeight = rowsCount * cellSize + 3 * folderPadding + folderTitleTextPaint.textSize
|
||||||
var folderDialogTop = centerY - folderDialogHeight / 2
|
var folderDialogTop = centerY - folderDialogHeight / 2
|
||||||
var folderDialogLeft = centerX - folderDialogWidth / 2
|
var folderDialogLeft = centerX - folderDialogWidth / 2
|
||||||
|
|
||||||
|
@ -1529,14 +1535,15 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val columnsCount = ceil(sqrt(count.toDouble())).roundToInt()
|
val columnsCount = ceil(sqrt(count.toDouble())).roundToInt()
|
||||||
val rowsCount = ceil(count.toFloat() / columnsCount).roundToInt()
|
val rowsCount = ceil(count.toFloat() / columnsCount).roundToInt()
|
||||||
val folderItemsRect = getItemsDrawingRect()
|
val folderItemsRect = getItemsDrawingRect()
|
||||||
|
val cellSize = min(cellWidth, cellHeight)
|
||||||
return (0 until columnsCount * rowsCount)
|
return (0 until columnsCount * rowsCount)
|
||||||
.toList()
|
.toList()
|
||||||
.map { Pair(it % columnsCount, it / columnsCount) }
|
.map { Pair(it % columnsCount, it / columnsCount) }
|
||||||
.mapIndexed { index, (x, y) ->
|
.mapIndexed { index, (x, y) ->
|
||||||
Triple(
|
Triple(
|
||||||
index,
|
index,
|
||||||
(folderItemsRect.left + x * cellWidth + cellWidth / 2).toInt(),
|
(folderItemsRect.left + x * cellSize + cellSize / 2).toInt(),
|
||||||
(folderItemsRect.top + y * cellHeight + cellHeight / 2).toInt()
|
(folderItemsRect.top + y * cellSize + cellSize / 2).toInt()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue