Allow editing trashed messages

Fixes #21
pull/30/head
M66B 6 years ago
parent 971781b416
commit 1572111935

@ -174,11 +174,14 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_thread:
onActionThread(id);
return true;
case R.id.action_seen: case R.id.action_seen:
onActionSeen(id); onActionSeen(id);
return true; return true;
case R.id.action_thread: case R.id.action_edit:
onActionThread(id); onActionEdit(id);
return true; return true;
case R.id.action_forward: case R.id.action_forward:
onActionForward(id); onActionForward(id);
@ -218,6 +221,7 @@ public class FragmentMessage extends FragmentEx {
// Initialize // Initialize
grpAddress.setVisibility(View.GONE); grpAddress.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE); grpAttachments.setVisibility(View.GONE);
top_navigation.setVisibility(View.GONE);
bottom_navigation.setVisibility(View.GONE); bottom_navigation.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
@ -251,10 +255,6 @@ public class FragmentMessage extends FragmentEx {
if (FragmentMessage.this.isVisible()) if (FragmentMessage.this.isVisible())
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
} else { } 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)); setSubtitle(Helper.localizeFolderName(getContext(), message.folderName));
tvFrom.setText(message.from == null ? null : TextUtils.join(", ", message.from)); 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); MenuItem actionSeen = top_navigation.getMenu().findItem(R.id.action_seen);
actionSeen.setIcon(message.ui_seen actionSeen.setIcon(message.ui_seen
? R.drawable.baseline_visibility_off_24 ? R.drawable.baseline_visibility_off_24
@ -308,6 +303,11 @@ public class FragmentMessage extends FragmentEx {
db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() { db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
@Override @Override
public void onChanged(@Nullable final List<TupleFolderEx> folders) { public void onChanged(@Nullable final List<TupleFolderEx> 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 hasTrash = false;
boolean hasJunk = false; boolean hasJunk = false;
boolean hasArchive = false; boolean hasArchive = false;
@ -323,6 +323,13 @@ public class FragmentMessage extends FragmentEx {
hasUser = true; 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_trash).setVisible(!outbox && hasTrash);
bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && hasJunk); bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && hasJunk);
bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser)); 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); 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) { private void onActionSeen(final long id) {
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
@ -379,16 +398,30 @@ public class FragmentMessage extends FragmentEx {
}); });
} }
private void onActionThread(long id) { private void onActionEdit(final long id) {
Bundle args = new Bundle(); executor.submit(new Runnable() {
args.putLong("thread", id); // message ID @Override
public void run() {
FragmentMessages fragment = new FragmentMessages(); try {
fragment.setArguments(args); DB db = DB.getInstance(getContext());
EntityMessage draft = db.message().getMessage(id);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); EntityFolder drafts = db.folder().getFolderByType(draft.account, EntityFolder.TYPE_DRAFTS);
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("thread"); if (drafts == null)
fragmentTransaction.commit(); 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) { private void onActionForward(long id) {

@ -238,5 +238,5 @@
android:id="@+id/grpReady" android:id="@+id/grpReady"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="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" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -14,6 +14,12 @@
android:title="@string/title_seen" android:title="@string/title_seen"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/action_edit"
android:icon="@drawable/baseline_edit_24"
android:title="@string/title_edit"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_forward" android:id="@+id/action_forward"
android:icon="@drawable/baseline_forward_24" android:icon="@drawable/baseline_forward_24"

@ -108,6 +108,7 @@
<string name="title_thread">Thread</string> <string name="title_thread">Thread</string>
<string name="title_seen">Read</string> <string name="title_seen">Read</string>
<string name="title_unseen">Unread</string> <string name="title_unseen">Unread</string>
<string name="title_edit">Edit</string>
<string name="title_forward">Forward</string> <string name="title_forward">Forward</string>
<string name="title_reply_all">Reply to all</string> <string name="title_reply_all">Reply to all</string>

Loading…
Cancel
Save