From b0c04087b5228a524c53a5e01d5fafdaaf5f1ecb Mon Sep 17 00:00:00 2001 From: Kyle-Phelps <54076255+kylephelps757@users.noreply.github.com> Date: Mon, 26 Aug 2019 15:15:22 -0400 Subject: [PATCH] Share (multiple) files from file browser, closes #590 (PR #662 by @kylehelps757) --- CONTRIBUTORS.md | 1 + .../opoc/ui/FilesystemViewerFragment.java | 14 ++++++++++++++ .../net/gsantner/opoc/util/ShareUtil.java | 19 +++++++++++++++++++ app/src/main/res/menu/filesystem__menu.xml | 7 +++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 42 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 47a9d296f2..02306fffc3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -38,3 +38,4 @@ Where: * **[Mark Goldman](https://github.com/goldmanm)**
~° Added sorting for todo.txt, improved wiki * **[natanelho](natanelho@gmail.com)**
~° Hebrew translation * **[Alexander Sachse](alexander.sachse@gmail.com)**
~° Added simple word counter +* **[Kyle Phelps](kyle.phelps757@gmail.com)**
~° Added functionality to chare multiple files from file browser diff --git a/app/src/main/java/net/gsantner/opoc/ui/FilesystemViewerFragment.java b/app/src/main/java/net/gsantner/opoc/ui/FilesystemViewerFragment.java index 6c875b203c..f7433b8c23 100644 --- a/app/src/main/java/net/gsantner/opoc/ui/FilesystemViewerFragment.java +++ b/app/src/main/java/net/gsantner/opoc/ui/FilesystemViewerFragment.java @@ -238,6 +238,7 @@ private void updateMenuItems() { _fragmentMenu.findItem(R.id.action_rename_selected_item).setVisible(multi1); _fragmentMenu.findItem(R.id.action_info_selected_item).setVisible(multi1); _fragmentMenu.findItem(R.id.action_move_selected_items).setVisible((multi1 || multiMore) && !_shareUtil.isUnderStorageAccessFolder(getCurrentFolder())); + _fragmentMenu.findItem(R.id.action_email_selected_items).setVisible((multi1 || multiMore) && !_shareUtil.isUnderStorageAccessFolder(getCurrentFolder())); _fragmentMenu.findItem(R.id.action_go_to).setVisible(!_filesystemViewerAdapter.areItemsSelected()); _fragmentMenu.findItem(R.id.action_sort).setVisible(!_filesystemViewerAdapter.areItemsSelected()); _fragmentMenu.findItem(R.id.action_import).setVisible(!_filesystemViewerAdapter.areItemsSelected()); @@ -449,6 +450,11 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + case R.id.action_email_selected_items: { + askForEmail(); + return true; + } + case R.id.action_info_selected_item: { if (_filesystemViewerAdapter.areItemsSelected()) { File file = new ArrayList<>(_filesystemViewerAdapter.getCurrentSelection()).get(0); @@ -566,6 +572,14 @@ public void onFsViewerConfig(FilesystemViewerData.Options opt) { }, getActivity().getSupportFragmentManager(), getActivity()); } + private void askForEmail() { + final ArrayList filesToMove = new ArrayList<>(_filesystemViewerAdapter.getCurrentSelection()); + ShareUtil s = new ShareUtil(getContext()); + s.shareMultipleStreams(filesToMove, "text/plain"); + _filesystemViewerAdapter.unselectAll(); + _filesystemViewerAdapter.reloadCurrentFolder(); + } + private void showImportDialog() { FilesystemViewerFactory.showFileDialog(new FilesystemViewerData.SelectionListenerAdapter() { @Override diff --git a/app/src/main/java/net/gsantner/opoc/util/ShareUtil.java b/app/src/main/java/net/gsantner/opoc/util/ShareUtil.java index 756000d3f3..a4d51a50a0 100644 --- a/app/src/main/java/net/gsantner/opoc/util/ShareUtil.java +++ b/app/src/main/java/net/gsantner/opoc/util/ShareUtil.java @@ -230,6 +230,25 @@ public boolean shareStream(File file, String mimeType) { } } + public boolean shareMultipleStreams(List files, String mimeType) { + ArrayList uris = new ArrayList<>(); + Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); + intent.setType(mimeType); + for (File file : files) { + File uri = new File(file.toString()); + Uri uriFile = FileProvider.getUriForFile(_context, getFileProviderAuthority(), file); + uris.add(uriFile); + } + + try { + intent.putParcelableArrayListExtra(intent.EXTRA_STREAM, uris); + showChooser(intent, null); + return true; + } catch (Exception e) { // FileUriExposed(API24) / IllegalArgument + return false; + } + } + /** * Start calendar application to add new event, with given details prefilled */ diff --git a/app/src/main/res/menu/filesystem__menu.xml b/app/src/main/res/menu/filesystem__menu.xml index 9b80b73f0b..e4cddec8d7 100644 --- a/app/src/main/res/menu/filesystem__menu.xml +++ b/app/src/main/res/menu/filesystem__menu.xml @@ -56,6 +56,13 @@ android:visible="false" app:showAsAction="never" /> + + . Create Folder Create new document Move + Email Info File/folder already exists! Please use a different name