|
|
|
@ -138,6 +138,12 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null)
|
|
|
|
|
message = (TupleMessageEx) getArguments().getSerializable("message");
|
|
|
|
|
else
|
|
|
|
|
message = (TupleMessageEx) savedInstanceState.getSerializable("message");
|
|
|
|
|
|
|
|
|
|
openPgpConnection = new OpenPgpServiceConnection(getContext(), "org.sufficientlysecure.keychain");
|
|
|
|
|
openPgpConnection.bindToService();
|
|
|
|
|
}
|
|
|
|
@ -156,10 +162,6 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
view = (ViewGroup) inflater.inflate(R.layout.fragment_message, container, false);
|
|
|
|
|
|
|
|
|
|
// Get arguments
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
|
final long id = (args == null ? -1 : args.getLong("id"));
|
|
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
debug = prefs.getBoolean("debug", false);
|
|
|
|
|
|
|
|
|
@ -193,7 +195,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
tvCount.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
onMenuThread(message.id);
|
|
|
|
|
onMenuThread();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -301,19 +303,19 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.action_spam:
|
|
|
|
|
onActionSpam(id);
|
|
|
|
|
onActionSpam();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.action_trash:
|
|
|
|
|
onActionDelete(id);
|
|
|
|
|
onActionDelete();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.action_move:
|
|
|
|
|
onActionMove(id);
|
|
|
|
|
onActionMove();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.action_archive:
|
|
|
|
|
onActionArchive(id);
|
|
|
|
|
onActionArchive();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.action_reply:
|
|
|
|
|
onActionReply(id);
|
|
|
|
|
onActionReply();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
@ -348,6 +350,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
outState.putSerializable("message", message);
|
|
|
|
|
outState.putBoolean("free", free);
|
|
|
|
|
if (free) {
|
|
|
|
|
outState.putInt("tag_count", (int) tvCount.getTag());
|
|
|
|
@ -361,31 +364,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
|
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
// Get arguments
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
|
final long id = (args == null ? -1 : args.getLong("id"));
|
|
|
|
|
|
|
|
|
|
final DB db = DB.getInstance(getContext());
|
|
|
|
|
|
|
|
|
|
// Observe message
|
|
|
|
|
db.message().liveMessage(id).observe(getViewLifecycleOwner(), new Observer<TupleMessageEx>() {
|
|
|
|
|
private boolean once = false;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onChanged(@Nullable final TupleMessageEx message) {
|
|
|
|
|
if (message == null || (!(debug && BuildConfig.DEBUG) && message.ui_hide)) {
|
|
|
|
|
// Message gone (moved, deleted)
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FragmentMessage.this.message = message;
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
|
if (once)
|
|
|
|
|
return;
|
|
|
|
|
once = true;
|
|
|
|
|
|
|
|
|
|
setSubtitle(Helper.localizeFolderName(getContext(), message.folderName));
|
|
|
|
|
|
|
|
|
|
tvFrom.setText(message.from == null ? null : MessageHelper.getFormattedAddresses(message.from, true));
|
|
|
|
@ -400,7 +379,6 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
tvBcc.setText(message.bcc == null ? null : MessageHelper.getFormattedAddresses(message.bcc, true));
|
|
|
|
|
|
|
|
|
|
tvError.setText(message.error);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
free = savedInstanceState.getBoolean("free");
|
|
|
|
|
if (free) {
|
|
|
|
@ -412,8 +390,6 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
decrypted = savedInstanceState.getString("decrypted");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
|
|
|
|
|
|
if (tvBody.getTag() == null) {
|
|
|
|
|
// Spanned text needs to be loaded after recreation too
|
|
|
|
|
final Bundle args = new Bundle();
|
|
|
|
@ -427,7 +403,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
protected Spanned onLoad(final Context context, final Bundle args) throws Throwable {
|
|
|
|
|
final long id = args.getLong("id");
|
|
|
|
|
final boolean show_images = args.getBoolean("show_images");
|
|
|
|
|
String body = (decrypted == null ? EntityMessage.read(context, id) : decrypted);
|
|
|
|
|
String body = (decrypted == null ? message.read(context) : decrypted);
|
|
|
|
|
args.putInt("size", body.length());
|
|
|
|
|
|
|
|
|
|
return Html.fromHtml(HtmlHelper.sanitize(getContext(), body, false), new Html.ImageGetter() {
|
|
|
|
@ -568,9 +544,24 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
grpError.setVisibility(free || message.error == null ? View.GONE : View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(getContext());
|
|
|
|
|
|
|
|
|
|
if (!message.virtual) {
|
|
|
|
|
// Observe message
|
|
|
|
|
db.message().liveMessage(message.id).observe(getViewLifecycleOwner(), new Observer<TupleMessageEx>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onChanged(@Nullable final TupleMessageEx message) {
|
|
|
|
|
if (message == null || (!(debug && BuildConfig.DEBUG) && message.ui_hide)) {
|
|
|
|
|
// Message gone (moved, deleted)
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Observe attachments
|
|
|
|
|
db.attachment().liveAttachments(id).removeObservers(getViewLifecycleOwner());
|
|
|
|
|
db.attachment().liveAttachments(id).observe(getViewLifecycleOwner(),
|
|
|
|
|
db.attachment().liveAttachments(message.id).observe(getViewLifecycleOwner(),
|
|
|
|
|
new Observer<List<EntityAttachment>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onChanged(@Nullable List<EntityAttachment> attachments) {
|
|
|
|
@ -583,7 +574,6 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Observe folders
|
|
|
|
|
db.folder().liveFolders(message.account).removeObservers(getViewLifecycleOwner());
|
|
|
|
|
db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onChanged(@Nullable List<TupleFolderEx> folders) {
|
|
|
|
@ -623,7 +613,6 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -636,23 +625,21 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
public void onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
|
|
|
|
|
|
boolean inOutbox = (message != null && EntityFolder.OUTBOX.equals(message.folderType));
|
|
|
|
|
boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType);
|
|
|
|
|
|
|
|
|
|
menu.findItem(R.id.menu_addresses).setVisible(!free);
|
|
|
|
|
menu.findItem(R.id.menu_thread).setVisible(!free && message != null && message.count > 1);
|
|
|
|
|
menu.findItem(R.id.menu_seen).setVisible(!free && message != null && !inOutbox);
|
|
|
|
|
menu.findItem(R.id.menu_forward).setVisible(!free && message != null && !inOutbox);
|
|
|
|
|
menu.findItem(R.id.menu_reply_all).setVisible(!free && message != null && message.cc != null && !inOutbox);
|
|
|
|
|
menu.findItem(R.id.menu_thread).setVisible(!free && !message.virtual && message.count > 1);
|
|
|
|
|
menu.findItem(R.id.menu_seen).setVisible(!free && !message.virtual && !inOutbox);
|
|
|
|
|
menu.findItem(R.id.menu_forward).setVisible(!free && !message.virtual && !inOutbox);
|
|
|
|
|
menu.findItem(R.id.menu_reply_all).setVisible(!free && !message.virtual && message.cc != null && !inOutbox);
|
|
|
|
|
menu.findItem(R.id.menu_decrypt).setVisible(decrypted == null);
|
|
|
|
|
|
|
|
|
|
if (message != null) {
|
|
|
|
|
MenuItem menuSeen = menu.findItem(R.id.menu_seen);
|
|
|
|
|
menuSeen.setIcon(message.ui_seen
|
|
|
|
|
? R.drawable.baseline_visibility_off_24
|
|
|
|
|
: R.drawable.baseline_visibility_24);
|
|
|
|
|
menuSeen.setTitle(message.ui_seen ? R.string.title_unseen : R.string.title_seen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
@ -661,19 +648,19 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
onMenuAddresses();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.menu_thread:
|
|
|
|
|
onMenuThread(message.id);
|
|
|
|
|
onMenuThread();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.menu_seen:
|
|
|
|
|
onMenuSeen(message.id);
|
|
|
|
|
onMenuSeen();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.menu_forward:
|
|
|
|
|
onMenuForward(message.id);
|
|
|
|
|
onMenuForward();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.menu_reply_all:
|
|
|
|
|
onMenuReplyAll(message.id);
|
|
|
|
|
onMenuReplyAll();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.menu_decrypt:
|
|
|
|
|
onMenuDecrypt(message);
|
|
|
|
|
onMenuDecrypt();
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
@ -684,11 +671,11 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
grpAddresses.setVisibility(grpAddresses.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuThread(long id) {
|
|
|
|
|
private void onMenuThread() {
|
|
|
|
|
getFragmentManager().popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("thread", id); // message ID
|
|
|
|
|
args.putLong("thread", message.id);
|
|
|
|
|
|
|
|
|
|
FragmentMessages fragment = new FragmentMessages();
|
|
|
|
|
fragment.setArguments(args);
|
|
|
|
@ -698,11 +685,11 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuSeen(long id) {
|
|
|
|
|
private void onMenuSeen() {
|
|
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -741,19 +728,19 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
}.load(this, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuForward(long id) {
|
|
|
|
|
private void onMenuForward() {
|
|
|
|
|
startActivity(new Intent(getContext(), ActivityCompose.class)
|
|
|
|
|
.putExtra("action", "forward")
|
|
|
|
|
.putExtra("reference", id));
|
|
|
|
|
.putExtra("reference", message.id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuReplyAll(long id) {
|
|
|
|
|
private void onMenuReplyAll() {
|
|
|
|
|
startActivity(new Intent(getContext(), ActivityCompose.class)
|
|
|
|
|
.putExtra("action", "reply_all")
|
|
|
|
|
.putExtra("reference", id));
|
|
|
|
|
.putExtra("reference", message.id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuDecrypt(EntityMessage message) {
|
|
|
|
|
private void onMenuDecrypt() {
|
|
|
|
|
Log.i(Helper.TAG, "On decrypt");
|
|
|
|
|
try {
|
|
|
|
|
if (!PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("pro", false))
|
|
|
|
@ -826,14 +813,14 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
Log.i(Helper.TAG, "Message onActivityResult request=" + requestCode + " result=" + resultCode + " data=" + data);
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
if (requestCode == ActivityView.REQUEST_OPENPGP && message != null) {
|
|
|
|
|
if (requestCode == ActivityView.REQUEST_OPENPGP) {
|
|
|
|
|
Log.i(Helper.TAG, "User interacted");
|
|
|
|
|
onMenuDecrypt(message);
|
|
|
|
|
onMenuDecrypt();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionSpam(final long id) {
|
|
|
|
|
private void onActionSpam() {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
|
|
|
|
builder
|
|
|
|
|
.setMessage(R.string.title_ask_spam)
|
|
|
|
@ -843,7 +830,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -886,7 +873,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionDelete(final long id) {
|
|
|
|
|
private void onActionDelete() {
|
|
|
|
|
boolean delete = (Boolean) bottom_navigation.getTag();
|
|
|
|
|
if (delete) {
|
|
|
|
|
// No trash or is trash
|
|
|
|
@ -899,7 +886,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -946,7 +933,7 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -986,9 +973,9 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionMove(long id) {
|
|
|
|
|
private void onActionMove() {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<List<EntityFolder>>() {
|
|
|
|
|
@Override
|
|
|
|
@ -1102,11 +1089,11 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
}.load(FragmentMessage.this, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionArchive(long id) {
|
|
|
|
|
private void onActionArchive() {
|
|
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -1147,9 +1134,9 @@ public class FragmentMessage extends FragmentEx {
|
|
|
|
|
}.load(FragmentMessage.this, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionReply(long id) {
|
|
|
|
|
private void onActionReply() {
|
|
|
|
|
startActivity(new Intent(getContext(), ActivityCompose.class)
|
|
|
|
|
.putExtra("action", "reply")
|
|
|
|
|
.putExtra("reference", id));
|
|
|
|
|
.putExtra("reference", message.id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|