Skip to content

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

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

Lightz2002 wants to merge 5 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.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createPinnedShortcutApi26(context, folder, shortcutName)
} else {
Toast.makeText(context, context.getString(R.string.add_to_home_screen_shortcut_added), Toast.LENGTH_SHORT).show()
if (file != null) {
shortcutFolderToNavigate = file
} else {
showMessageInSnackbar(R.id.list_layout, getString(R.string.default_error_msg))
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 wernrab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did a quick smoke test on the emulator. In your description you mentioned "Long-press/overflow menu on a folder". I found the "Add to Home screen" action in the thee-dots menu of folders.

When I delete or rename the folder after creating the shortcut, tapping the shortcut makes the app run into a NullPointerException as soon as it attempts to show an error message. After recreating the folder, the shortcut works again.

Copilot gave me a hint: The root cause for the NPE seems to be a wrong call order within FileDisplayActivity.onCreate(). The new handleShortcutIntent() is called before setContentView(view). I did a quick test: calling it afterwards showed the error message as intended. Please check this further.

@wernrab

wernrab commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

@copilot Please check the correct call order of functions within FileDisplayActivity.onCreate(), especially handleShortcutIntent() and setContentView()

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

Comment on lines +35 to +37
if (shortcutManager?.isRequestPinShortcutSupported != true) {
Toast.makeText(context, context.getString(R.string.add_to_home_screen_shortcut_added), Toast.LENGTH_SHORT).show()
return
Comment on lines +42 to +46
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)
Comment on lines +57 to +58
shortcutManager.requestPinShortcut(shortcut, null)
Toast.makeText(context, context.getString(R.string.add_to_home_screen_shortcut_added), Toast.LENGTH_SHORT).show()
Comment on lines +744 to +748
FileMenuOption.ADD_TO_HOME_SCREEN -> {
if (file.isFolder) {
val dialog = AddToHomeScreenDialogFragment.newInstance(file)
dialog.show(childFragmentManager, DIALOG_ADD_TO_HOME_SCREEN)
}
@Lightz2002

Copy link
Copy Markdown
Author

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

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.

4 participants