mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-04-24 14:48:43 +02:00
Handle pages in shortcut pin request
This commit is contained in:
parent
d4b131ab23
commit
3742762220
@ -112,14 +112,14 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val shortcutId = item.shortcutInfo?.id!!
|
val shortcutId = item.shortcutInfo?.id!!
|
||||||
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: ""
|
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: ""
|
||||||
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
|
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
|
||||||
val rect = findFirstEmptyCell() ?: return@ensureBackgroundThread
|
val (page, rect) = findFirstEmptyCell()
|
||||||
val gridItem = HomeScreenGridItem(
|
val gridItem = HomeScreenGridItem(
|
||||||
null,
|
null,
|
||||||
rect.left,
|
rect.left,
|
||||||
rect.top,
|
rect.top,
|
||||||
rect.right,
|
rect.right,
|
||||||
rect.bottom,
|
rect.bottom,
|
||||||
0,
|
page,
|
||||||
item.shortcutInfo!!.`package`,
|
item.shortcutInfo!!.`package`,
|
||||||
"",
|
"",
|
||||||
label,
|
label,
|
||||||
@ -137,7 +137,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
item.accept()
|
item.accept()
|
||||||
home_screen_grid.storeAndShowGridItem(gridItem)
|
home_screen_grid.storeAndShowGridItem(gridItem, navigateToPage = true)
|
||||||
} catch (ignored: IllegalStateException) {
|
} catch (ignored: IllegalStateException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,27 +152,30 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findFirstEmptyCell(): Rect? {
|
private fun findFirstEmptyCell(): Pair<Int, Rect> {
|
||||||
val gridItems = homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
|
val gridItems = homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
|
||||||
val occupiedCells = ArrayList<Pair<Int, Int>>()
|
val maxPage = gridItems.map { it.page }.max()
|
||||||
|
val occupiedCells = ArrayList<Triple<Int, Int, Int>>()
|
||||||
gridItems.forEach { item ->
|
gridItems.forEach { item ->
|
||||||
for (xCell in item.left..item.right) {
|
for (xCell in item.left..item.right) {
|
||||||
for (yCell in item.top..item.bottom) {
|
for (yCell in item.top..item.bottom) {
|
||||||
occupiedCells.add(Pair(xCell, yCell))
|
occupiedCells.add(Triple(item.page, xCell, yCell))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (page in 0 until maxPage) {
|
||||||
for (checkedYCell in 0 until COLUMN_COUNT) {
|
for (checkedYCell in 0 until COLUMN_COUNT) {
|
||||||
for (checkedXCell in 0 until ROW_COUNT - 1) {
|
for (checkedXCell in 0 until ROW_COUNT - 1) {
|
||||||
val wantedCell = Pair(checkedXCell, checkedYCell)
|
val wantedCell = Triple(page, checkedXCell, checkedYCell)
|
||||||
if (!occupiedCells.contains(wantedCell)) {
|
if (!occupiedCells.contains(wantedCell)) {
|
||||||
return Rect(wantedCell.first, wantedCell.second, wantedCell.first, wantedCell.second)
|
return Pair(page, Rect(wantedCell.first, wantedCell.second, wantedCell.first, wantedCell.second))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return Pair(maxPage + 1, Rect(0, 0, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
@ -368,10 +368,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun storeAndShowGridItem(item: HomeScreenGridItem) {
|
fun storeAndShowGridItem(item: HomeScreenGridItem, navigateToPage: Boolean = false) {
|
||||||
val newId = context.homeScreenGridItemsDB.insert(item)
|
val newId = context.homeScreenGridItemsDB.insert(item)
|
||||||
item.id = newId
|
item.id = newId
|
||||||
gridItems.add(item)
|
gridItems.add(item)
|
||||||
|
if (navigateToPage) {
|
||||||
|
skipToPage(item.page)
|
||||||
|
}
|
||||||
redrawGrid()
|
redrawGrid()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -900,6 +903,17 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun skipToPage(targetPage: Int): Boolean {
|
||||||
|
if (targetPage < getMaxPage() + 1) {
|
||||||
|
lastPage = currentPage
|
||||||
|
currentPage = targetPage
|
||||||
|
handlePageChange()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
private fun handlePageChange(redraw: Boolean = false) {
|
private fun handlePageChange(redraw: Boolean = false) {
|
||||||
pageChangeEnabled = false
|
pageChangeEnabled = false
|
||||||
if (redraw) {
|
if (redraw) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user