fix: back button moves up a folder instead of closing app - #226
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The current “subfolder” detection uses parentId != ROOT_PARENT_ID, which can disable Back handling in legitimate subfolders (and enable it in unexpected cases), breaking the intended navigation behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates back-button handling in MainFileListFragment so that pressing Back at the root level closes the app (and also collapses the FAB menu when expanded), aligning behavior with the intent described in the PR description and referenced PR.
Changes:
- Adds an
OnBackPressedCallbackto intercept Back presses and collapse the FAB menu when expanded. - Enables/disables the back-press callback based on whether the FAB is expanded or the user is inside a subfolder.
- Refreshes the callback enabled-state when the displayed folder changes and when the FAB expand/collapse state changes.
File summaries
| File | Description |
|---|---|
| opencloudApp/src/main/java/eu/opencloud/android/presentation/files/filelist/MainFileListFragment.kt | Adds Back-press callback to collapse the FAB menu first and otherwise browse up, with conditional enablement at root level. |
Review details
Suppressed comments (1)
opencloudApp/src/main/java/eu/opencloud/android/presentation/files/filelist/MainFileListFragment.kt:517
isInSubfolderis derived fromparentId != ROOT_PARENT_ID, butROOT_PARENT_IDis also used as the root sentinel in browse-up logic (seemanageBrowseUp()), so folders directly under root can haveparentId == ROOT_PARENT_ID. In that case this callback will be disabled and Back will fall through to the Activity (exiting) instead of browsing up to root. Also, becauseparentIdis nullable,null != ROOT_PARENT_IDevaluates totrueand would incorrectly enable browse-up.
Derive the state from the actual folder being shown (e.g., remotePath != ROOT_PATH) so root is detected reliably.
private fun updateBackPressedCallbackState() {
val isInSubfolder = mainFileListViewModel.currentFolderDisplayed.value.parentId != ROOT_PARENT_ID
onBackPressedCallback.isEnabled = isFabExpanded() || isInSubfolder
}
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8464ebc to
49dc4b3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new back-press enablement logic treats a nullable parentId as “in subfolder,” which can enable the callback in invalid states and lead to a crash path in browse-up handling.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
074d80b to
415e256
Compare
415e256 to
2cdffb9
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The current diff introduces a compilation issue in onViewCreated and the back-press enablement logic can disable navigation in folders whose parent is root.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
| private fun updateBackPressedCallbackState() { | ||
| val parentId = mainFileListViewModel.currentFolderDisplayed.value.parentId | ||
| val isInSubfolder = parentId != null && parentId != ROOT_PARENT_ID | ||
| onBackPressedCallback.isEnabled = isFabExpanded() || isInSubfolder | ||
| } |
There was a problem hiding this comment.
🟡 Changes recommended
The new fragment-level back callback is likely ineffective because host activities override onBackPressed() and don’t delegate to the OnBackPressedDispatcher in the relevant paths.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
This is similar to oC #4943 but closes the FAB menu on root level as well.