diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 47c1dcfe59..102bb9e236 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -174,11 +174,14 @@ public class FragmentMessage extends FragmentEx { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { + case R.id.action_thread: + onActionThread(id); + return true; case R.id.action_seen: onActionSeen(id); return true; - case R.id.action_thread: - onActionThread(id); + case R.id.action_edit: + onActionEdit(id); return true; case R.id.action_forward: onActionForward(id); @@ -218,6 +221,7 @@ public class FragmentMessage extends FragmentEx { // Initialize grpAddress.setVisibility(View.GONE); grpAttachments.setVisibility(View.GONE); + top_navigation.setVisibility(View.GONE); bottom_navigation.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); @@ -251,10 +255,6 @@ public class FragmentMessage extends FragmentEx { if (FragmentMessage.this.isVisible()) getFragmentManager().popBackStack(); } else { - final boolean inbox = EntityFolder.TYPE_INBOX.equals(message.folderType); - final boolean outbox = EntityFolder.TYPE_INBOX.equals(message.folderType); - final boolean archive = EntityFolder.TYPE_ARCHIVE.equals(message.folderType); - setSubtitle(Helper.localizeFolderName(getContext(), message.folderName)); tvFrom.setText(message.from == null ? null : TextUtils.join(", ", message.from)); @@ -287,11 +287,6 @@ public class FragmentMessage extends FragmentEx { } }); - top_navigation.getMenu().findItem(R.id.action_thread).setVisible(message.count > 1); - top_navigation.getMenu().findItem(R.id.action_seen).setVisible(!outbox); - top_navigation.getMenu().findItem(R.id.action_forward).setVisible(!outbox); - top_navigation.getMenu().findItem(R.id.action_reply_all).setVisible(!outbox); - MenuItem actionSeen = top_navigation.getMenu().findItem(R.id.action_seen); actionSeen.setIcon(message.ui_seen ? R.drawable.baseline_visibility_off_24 @@ -308,6 +303,11 @@ public class FragmentMessage extends FragmentEx { db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable final List folders) { + boolean inbox = EntityFolder.TYPE_INBOX.equals(message.folderType); + boolean outbox = EntityFolder.TYPE_OUTBOX.equals(message.folderType); + boolean archive = EntityFolder.TYPE_ARCHIVE.equals(message.folderType); + boolean trash = EntityFolder.TYPE_TRASH.equals(message.folderType); + boolean hasTrash = false; boolean hasJunk = false; boolean hasArchive = false; @@ -323,6 +323,13 @@ public class FragmentMessage extends FragmentEx { hasUser = true; } + top_navigation.getMenu().findItem(R.id.action_thread).setVisible(message.count > 1); + top_navigation.getMenu().findItem(R.id.action_seen).setVisible(!outbox); + top_navigation.getMenu().findItem(R.id.action_edit).setVisible(trash); + top_navigation.getMenu().findItem(R.id.action_forward).setVisible(!outbox); + top_navigation.getMenu().findItem(R.id.action_reply_all).setVisible(!outbox); + top_navigation.setVisibility(View.VISIBLE); + bottom_navigation.getMenu().findItem(R.id.action_trash).setVisible(!outbox && hasTrash); bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && hasJunk); bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser)); @@ -361,6 +368,18 @@ public class FragmentMessage extends FragmentEx { grpAddress.setVisibility(grpAddress.getVisibility() == View.GONE ? View.VISIBLE : View.GONE); } + private void onActionThread(long id) { + Bundle args = new Bundle(); + args.putLong("thread", id); // message ID + + FragmentMessages fragment = new FragmentMessages(); + fragment.setArguments(args); + + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("thread"); + fragmentTransaction.commit(); + } + private void onActionSeen(final long id) { executor.submit(new Runnable() { @Override @@ -379,16 +398,30 @@ public class FragmentMessage extends FragmentEx { }); } - private void onActionThread(long id) { - Bundle args = new Bundle(); - args.putLong("thread", id); // message ID - - FragmentMessages fragment = new FragmentMessages(); - fragment.setArguments(args); - - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("thread"); - fragmentTransaction.commit(); + private void onActionEdit(final long id) { + executor.submit(new Runnable() { + @Override + public void run() { + try { + DB db = DB.getInstance(getContext()); + EntityMessage draft = db.message().getMessage(id); + EntityFolder drafts = db.folder().getFolderByType(draft.account, EntityFolder.TYPE_DRAFTS); + if (drafts == null) + drafts = db.folder().getLocalDrafts(); + if (drafts == null) + return; + draft.id = null; + draft.folder = drafts.id; + draft.id = db.message().insertMessage(draft); + + getContext().startActivity( + new Intent(getContext(), ActivityCompose.class) + .putExtra("id", draft.id)); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } + } + }); } private void onActionForward(long id) { diff --git a/app/src/main/res/layout/fragment_message.xml b/app/src/main/res/layout/fragment_message.xml index 1791d04aa0..cf27e901af 100644 --- a/app/src/main/res/layout/fragment_message.xml +++ b/app/src/main/res/layout/fragment_message.xml @@ -238,5 +238,5 @@ android:id="@+id/grpReady" android:layout_width="0dp" android:layout_height="0dp" - app:constraint_referenced_ids="tvFrom,tvTime,tvSubject,tvCount,top_navigation,scroll" /> + app:constraint_referenced_ids="tvFrom,tvTime,tvSubject,tvCount,scroll" /> diff --git a/app/src/main/res/menu/action_view_top.xml b/app/src/main/res/menu/action_view_top.xml index e322647fe0..78e7d39e2f 100644 --- a/app/src/main/res/menu/action_view_top.xml +++ b/app/src/main/res/menu/action_view_top.xml @@ -14,6 +14,12 @@ android:title="@string/title_seen" app:showAsAction="ifRoom" /> + + Thread Read Unread + Edit Forward Reply to all