Browse Source

Added move sent menu

main
M66B 6 years ago
parent
commit
9d53085249
4 changed files with 63 additions and 0 deletions
  1. +5
    -0
      app/src/main/java/eu/faircode/email/DaoMessage.java
  2. +51
    -0
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  3. +5
    -0
      app/src/main/res/menu/menu_messages.xml
  4. +2
    -0
      app/src/main/res/values/strings.xml

+ 5
- 0
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -152,6 +152,11 @@ public interface DaoMessage {
" AND ui_found = :found")
List<EntityMessage> getMessageByMsgId(long account, String msgid, String reference, boolean found);
@Query("SELECT * FROM message" +
" WHERE folder = :folder" +
" AND ui_seen")
List<EntityMessage> getMessageSeen(long folder);
@Query("SELECT message.*" +
", account.name AS accountName, account.color AS accountColor" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" +


+ 51
- 0
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -86,6 +86,7 @@ public class FragmentMessages extends FragmentEx {
private String search = null;
private long primary = -1;
private boolean outbox = false;
private boolean connected = false;
private AdapterMessage adapter;
private List<Long> archives = new ArrayList<>();
@ -577,6 +578,9 @@ public class FragmentMessages extends FragmentEx {
setSubtitle(getString(R.string.title_folder_unseen, name, folder.unseen));
else
setSubtitle(name);
outbox = EntityFolder.OUTBOX.equals(folder.type);
getActivity().invalidateOptionsMenu();
}
}
});
@ -716,6 +720,7 @@ public class FragmentMessages extends FragmentEx {
menu.findItem(R.id.menu_sort_on).setVisible(TextUtils.isEmpty(search));
menu.findItem(R.id.menu_folders).setVisible(primary >= 0);
menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24);
menu.findItem(R.id.menu_move_sent).setVisible(outbox);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String sort = prefs.getString("sort", "time");
@ -758,6 +763,10 @@ public class FragmentMessages extends FragmentEx {
loadMessages();
return true;
case R.id.menu_move_sent:
onMenuMoveSent();
return true;
default:
return super.onOptionsItemSelected(item);
}
@ -777,6 +786,48 @@ public class FragmentMessages extends FragmentEx {
fragmentTransaction.commit();
}
private void onMenuMoveSent() {
Bundle args = new Bundle();
args.putLong("folder", folder);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
long outbox = args.getLong("folder");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (EntityMessage message : db.message().getMessageSeen(outbox)) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
EntityFolder sent = db.folder().getFolderByType(identity.account, EntityFolder.SENT);
if (sent != null) {
message.folder = sent.id;
message.uid = null;
db.message().updateMessage(message);
Log.i(Helper.TAG, "Appending sent msgid=" + message.msgid);
EntityOperation.queue(db, message, EntityOperation.ADD); // Could already exist
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), ex);
}
}.load(this, args);
}
private void loadMessages() {
final DB db = DB.getInstance(getContext());


+ 5
- 0
app/src/main/res/menu/menu_messages.xml View File

@ -34,4 +34,9 @@
android:icon="@drawable/baseline_folder_open_24"
android:title="@string/title_folder_primary"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_move_sent"
android:title="@string/title_move_sent"
app:showAsAction="never" />
</menu>

+ 2
- 0
app/src/main/res/values/strings.xml View File

@ -235,6 +235,8 @@
<string name="title_sort_on_unread">Unread</string>
<string name="title_sort_on_starred">Starred</string>
<string name="title_move_sent">Move to sent</string>
<string name="title_previous">Previous</string>
<string name="title_next">Next</string>


Loading…
Cancel
Save