Add max capacity for folders

This commit is contained in:
Ensar Sarajčić 2023-08-21 08:44:46 +02:00
parent c83e7a5226
commit cca2ceaab9
2 changed files with 22 additions and 1 deletions

View File

@ -33,6 +33,10 @@ data class HomeScreenGridItem(
@Ignore var widthCells: Int = 1,
@Ignore var heightCells: Int = 1
) {
companion object {
const val FOLDER_MAX_CAPACITY = 16
}
constructor() : this(null, -1, -1, -1, -1, 0, "", "", "", ITEM_TYPE_ICON, "", -1, "", null, false, null, null, null, null, 1, 1)
fun getWidthInCells() = if (right == -1 || left == -1) {

View File

@ -313,9 +313,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
if (it == null) {
draggingEnteredNewFolderAt = System.currentTimeMillis()
} else if (System.currentTimeMillis() - it > PAGE_CHANGE_HOLD_THRESHOLD) {
if (coveredFolder.getFolderItems().count() >= HomeScreenGridItem.FOLDER_MAX_CAPACITY && draggedItem?.parentId != coveredFolder.id) {
performHapticFeedback()
draggingEnteredNewFolderAt = null
} else {
openFolder(coveredFolder)
}
}
}
} else {
draggingEnteredNewFolderAt = null
}
@ -597,6 +602,18 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
newParentId: Long? = null,
toFolderEnd: Boolean = true
) {
if (newParentId != null && newParentId != draggedHomeGridItem?.parentId) {
gridItems.firstOrNull { it.id == newParentId }?.also {
if (it.getFolderItems().count() >= HomeScreenGridItem.FOLDER_MAX_CAPACITY) {
performHapticFeedback()
draggedItem = null
draggedItemCurrentCoords = Pair(-1, -1)
redrawGrid()
return
}
}
}
val finalXIndex = if (newParentId != null) {
if (toFolderEnd) {
gridItems.firstOrNull { it.id == newParentId }?.getFolderItems()?.maxOf { it.left + 1 } ?: 0