Add enough gaps between folder items to show item names
This commit is contained in:
parent
e88eb05e00
commit
b7eecc5663
|
@ -302,7 +302,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val coveredCell = getClosestGridCells(center)
|
val coveredCell = getClosestGridCells(center)
|
||||||
if (coveredCell != null) {
|
if (coveredCell != null) {
|
||||||
val coveredFolder = gridItems.firstOrNull { it.type == ITEM_TYPE_FOLDER && it.left == coveredCell.x && it.top == coveredCell.y }
|
val coveredFolder = gridItems.firstOrNull { it.type == ITEM_TYPE_FOLDER && it.left == coveredCell.x && it.top == coveredCell.y }
|
||||||
if (coveredFolder != null && coveredFolder.id != draggedItem?.id) {
|
if (coveredFolder != null && coveredFolder.id != draggedItem?.id && currentlyOpenFolder == null) {
|
||||||
draggingEnteredNewFolderAt.also {
|
draggingEnteredNewFolderAt.also {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
draggingEnteredNewFolderAt = System.currentTimeMillis()
|
draggingEnteredNewFolderAt = System.currentTimeMillis()
|
||||||
|
@ -993,8 +993,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
if (folder != null && folder.getItems().isNotEmpty()) {
|
if (folder != null && folder.getItems().isNotEmpty()) {
|
||||||
val items = folder.getItems()
|
val items = folder.getItems()
|
||||||
val folderRect = folder.getDrawingRect()
|
val folderRect = folder.getDrawingRect()
|
||||||
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
|
||||||
|
@ -1003,7 +1001,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
canvas.withScale(folder.scale, folder.scale, folderRect.centerX(), folderRect.centerY()) {
|
canvas.withScale(folder.scale, folder.scale, folderRect.centerX(), folderRect.centerY()) {
|
||||||
canvas.drawRoundRect(folderRect, roundedCornerRadius / folder.scale, roundedCornerRadius / folder.scale, folderBackgroundPaint)
|
canvas.drawRoundRect(folderRect, roundedCornerRadius / folder.scale, roundedCornerRadius / folder.scale, folderBackgroundPaint)
|
||||||
val textX = folderRect.left + folderPadding
|
val textX = folderRect.left + folderPadding
|
||||||
val textY = folderRect.top + folderPadding + folderTitleTextPaint.textSize
|
val textY = folderRect.top + folderPadding
|
||||||
val staticLayout = StaticLayout.Builder
|
val staticLayout = StaticLayout.Builder
|
||||||
.obtain(
|
.obtain(
|
||||||
folder.item.title,
|
folder.item.title,
|
||||||
|
@ -1022,16 +1020,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
|
|
||||||
items.forEach { item ->
|
items.forEach { item ->
|
||||||
val (row, column) = folder.getItemPosition(item)
|
val itemRect = folder.getItemRect(item)
|
||||||
val left = (folderItemsRect.left + column * cellSize).roundToInt()
|
// canvas.drawRect(itemRect, contrastTextPaint)
|
||||||
val top = (folderItemsRect.top + row * cellSize).roundToInt()
|
canvas.drawItemInCell(item, itemRect)
|
||||||
val rect = Rect(
|
|
||||||
left,
|
|
||||||
top,
|
|
||||||
left + cellSize,
|
|
||||||
top + cellSize
|
|
||||||
)
|
|
||||||
canvas.drawItemInCell(item, rect)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1038,7 @@ 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 cellSize = folder.getCellSize()
|
||||||
|
|
||||||
val shadowX = center.second - cellSize / 2 + iconMargin + iconSize / 2f
|
val shadowX = center.second - cellSize / 2 + iconMargin + iconSize / 2f
|
||||||
val shadowY = center.third - cellSize / 2 + iconMargin + iconSize / 2
|
val shadowY = center.third - cellSize / 2 + iconMargin + iconSize / 2
|
||||||
|
@ -1172,10 +1163,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
val clickableLeft: Int
|
val clickableLeft: Int
|
||||||
val clickableTop: Int
|
val clickableTop: Int
|
||||||
if (folder != null && item.parentId == folder.item.id) {
|
if (folder != null && item.parentId == folder.item.id) {
|
||||||
val folderRect = folder.getItemsDrawingRect()
|
val itemRect = folder.getItemRect(item)
|
||||||
val (row, column) = folder.getItemPosition(item)
|
clickableLeft = itemRect.left
|
||||||
clickableLeft = (folderRect.left + column * cellWidth).toInt()
|
clickableTop = itemRect.top - iconMargin
|
||||||
clickableTop = (folderRect.top + row * cellHeight - iconMargin).toInt()
|
|
||||||
} else {
|
} else {
|
||||||
val cell = cells[item.getTopLeft()]!!
|
val cell = cells[item.getTopLeft()]!!
|
||||||
clickableLeft = cell.left + sideMargins.left
|
clickableLeft = cell.left + sideMargins.left
|
||||||
|
@ -1495,12 +1485,14 @@ 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 cellSize = getCellSize()
|
||||||
|
val gap = getGapSize()
|
||||||
|
val yGap = gap + textPaint.textSize + 2 * labelSideMargin
|
||||||
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 * cellSize + 2 * folderPadding
|
val folderDialogWidth = columnsCount * cellSize + 2 * folderPadding + (columnsCount - 1) * gap
|
||||||
val folderDialogHeight = rowsCount * cellSize + 3 * folderPadding + folderTitleTextPaint.textSize
|
val folderDialogHeight = rowsCount * cellSize + 3 * folderPadding + folderTitleTextPaint.textSize + rowsCount * yGap
|
||||||
var folderDialogTop = centerY - folderDialogHeight / 2
|
var folderDialogTop = centerY - folderDialogHeight / 2
|
||||||
var folderDialogLeft = centerX - folderDialogWidth / 2
|
var folderDialogLeft = centerX - folderDialogWidth / 2
|
||||||
|
|
||||||
|
@ -1535,20 +1527,22 @@ 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)
|
val cellSize = getCellSize()
|
||||||
|
val gap = getGapSize()
|
||||||
|
val yGap = gap + textPaint.textSize + 2 * labelSideMargin
|
||||||
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 * cellSize + cellSize / 2).toInt(),
|
(folderItemsRect.left + x * cellSize + x * gap + cellSize / 2).toInt(),
|
||||||
(folderItemsRect.top + y * cellSize + cellSize / 2).toInt()
|
(folderItemsRect.top + y * cellSize + y * yGap + cellSize / 2).toInt()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getItemPosition(item: HomeScreenGridItem): Pair<Int, Int> {
|
private fun getItemPosition(item: HomeScreenGridItem): Pair<Int, Int> {
|
||||||
val count = getItems().count()
|
val count = getItems().count()
|
||||||
val columnsCount = ceil(sqrt(count.toDouble())).roundToInt()
|
val columnsCount = ceil(sqrt(count.toDouble())).roundToInt()
|
||||||
val column = item.left % columnsCount
|
val column = item.left % columnsCount
|
||||||
|
@ -1556,6 +1550,22 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
return Pair(row, column)
|
return Pair(row, column)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getItemRect(item: HomeScreenGridItem): Rect {
|
||||||
|
val (row, column) = getItemPosition(item)
|
||||||
|
val itemsRect = getItemsDrawingRect()
|
||||||
|
val cellSize = getCellSize()
|
||||||
|
val gapSize = getGapSize()
|
||||||
|
val yGapSize = gapSize + textPaint.textSize + 2 * labelSideMargin
|
||||||
|
val left = (itemsRect.left + column * cellSize + column * gapSize).roundToInt()
|
||||||
|
val top = (itemsRect.top + row * cellSize + row * yGapSize).roundToInt()
|
||||||
|
return Rect(
|
||||||
|
left,
|
||||||
|
top,
|
||||||
|
left + cellSize,
|
||||||
|
top + cellSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun animateClosing(callback: () -> Unit) {
|
fun animateClosing(callback: () -> Unit) {
|
||||||
post {
|
post {
|
||||||
if (closing) {
|
if (closing) {
|
||||||
|
@ -1581,6 +1591,17 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCellSize(): Int = min(cellWidth, cellHeight)
|
||||||
|
|
||||||
|
private fun getGapSize(): Float {
|
||||||
|
val cellSize = getCellSize()
|
||||||
|
return if (cellSize == cellWidth) {
|
||||||
|
0f
|
||||||
|
} else {
|
||||||
|
cellSize / 5f
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Loading…
Reference in New Issue