launcher: collapse the folder a merged item was dragged out of
- Commit
9e5691ace535dabfe50c3a27b7908c30fe7382f2- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 19:59 UTC (28 days ago)
- Parents
7abea8a
Symptom: open a two-app folder, drag one app out and drop it onto another icon (or into another folder). The new folder is created correctly, but the old folder stays on the home screen as a folder containing a single app - a folder that should have collapsed back into that app's icon. Root cause: LauncherRepository.createFolder and addToFolder moved the dragged row into its new folder without checking the folder it came from. The plain-move path does check: LauncherViewModel.commitMoveImpl calls collapseFolderIfNeeded for the source folder after a move, but the merge path (mergeIntoFolderImpl -> createFolder / addToFolder) never did, so the single-child folder invariant that FolderRules.shouldCollapse defines was never enforced after a merge. Fix: capture the dragged item's container before the move in both repository functions and collapse that folder afterwards when it was one (and, for addToFolder, not the destination). This keeps the invariant in the repository, where the class doc says grid invariants are enforced, instead of adding a second call site in the ViewModel merge path. Verification: compile plus the existing domain and DAO suites; LauncherRepository itself is backed by the SQLCipher database and has no Robolectric harness in this module (the DAO suite uses an in-memory unencrypted database), so no repository regression test is added. Full module verification runs at the end of the stack.
Diff
launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt b/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.ktindex 525192ddf1..95d0c53a3e 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt@@ -207,16 +207,28 @@ class LauncherRepository private constructor(context: Context) : title = FolderRules.DEFAULT_FOLDER_TITLE, ), )+ val draggedFrom = dragged.container dao.move(target.id, folderId, 0, 0, 0, 0) dao.move(dragged.id, folderId, 0, 0, 0, 1)+ // The dragged item may have come out of another folder: leaving+ // that folder with a single child strands a folder that should+ // have collapsed back into its remaining icon. commitMove checks+ // this after a plain move; a merge is a move too.+ if (draggedFrom is ContainerRef.Folder) {+ collapseFolderIfNeeded(draggedFrom.id)+ } folderId } /** Appends [itemId] to an existing folder. */ suspend fun addToFolder(folderId: Long, itemId: Long) { db.withWriteTransaction {+ val draggedFrom = dao.get(itemId)?.container val ranks = dao.getFolderChildren(folderId).map { it.rank } dao.move(itemId, folderId, 0, 0, 0, FolderRules.nextRank(ranks))+ if (draggedFrom is ContainerRef.Folder && draggedFrom.id != folderId) {+ collapseFolderIfNeeded(draggedFrom.id)+ } } }