Added send as attachment

pull/162/head
M66B 5 years ago
parent 81f22c6055
commit d9488e12e5

@ -57,9 +57,9 @@ For authorizing:
* ~~Pinch zoom text size~~ * ~~Pinch zoom text size~~
* ~~Display GIFs~~ * ~~Display GIFs~~
* ~~Themes~~ (a grey light and dark theme were added because this is what most people seems to want) * ~~Themes~~ (a grey light and dark theme were added because this is what most people seems to want)
* Send as attachment * ~~Any day time condition~~ (any day doesn't really fit into the from/to date/time condition)
* ~~Send as attachment~~
* Search for settings * Search for settings
* Select any day for time conditions
* Widget for selected account * Widget for selected account
Anything on this list is in random order and *might* be added in the near future. Anything on this list is in random order and *might* be added in the near future.

@ -94,6 +94,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
@ -2393,10 +2394,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers); popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers);
popupMenu.getMenu().findItem(R.id.menu_show_headers).setEnabled(message.uid != null); popupMenu.getMenu().findItem(R.id.menu_show_headers).setEnabled(message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_raw).setEnabled( popupMenu.getMenu().findItem(R.id.menu_raw_download).setEnabled(
message.uid != null && (message.raw == null || message.raw)); message.uid != null && (message.raw == null || !message.raw));
popupMenu.getMenu().findItem(R.id.menu_raw).setTitle( popupMenu.getMenu().findItem(R.id.menu_raw_save).setEnabled(
message.raw == null || !message.raw ? R.string.title_raw_download : R.string.title_raw_save); message.uid != null && (message.raw != null && message.raw));
popupMenu.getMenu().findItem(R.id.menu_raw_send).setEnabled(
message.uid != null && (message.raw != null && message.raw));
popupMenu.getMenu().findItem(R.id.menu_manage_keywords).setEnabled(message.uid != null && !message.folderReadOnly); popupMenu.getMenu().findItem(R.id.menu_manage_keywords).setEnabled(message.uid != null && !message.folderReadOnly);
@ -2449,8 +2452,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_show_headers: case R.id.menu_show_headers:
onMenuShowHeaders(message); onMenuShowHeaders(message);
return true; return true;
case R.id.menu_raw: case R.id.menu_raw_download:
onMenuRaw(message); onMenuRawDownload(message);
return true;
case R.id.menu_raw_save:
onMenuRawSave(message);
return true;
case R.id.menu_raw_send:
onMenuRawSend(message);
return true; return true;
default: default:
return false; return false;
@ -3041,46 +3050,56 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
notifyDataSetChanged(); notifyDataSetChanged();
} }
private void onMenuRaw(TupleMessageEx message) { private void onMenuRawDownload(TupleMessageEx message) {
if (message.raw == null) { Bundle args = new Bundle();
Bundle args = new Bundle(); args.putLong("id", message.id);
args.putLong("id", message.id);
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
Long id = args.getLong("id"); Long id = args.getLong("id");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null) if (message == null)
return null; return null;
EntityOperation.queue(context, message, EntityOperation.RAW); EntityOperation.queue(context, message, EntityOperation.RAW);
db.message().setMessageRaw(message.id, false); db.message().setMessageRaw(message.id, false);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
}
return null;
} }
return null;
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(parentFragment.getFragmentManager(), ex); Helper.unexpectedError(parentFragment.getFragmentManager(), ex);
} }
}.execute(context, owner, args, "message:raw"); }.execute(context, owner, args, "message:raw");
} else { }
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( private void onMenuRawSave(TupleMessageEx message) {
new Intent(FragmentMessages.ACTION_STORE_RAW) LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
.putExtra("id", message.id)); lbm.sendBroadcast(
} new Intent(FragmentMessages.ACTION_STORE_RAW)
.putExtra("id", message.id));
}
private void onMenuRawSend(TupleMessageEx message) {
File file = message.getRawFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
Intent send = new Intent(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_STREAM, uri);
send.setType("message/rfc822");
context.startActivity(send);
} }
ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) { ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) {

@ -54,6 +54,16 @@
android:title="@string/title_show_headers" /> android:title="@string/title_show_headers" />
<item <item
android:id="@+id/menu_raw" android:id="@+id/menu_raw_download"
android:title="@string/title_raw_download" /> android:title="@string/title_raw_download" />
<item
android:id="@+id/menu_raw_save"
android:enabled="false"
android:title="@string/title_raw_save" />
<item
android:id="@+id/menu_raw_send"
android:enabled="false"
android:title="@string/title_raw_send" />
</menu> </menu>

@ -478,6 +478,7 @@
<string name="title_show_headers">Show headers</string> <string name="title_show_headers">Show headers</string>
<string name="title_raw_download">Download raw message</string> <string name="title_raw_download">Download raw message</string>
<string name="title_raw_save">Save raw message</string> <string name="title_raw_save">Save raw message</string>
<string name="title_raw_send">Send as attachment</string>
<string name="title_manage_keywords">Manage keywords</string> <string name="title_manage_keywords">Manage keywords</string>
<string name="title_add_keyword">Add keyword</string> <string name="title_add_keyword">Add keyword</string>
<string name="title_show_inline">Show inline attachments</string> <string name="title_show_inline">Show inline attachments</string>

Loading…
Cancel
Save