Skip to content

fix: back button moves up a folder instead of closing app - #226

Open
wernrab wants to merge 1 commit into
opencloud-eu:mainfrom
wernrab:fix_folder_up
Open

fix: back button moves up a folder instead of closing app#226
wernrab wants to merge 1 commit into
opencloud-eu:mainfrom
wernrab:fix_folder_up

Conversation

@wernrab

@wernrab wernrab commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

This is similar to oC #4943 but closes the FAB menu on root level as well.

@wernrab wernrab self-assigned this Sep 10, 2026
@wernrab
wernrab marked this pull request as ready for review September 10, 2026 14:23
Copilot AI lite review requested due to automatic review settings September 10, 2026 14:23
@guruz
guruz self-requested a review September 10, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 OnBackPressedCallback to 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

  • isInSubfolder is derived from parentId != ROOT_PARENT_ID, but ROOT_PARENT_ID is also used as the root sentinel in browse-up logic (see manageBrowseUp()), so folders directly under root can have parentId == 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, because parentId is nullable, null != ROOT_PARENT_ID evaluates to true and 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +515 to +519
private fun updateBackPressedCallbackState() {
val parentId = mainFileListViewModel.currentFolderDisplayed.value.parentId
val isInSubfolder = parentId != null && parentId != ROOT_PARENT_ID
onBackPressedCallback.isEnabled = isFabExpanded() || isInSubfolder
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants