mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 07:36:31 +02:00
Added send raw dialog
This commit is contained in:
@@ -1401,11 +1401,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
properties.setValue("raw_save", message.id, false);
|
||||
onMenuRawSave(message);
|
||||
}
|
||||
|
||||
if (properties.getValue("raw_send", message.id)) {
|
||||
properties.setValue("raw_send", message.id, false);
|
||||
onMenuRawSend(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearExpanded(TupleMessageEx message) {
|
||||
@@ -4561,7 +4556,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
popupMenu.getMenu().findItem(R.id.menu_share_as_html).setVisible(message.content && BuildConfig.DEBUG);
|
||||
|
||||
popupMenu.getMenu().findItem(R.id.menu_raw_save).setEnabled(message.uid != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_raw_send).setEnabled(message.uid != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_raw_send_message).setEnabled(message.uid != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_raw_send_thread).setEnabled(message.uid != null);
|
||||
|
||||
popupMenu.getMenu().findItem(R.id.menu_raw_save).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
|
||||
popupMenu.getMenu().findItem(R.id.menu_raw_send).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
|
||||
@@ -4646,8 +4642,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
} else if (itemId == R.id.menu_raw_save) {
|
||||
onMenuRawSave(message);
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_raw_send) {
|
||||
onMenuRawSend(message);
|
||||
} else if (itemId == R.id.menu_raw_send_message) {
|
||||
onMenuRawSend(message, false);
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_raw_send_thread) {
|
||||
onMenuRawSend(message, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -5302,26 +5301,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
private void onMenuRawSend(TupleMessageEx message) {
|
||||
if (message.raw == null || !message.raw) {
|
||||
properties.setValue("raw_send", message.id, true);
|
||||
rawDownload(message);
|
||||
} else
|
||||
try {
|
||||
File file = message.getRawFile(context);
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
private void onMenuRawSend(TupleMessageEx message, boolean threads) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLongArray("ids", new long[]{message.id});
|
||||
args.putBoolean("threads", threads);
|
||||
|
||||
Intent send = new Intent(Intent.ACTION_SEND);
|
||||
//send.setPackage(BuildConfig.APPLICATION_ID);
|
||||
send.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
send.setType("message/rfc822");
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
context.startActivity(send);
|
||||
} catch (Throwable ex) {
|
||||
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||
}
|
||||
FragmentDialogForwardRaw ask = new FragmentDialogForwardRaw();
|
||||
ask.setArguments(args);
|
||||
ask.show(parentFragment.getParentFragmentManager(), "message:raw");
|
||||
}
|
||||
|
||||
private void rawDownload(TupleMessageEx message) {
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FragmentDialogForwardRaw extends FragmentDialogBase {
|
||||
private boolean enabled;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null)
|
||||
enabled = savedInstanceState.getBoolean("fair:enabled");
|
||||
|
||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_forward_raw, null);
|
||||
TextView tvRemaining = dview.findViewById(R.id.tvRemaining);
|
||||
TextView tvOption = dview.findViewById(R.id.tvOption);
|
||||
|
||||
tvRemaining.setText(getString(R.string.title_eml_downloaded, "-"));
|
||||
|
||||
tvOption.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(
|
||||
new Intent(getContext(), ActivitySetup.class)
|
||||
.putExtra("tab", "connection"));
|
||||
}
|
||||
});
|
||||
|
||||
NumberFormat NF = NumberFormat.getNumberInstance();
|
||||
|
||||
new SimpleTask<long[]>() {
|
||||
@Override
|
||||
protected long[] onExecute(Context context, Bundle args) {
|
||||
long[] ids = args.getLongArray("ids");
|
||||
boolean threads = args.getBoolean("threads");
|
||||
|
||||
List<Long> result = new ArrayList<>();
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
List<String> msgids = new ArrayList<>();
|
||||
|
||||
for (long id : ids) {
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message == null)
|
||||
continue;
|
||||
|
||||
List<EntityMessage> messages = db.message().getMessagesByThread(
|
||||
message.account, message.thread, threads ? null : id, null);
|
||||
if (messages == null)
|
||||
continue;
|
||||
|
||||
for (EntityMessage thread : messages) {
|
||||
if (msgids.contains(thread.msgid))
|
||||
continue;
|
||||
msgids.add(thread.msgid);
|
||||
|
||||
result.add(thread.id);
|
||||
|
||||
if (thread.raw == null || !thread.raw)
|
||||
EntityOperation.queue(context, thread, EntityOperation.RAW);
|
||||
}
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return Helper.toLongArray(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, long[] ids) {
|
||||
DB db = DB.getInstance(getContext());
|
||||
LiveData<Integer> ld = db.message().liveRaw(ids);
|
||||
ld.observe(getViewLifecycleOwner(), new Observer<Integer>() {
|
||||
@Override
|
||||
public void onChanged(Integer remaining) {
|
||||
if (remaining == null)
|
||||
return;
|
||||
|
||||
String of = getString(R.string.title_of,
|
||||
NF.format(ids.length - remaining),
|
||||
NF.format(ids.length));
|
||||
tvRemaining.setText(getString(R.string.title_eml_downloaded, of));
|
||||
|
||||
if (remaining == 0) {
|
||||
ld.removeObserver(this);
|
||||
getArguments().putLongArray("ids", ids);
|
||||
enabled = true;
|
||||
setButtonEnabled(enabled);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, getArguments(), "messages:forward");
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(dview)
|
||||
.setPositiveButton(R.string.title_send, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
send(getArguments().getLongArray("ids"));
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
setButtonEnabled(enabled);
|
||||
}
|
||||
|
||||
void setButtonEnabled(boolean enabled) {
|
||||
((AlertDialog) getDialog())
|
||||
.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putBoolean("fair:enabled", enabled);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void send(long[] ids) {
|
||||
try {
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
for (long id : ids) {
|
||||
File file = EntityMessage.getRawFile(getContext(), id);
|
||||
Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, file);
|
||||
uris.add(uri);
|
||||
}
|
||||
|
||||
Intent send = new Intent(Intent.ACTION_SEND_MULTIPLE);
|
||||
send.setPackage(BuildConfig.APPLICATION_ID);
|
||||
send.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
|
||||
send.setType("message/rfc822");
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
startActivity(send);
|
||||
} catch (Throwable ex) {
|
||||
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.core.view.MenuItemCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -130,7 +129,6 @@ import androidx.fragment.app.FragmentResultListener;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
@@ -379,8 +377,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
private static final int REQUEST_BOUNDARY_RETRY = 22;
|
||||
static final int REQUEST_PICK_CONTACT = 23;
|
||||
static final int REQUEST_BUTTONS = 24;
|
||||
private static final int REQUEST_ASKED_RAW = 25;
|
||||
private static final int REQUEST_ALL_READ = 26;
|
||||
private static final int REQUEST_ALL_READ = 25;
|
||||
|
||||
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
|
||||
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
|
||||
@@ -3573,106 +3570,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
}
|
||||
|
||||
private void onActionRaw() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean raw_asked = prefs.getBoolean("raw_asked", false);
|
||||
|
||||
if (raw_asked) {
|
||||
_onActionRaw();
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString("question", getString(R.string.title_raw_send));
|
||||
args.putString("remark", getString(R.string.title_ask_raw));
|
||||
args.putString("notagain", "raw_asked");
|
||||
|
||||
FragmentDialogAsk ask = new FragmentDialogAsk();
|
||||
ask.setArguments(args);
|
||||
ask.setTargetFragment(FragmentMessages.this, REQUEST_ASKED_RAW);
|
||||
ask.show(getParentFragmentManager(), "messages:raw");
|
||||
}
|
||||
|
||||
private void _onActionRaw() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLongArray("ids", getSelection());
|
||||
args.putBoolean("threads", false);
|
||||
|
||||
selectionTracker.clearSelection();
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
private Toast toast = null;
|
||||
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long[] ids = args.getLongArray("ids");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
for (long id : ids) {
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message == null)
|
||||
continue;
|
||||
|
||||
if (message.raw == null || !message.raw)
|
||||
EntityOperation.queue(context, message, EntityOperation.RAW);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
long[] ids = args.getLongArray("ids");
|
||||
|
||||
final Context context = getContext();
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
final LiveData<Integer> ld = db.message().liveRaw(ids);
|
||||
ld.observe(getViewLifecycleOwner(), new Observer<Integer>() {
|
||||
private Integer last = null;
|
||||
|
||||
@Override
|
||||
public void onChanged(Integer remaining) {
|
||||
if (remaining == null || remaining == 0) {
|
||||
ld.removeObserver(this);
|
||||
|
||||
try {
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
for (long id : ids) {
|
||||
File file = EntityMessage.getRawFile(context, id);
|
||||
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
|
||||
uris.add(uri);
|
||||
}
|
||||
|
||||
Intent send = new Intent(Intent.ACTION_SEND_MULTIPLE);
|
||||
send.setPackage(BuildConfig.APPLICATION_ID);
|
||||
send.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
|
||||
send.setType("message/rfc822");
|
||||
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
context.startActivity(send);
|
||||
} catch (Throwable ex) {
|
||||
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
} else {
|
||||
if (!Objects.equals(last, remaining)) {
|
||||
last = remaining;
|
||||
|
||||
String msg = getString(R.string.title_raw_remaining, remaining);
|
||||
if (toast != null)
|
||||
toast.cancel();
|
||||
toast = ToastEx.makeText(context, msg, Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "messages:forward");
|
||||
FragmentDialogForwardRaw ask = new FragmentDialogForwardRaw();
|
||||
ask.setArguments(args);
|
||||
ask.show(getParentFragmentManager(), "messages:raw");
|
||||
}
|
||||
|
||||
private void onActionMoveSelectionAccount(long account, boolean copy, List<Long> disabled) {
|
||||
@@ -6566,10 +6472,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
case REQUEST_BUTTONS:
|
||||
adapter.notifyDataSetChanged();
|
||||
break;
|
||||
case REQUEST_ASKED_RAW:
|
||||
if (resultCode == RESULT_OK)
|
||||
_onActionRaw();
|
||||
break;
|
||||
case REQUEST_ALL_READ:
|
||||
if (resultCode == RESULT_OK)
|
||||
markAllRead();
|
||||
|
||||
Reference in New Issue
Block a user