Skip to content

Feat: "Add to Home screen" option to create folder shortcuts with deep link - #219

Open
Lightz2002 wants to merge 14 commits into
opencloud-eu:mainfrom
Lightz2002:main
Open

Lightz2002 wants to merge 14 commits into
opencloud-eu:mainfrom
Lightz2002:main

Conversation

@Lightz2002

Copy link
Copy Markdown
  • Adds an "Add to Home screen" action for folders that pins a launcher shortcut,
    deep-linking straight into that folder when tapped.

Changes

  • Add ADD_TO_HOME_SCREEN to FileMenuOption and wire it into the file actions menu
    (action_add_to_home) with a new icon; only shown for single-selected folders via
    FilterFileMenuOptionsUseCase
  • New AddToHomeScreenDialogFragment: pre-filled, editable shortcut name with validation
    (empty name, max filename length, forbidden characters)
  • New FolderShortcutHelper: creates a pinned shortcut via ShortcutManager (API 26+),
    embedding the folder's remote ID, remote path, and space ID in the intent
  • FileDisplayActivity handles the new OPEN_SHORTCUT action: resolves the folder by
    remote path + space ID from local storage and navigates directly into it; extras are
    consumed after handling; shows an error snackbar if the folder no longer exists locally

Notes

  • Devices below API 26 show a toast instead of creating a shortcut
  • Shortcut opens in All Files view regardless of the last used file list option

Testing

  • Long-press/overflow menu on a folder → "Add to Home screen" → confirm → pin the shortcut
  • Tap the shortcut → app opens directly inside the target folder
  • Rename the shortcut in the dialog; verify empty names / forbidden chars are rejected
  • Delete the folder, then tap the shortcut → error message shown

@wernrab
wernrab requested review from guruz and wernrab August 31, 2026 13:56
@guruz

guruz commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

@wernrab can you review this one?

@Lightz2002 I think "add folder path to home screen" is a not so good commit message.

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

There are user-visible correctness issues (misleading success messaging and incomplete/unsafe validation + a potential pre-contentView snackbar crash path) that should be fixed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an “Add to Home screen” action for folder items, allowing users to pin a launcher shortcut that deep-links back into the selected folder, with UI for naming/validating the shortcut and runtime handling to open the target folder.

Changes:

  • Introduces a new FileMenuOption.ADD_TO_HOME_SCREEN and wires it into the file actions menu (icon + string resources).
  • Adds AddToHomeScreenDialogFragment to collect/validate the shortcut name and FolderShortcutHelper to request a pinned shortcut via ShortcutManager.
  • Extends FileDisplayActivity to process the shortcut intent and navigate into the resolved folder.
File summaries
File Description
opencloudDomain/src/main/java/eu/opencloud/android/domain/files/model/FileMenuOption.kt Adds a new menu option enum value for the feature.
opencloudApp/src/main/res/values/strings.xml Adds UI strings for the new menu item and dialog.
opencloudApp/src/main/res/menu/file_actions_menu.xml Adds the new “Add to Home screen” menu item.
opencloudApp/src/main/res/drawable/ic_action_add_to_home.xml Adds the vector icon for the new action.
opencloudApp/src/main/java/eu/opencloud/android/usecases/files/FilterFileMenuOptionsUseCase.kt Shows the option only for single-selected folders.
opencloudApp/src/main/java/eu/opencloud/android/ui/activity/FileDisplayActivity.kt Handles shortcut intents and navigates into the folder.
opencloudApp/src/main/java/eu/opencloud/android/presentation/files/filelist/MainFileListFragment.kt Opens the new dialog and triggers shortcut creation.
opencloudApp/src/main/java/eu/opencloud/android/presentation/files/addtohomescreen/FolderShortcutHelper.kt Implements pinned shortcut creation and intent extras.
opencloudApp/src/main/java/eu/opencloud/android/presentation/files/addtohomescreen/AddToHomeScreenDialogFragment.kt Adds the shortcut naming dialog with validation.
opencloudApp/src/main/java/eu/opencloud/android/extensions/FileMenuOptionExt.kt Maps the new option to menu id/string/icon resources.
Review details

Suppressed comments (1)

opencloudApp/src/main/java/eu/opencloud/android/presentation/files/addtohomescreen/FolderShortcutHelper.kt:36

  • requestPinShortcut() can fail/return false; also when pinning isn’t supported the code currently shows the same “added” success toast. This can report success even when the launcher declined/doesn’t support pinning.
        if (shortcutManager?.isRequestPinShortcutSupported != true) {
            Toast.makeText(context, context.getString(R.string.add_to_home_screen_shortcut_added), Toast.LENGTH_SHORT).show()
            return
        }
  • Files reviewed: 10/10 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Lightz2002

Copy link
Copy Markdown
Author

Hi @guruz , Please kindly inform me if there are changes i need to make since the pr is failing, thanks

@guruz

guruz commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Hey @Lightz2002 ! You can run detekt also on your local machine with ./gradlew build, it should run detekt for you.
See detekt output here: https://github.com/opencloud-eu/android/actions/runs/33406305453/job/100174046056?pr=219

