Skip to content

Commit

Permalink
Added Send zip menu
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Nov 28, 2018
1 parent 040cf18 commit 13c4fbf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
50 changes: 48 additions & 2 deletions app/src/main/java/de/k3b/android/ToGoZip/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onPrepareOptionsMenu(Menu menu) {
ZipStorage storage = SettingsImpl.getCurrentZipStorage(this);

updateMenuItem(menu, R.id.cmd_delete, R.string.delete_menu_title, storage.exists());
updateMenuItem(menu, R.id.cmd_view_zip, R.string.view_zip_menu_title, storage.exists());
final boolean zipExists = storage.exists();
updateMenuItem(menu, R.id.cmd_delete, R.string.delete_menu_title, zipExists);
updateMenuItem(menu, R.id.cmd_view_zip, R.string.view_zip_menu_title, zipExists);
updateMenuItem(menu, R.id.cmd_send, R.string.send_zip_menu_title, zipExists);

updateMenuItem(menu, R.id.cmd_filemanager, 0,
FileManagerUtil.hasShowInFilemanager(this, getZipFolder(storage)));

Expand Down Expand Up @@ -380,6 +383,8 @@ private void updateMenuItem(Menu menu, int cmd, int menuTitle, boolean visible)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.cmd_send:
return onCmdSend(item.getTitle());
case R.id.cmd_delete:
return onCmdDeleteQuestion();
case R.id.cmd_view_zip:
Expand Down Expand Up @@ -434,6 +439,47 @@ private boolean tryStartActivity(Intent startIntent, Uri contentUri, String mime
return result;
}

private boolean onCmdSend(CharSequence title) {
ZipStorage storage = SettingsImpl.getCurrentZipStorage(this);
Intent intent = new Intent(Intent.ACTION_SEND);
Uri contentUri = Uri.parse(storage.getFullZipUriOrNull());
String mime = "application/zip";

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);


// EXTRA_CC, EXTRA_BCC
// intent.putExtra(Intent.EXTRA_EMAIL, new String[]{toAddress});

intent.putExtra(Intent.EXTRA_SUBJECT, SettingsImpl.getZipFile());

// intent.putExtra(Intent.EXTRA_TEXT, body);

intent.putExtra(Intent.EXTRA_STREAM, contentUri);

intent.setType(mime);

final String debugMessage = "SettingsActivity.onCmdSend(" +
title +
", startActivity='" + intent.toUri(0)
+ "')";
try {
final Intent chooser = Intent.createChooser(intent, title);
chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
this.startActivity(chooser);
if (Global.debugEnabled) {
Log.d(Global.LOG_CONTEXT, debugMessage);
}
}
catch(Exception ex) {
Log.w(Global.LOG_CONTEXT, debugMessage, ex);
}

return true;
}

private boolean onCmdDeleteQuestion() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.delete_menu_title, SettingsImpl.getZipFile()));
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/menu_config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/cmd_send"
android:title="@string/send_zip_menu_title"
android:orderInCategory="5"
android:showAsAction="never"
/>

<item android:id="@+id/cmd_view_zip"
android:title="@string/view_zip_menu_title"
android:orderInCategory="5"
Expand Down
8 changes: 8 additions & 0 deletions libK3b/libK3b.iml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@
<orderEntry type="library" exported="" scope="TEST" name="Gradle: powermock-reflect-1.5.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="Gradle: javassist-3.18.0-GA" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="Gradle: objenesis-1.2" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
<orderEntry type="library" exported="" name="libK3b.libK3b-L2.0.15" level="project" />
</component>
</module>

0 comments on commit 13c4fbf

Please sign in to comment.