Skip to content

Commit

Permalink
Share (multiple) files from file browser, closes gsantner#590 (PR gsa…
Browse files Browse the repository at this point in the history
…ntner#662 by @kylehelps757)
  • Loading branch information
kylephelps757 authored and gsantner committed Aug 26, 2019
1 parent 128d49d commit b0c0408
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ Where:
* **[Mark Goldman](https://github.com/goldmanm)**<br/>~° Added sorting for todo.txt, improved wiki
* **[natanelho]([email protected])**<br/>~° Hebrew translation
* **[Alexander Sachse]([email protected])**<br/>~° Added simple word counter
* **[Kyle Phelps]([email protected])**<br/>~° Added functionality to chare multiple files from file browser
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -566,6 +572,14 @@ public void onFsViewerConfig(FilesystemViewerData.Options opt) {
}, getActivity().getSupportFragmentManager(), getActivity());
}

private void askForEmail() {
final ArrayList<File> 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
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/net/gsantner/opoc/util/ShareUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ public boolean shareStream(File file, String mimeType) {
}
}

public boolean shareMultipleStreams(List<File> files, String mimeType) {
ArrayList<Uri> 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
*/
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/filesystem__menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
android:visible="false"
app:showAsAction="never" />

<item
android:id="@+id/action_email_selected_items"
android:icon="@drawable/gs_email_sign_black_24dp"
android:title="@string/email"
android:visible="false"
app:showAsAction="never" />


<item
android:id="@+id/action_go_to"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="create_folder">Create Folder</string>
<string name="create_new_document">Create new document</string>
<string name="move">Move</string>
<string name="email">Email</string>
<string name="info">Info</string>
<string name="file_folder_already_exists_please_use_a_different_name">File/folder already exists! Please use a different name</string>

Expand Down

0 comments on commit b0c0408

Please sign in to comment.