@wernrab We should really change this maximum function length from 100 to 200 or whatever :(

@guruz

guruz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@wernrab We should really change this maximum function length from 100 to 200 or whatever :(

-> #225

@Lightz2002

Copy link
Copy Markdown
Author

hi @guruz @wernrab , i have commited again to pass the detekt last time. can you help check and review again, thanks.

wernrab

This comment was marked as resolved.

@wernrab

This comment was marked as outdated.

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

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (3)

opencloudApp/src/main/java/eu/opencloud/android/presentation/files/addtohomescreen/FolderShortcutHelper.kt:52

  • The dialog allows names up to the filesystem limit (223 characters), but Android pinned shortcuts impose much smaller limits on shortLabel/longLabel. A valid 26+ character input can therefore fail during ShortcutInfo validation or pinning instead of creating the shortcut. Validate against the shortcut API limits or deliberately truncate before building it.
        val shortcut = ShortcutInfo.Builder(context, shortcutId)
            .setShortLabel(shortcutName)
            .setLongLabel(shortcutName)

opencloudApp/src/main/java/eu/opencloud/android/presentation/files/addtohomescreen/FolderShortcutHelper.kt:27

  • On API levels below 26 this branch cannot create a pinned shortcut, but it displays the success message Shortcut added to Home screen. Users are therefore told the action succeeded even though no shortcut was created; use an unsupported-version message or hide/disable the action.
            Toast.makeText(context, context.getString(R.string.add_to_home_screen_shortcut_added), Toast.LENGTH_SHORT).show()

opencloudApp/src/main/java/eu/opencloud/android/ui/activity/FileDisplayActivity.kt:1992

  • This error path runs from onCreate before setContentView initializes the activity layout. Consequently findViewById(R.id.list_layout) is null and Snackbar.make can fail, so tapping a shortcut for a deleted folder crashes instead of showing the documented error. Defer the snackbar until after the content view is set.
                showMessageInSnackbar(R.id.list_layout, getString(R.string.default_error_msg))
  • Files reviewed: 10/10 changed files
  • Comments generated: 4
  • Review effort level: Lite

@Lightz2002

Copy link
Copy Markdown
Author

Hi @wernrab i have made adjustments again, please kindly help check and review again, Thanks for your input !

@wernrab
wernrab self-requested a review October 1, 2026 09:41
@Lightz2002

Copy link
Copy Markdown
Author

@wernrab i have made some adjustments again.

@wernrab
wernrab self-requested a review October 5, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown

ryan added 5 commits October 6, 2026 14:39
The launcher starts shortcut intents from another UID, so the
non-exported FileDisplayActivity was rejected with a SecurityException.
A dedicated exported trampoline validates the shortcut action and
forwards only the shortcut extras to the real activity.
The shortcut carried only path and space, so after an account switch
the same path resolved against the wrong account (or not at all).
Include the folder owner in the shortcut intent and restart with
that account selected before looking the folder up.
The dialog accepted names up to MAX_FILENAME_LENGTH (223 chars) and
passed them unchanged to setShortLabel/setLongLabel, which Android
caps at 10/25 recommended characters. Validate the name in the dialog
and truncate labels defensively before building the ShortcutInfo.
requestPinShortcut is asynchronous and the success toast fired
unconditionally before the user even confirmed the launcher dialog.
Pass an IntentSender backed by ShortcutPinResultReceiver and report
success only when the launcher actually pinned the shortcut; surface
an error toast when requestPinShortcut returns false.
The action was only wired to the bottom-sheet menu; when chosen from
the long-press selection action mode it fell through
onSingleFileActionChosen and did nothing. Open the dialog via the
child fragment manager and clear the selection like other actions.

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.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Review effort: Lite
Findings: 1 High severity · 2 Medium severity

Open (3)
Resolved since last review (3)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Handle shortcut intents in existing activity instances

opencloudApp/​src/​main/​java/​eu/​opencloud/​android/​ui/​activity/​FileDisplayActivity.kt:258

handleShortcutIntent() is only invoked from onCreate, but the trampoline starts FileDisplayActivity with FLAG_ACTIVITY_CLEAR_TOP. When the app already has a FileDisplayActivity, Android delivers the shortcut intent to that existing instance via onNewIntent; BaseActivity.onNewIntent() does not call this handler, so tapping a pinned shortcut while the app is open is a no-op (and this also prevents the cross-account redirect from being processed). Handle the shortcut intent from onNewIntent as well, including updating the activity's intent/account state before resolving the folder.

Comment on lines +2010 to +2020
if (shortcutRemotePath != null) {
val file = storageManager.getFileByPath(shortcutRemotePath, shortcutSpaceId)
if (file != null) {
shortcutFolderToNavigate = file
} else {
showMessageInSnackbar(
R.id.list_layout,
getString(R.string.add_to_home_screen_shortcut_folder_missing)
)
}
}

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.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
Resolved since last review (2)

Comment on lines +1982 to +1984
private fun handleShortcutIntent() {
val sc = eu.opencloud.android.presentation.files.addtohomescreen.FolderShortcutHelper
if (intent?.action != sc.ACTION_OPEN_SHORTCUT) return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

4 participants