Feat: "Add to Home screen" option to create folder shortcuts with deep link - #219
Lightz2002 wants to merge 9 commits into
Conversation
|
@wernrab can you review this one? @Lightz2002 I think "add folder path to home screen" is a not so good commit message. |
There was a problem hiding this comment.
🟡 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_SCREENand wires it into the file actions menu (icon + string resources). - Adds
AddToHomeScreenDialogFragmentto collect/validate the shortcut name andFolderShortcutHelperto request a pinned shortcut viaShortcutManager. - Extends
FileDisplayActivityto 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>
|
Hi @guruz , Please kindly inform me if there are changes i need to make since the pr is failing, thanks |
|
Hey @Lightz2002 ! You can run detekt also on your local machine with ./gradlew build, it should run detekt for you. @wernrab We should really change this maximum function length from 100 to 200 or whatever :( |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
🟡 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 duringShortcutInfovalidation 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
onCreatebeforesetContentViewinitializes the activity layout. ConsequentlyfindViewById(R.id.list_layout)is null andSnackbar.makecan 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
| val shortcutIntent = Intent(context, FileDisplayActivity::class.java).apply { | ||
| action = ACTION_OPEN_SHORTCUT | ||
| putExtra(EXTRA_SHORTCUT_FOLDER_REMOTE_ID, folder.remoteId) | ||
| putExtra(EXTRA_SHORTCUT_FOLDER_REMOTE_PATH, folder.remotePath) | ||
| putExtra(EXTRA_SHORTCUT_FOLDER_SPACE_ID, folder.spaceId) |
| shortcutManager.requestPinShortcut(shortcut, null) | ||
| Toast.makeText(context, context.getString(R.string.add_to_home_screen_shortcut_added), Toast.LENGTH_SHORT).show() |
There was a problem hiding this comment.
I could reproduce what Copilot has described above: The success message appears while the user is prompted to confirm the action. They can even cancel the action afterwards.
| FileMenuOption.ADD_TO_HOME_SCREEN -> { | ||
| if (file.isFolder) { | ||
| val dialog = AddToHomeScreenDialogFragment.newInstance(file) | ||
| dialog.show(childFragmentManager, DIALOG_ADD_TO_HOME_SCREEN) | ||
| } |
|
Hi @wernrab i have made adjustments again, please kindly help check and review again, Thanks for your input ! |
|
@wernrab i have made some adjustments again. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One or more issues must be addressed before approval.
Review effort: Lite
Findings: 1
Open (5)
Shortcut target activity is not exported · New Shortcut labels exceed Android's length limits · New This handles only the bottom-sheet path. The sameaction_add_to_homeitem is inflated into the…requestPinShortcutis asynchronous, and passing a null result callback means this code cannot… This shortcut intent carries only path and space, whileFileDisplayActivityresolves it through…
Resolved since last review (3)
| val shortcut = ShortcutInfo.Builder(context, shortcutId) | ||
| .setShortLabel(shortcutName) | ||
| .setLongLabel(shortcutName) | ||
| .setIcon(Icon.createWithResource(context, R.mipmap.icon)) | ||
| .setIntent(shortcutIntent) |
| val shortcut = ShortcutInfo.Builder(context, shortcutId) | ||
| .setShortLabel(shortcutName) | ||
| .setLongLabel(shortcutName) | ||
| .setIcon(Icon.createWithResource(context, R.mipmap.icon)) | ||
| .setIntent(shortcutIntent) |


deep-linking straight into that folder when tapped.
Changes
ADD_TO_HOME_SCREENtoFileMenuOptionand wire it into the file actions menu(
action_add_to_home) with a new icon; only shown for single-selected folders viaFilterFileMenuOptionsUseCaseAddToHomeScreenDialogFragment: pre-filled, editable shortcut name with validation(empty name, max filename length, forbidden characters)
FolderShortcutHelper: creates a pinned shortcut viaShortcutManager(API 26+),embedding the folder's remote ID, remote path, and space ID in the intent
FileDisplayActivityhandles the newOPEN_SHORTCUTaction: resolves the folder byremote 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
Testing