Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[file_selector] Add Android support #6468

Closed
wants to merge 2 commits into from

Conversation

gantelo
Copy link

@gantelo gantelo commented Sep 22, 2022

This PR adds a stub with the Android implementation for the file_selector package.

Issue related: [file_selector] Add Android support #110098

We worked on the structure of the Android native code (using Java) and the Dart code to link the work to this native part.

We based our structure on the other available packages to avoid having too many discrepancies between them.

For the dart code, we extend the FileSelectorPlatform and override the main four methods:

  • openFile
  • openFiles
  • getDirectoryPath
  • getSavePath

Current implemented methods:

  • openFile
  • openFiles
  • getDirectoryPath
  • getSavePath

Each of these invokes the MethodChannel('plugins.flutter.io/file_selector_android') that is our native code.

Our native code has two main points:

  • FileSelectorPlugin: this class has the LifeCycleObserver and ActivityState classes to manage the plugin's activity and the result wrappers to respond on the platform thread.
  • FileSelectorDelegate: is the heavy lifting for the plugin.

Right now, we have implemented the overriding of onMethodCall, having the following:

    switch (call.method) {
      case METHOD_GET_DIRECTORY_PATH:
        delegate.getDirectoryPath(call, result);
        break;
      case METHOD_GET_SAVE_PATH:
        throw new UnsupportedOperationException("getSavePath is not supported yet");
      case METHOD_OPEN_FILE:
        throw new UnsupportedOperationException("openFile is not supported yet");
      default:
        throw new IllegalArgumentException("Unknown method " + call.method);
    }

We already have a naive implementation of the getDirectoryPath, which is to be perfectioned upon feedback from our structure base.

As for the tests, we only added a simple test for the dart implementation of getDirectoryPath, and the next steps are to add the Java tests for our code.

getDirectoryPath
getDirectoryPath naive functionality

Please, any early feedback will be more than welcome to avoid rework in the future.

Edit:
We finished the getDirectoryPath implementation and added proper tests in native and dart code.

We split the native implementation in a file for each class to avoid being too cumbersome with the activity helpers and wrappers.
We also made some minor refactors when starting to test the native code because we found (even if small) some better dependency injection management for our code.

Lastly, as a note, we couldn't set the Confirm Button Text property because of an inability, at least in the action, for setting other parameters than the extra initial uri. This means that, in Android, we'll have to stick with the button text being "USE THIS FOLDER" for now.

As ACTION_OPEN_DOCUMENT_TREE is SDK 21+ this is our current support. We'll add support for 19+ once we have feedback and well defined structure of the remaining items.

Note: we may need an override: no versioning needed since this is not the final version of the package, and it won't be yet deployed unless you say so.

Note 2: we'll have to update the documentation to add the proper support for Android once we decide we can ship this.

By the way, @stuartmorgan, I didn't get the coverage check for this PR. Do we have to push the .lcov file? In this issue, it says we should upload it to the flutter/flutter repo, and I don't see any of these in the /plugins repo. Could you advise us on how to proceed there? Thanks.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@gantelo
Copy link
Author

gantelo commented Sep 23, 2022

Hi @stuartmorgan @timsneath,

Following our emails from yesterday, this is the first approach for an Android implementation.

I'm still working on the details for the getDirectoryPath, but it's naively functional for now.

Edited the initial PR description with updates.

@gantelo gantelo force-pushed the android-package branch 5 times, most recently from 3ab34bf to 3ae7a03 Compare September 23, 2022 20:35
@gantelo gantelo marked this pull request as ready for review September 23, 2022 21:02
@gantelo gantelo marked this pull request as draft September 28, 2022 20:08
@gantelo gantelo force-pushed the android-package branch 2 times, most recently from eea9053 to e1a3a58 Compare September 30, 2022 17:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants