Showing source folder on moving

pull/184/head
M66B 5 years ago
parent 42f1e43dde
commit 504da909d0

@ -163,6 +163,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.KeyStore; import java.security.KeyStore;
@ -894,21 +895,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
try { try {
db.beginTransaction(); db.beginTransaction();
EntityFolder target = db.folder().getFolderByType(aid, type); EntityAccount account = db.account().getAccount(aid);
if (target != null) { if (account == null)
EntityAccount account = db.account().getAccount(target.account); return result;
List<EntityMessage> messages = db.message().getMessagesByThread(
aid, thread, threading ? null : id, null); EntityFolder targetFolder = db.folder().getFolderByType(aid, type);
for (EntityMessage threaded : messages) { if (targetFolder == null)
EntityFolder folder = db.folder().getFolder(threaded.folder); return result;
if (!folder.read_only &&
!target.id.equals(threaded.folder) && List<EntityMessage> messages = db.message().getMessagesByThread(
(!filter_archive || !EntityFolder.ARCHIVE.equals(folder.type)) && aid, thread, threading ? null : id, null);
!EntityFolder.DRAFTS.equals(folder.type) && !EntityFolder.OUTBOX.equals(folder.type) && for (EntityMessage threaded : messages) {
(!EntityFolder.SENT.equals(folder.type) || EntityFolder.TRASH.equals(target.type)) && EntityFolder sourceFolder = db.folder().getFolder(threaded.folder);
!EntityFolder.TRASH.equals(folder.type) && !EntityFolder.JUNK.equals(folder.type)) if (sourceFolder != null && !sourceFolder.read_only &&
result.add(new MessageTarget(threaded, account, target)); !targetFolder.id.equals(threaded.folder) &&
} (!filter_archive || !EntityFolder.ARCHIVE.equals(sourceFolder.type)) &&
!EntityFolder.DRAFTS.equals(sourceFolder.type) && !EntityFolder.OUTBOX.equals(sourceFolder.type) &&
(!EntityFolder.SENT.equals(sourceFolder.type) || EntityFolder.TRASH.equals(targetFolder.type)) &&
!EntityFolder.TRASH.equals(sourceFolder.type) && !EntityFolder.JUNK.equals(sourceFolder.type))
result.add(new MessageTarget(context, threaded, account, sourceFolder, account, targetFolder));
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -1663,12 +1668,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
return result; return result;
EntityFolder target = db.folder().getFolderByType(message.account, type); EntityAccount account = db.account().getAccount(message.account);
if (target == null) if (account == null)
return result;
EntityFolder sourceFolder = db.folder().getFolder(message.folder);
if (sourceFolder == null)
return result; return result;
EntityAccount account = db.account().getAccount(target.account); EntityFolder targetFolder = db.folder().getFolderByType(message.account, type);
result.add(new MessageTarget(message, account, target)); if (targetFolder == null)
return result;
result.add(new MessageTarget(context, message, account, sourceFolder, account, targetFolder));
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -2125,15 +2137,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
return result; return result;
EntityFolder target = db.folder().getFolder(tid); EntityAccount sourceAccount = db.account().getAccount(message.account);
if (target == null) if (sourceAccount == null)
return result;
EntityFolder targetFolder = db.folder().getFolder(tid);
if (targetFolder == null)
return result;
EntityAccount targetAccount = db.account().getAccount(targetFolder.account);
if (targetAccount == null)
return result; return result;
EntityAccount account = db.account().getAccount(target.account);
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading && thread ? null : id, message.folder); message.account, message.thread, threading && thread ? null : id, message.folder);
for (EntityMessage threaded : messages) for (EntityMessage threaded : messages) {
result.add(new MessageTarget(threaded, account, target)); EntityFolder sourceFolder = db.folder().getFolder(threaded.folder);
if (sourceFolder == null)
continue;
result.add(new MessageTarget(context, threaded, sourceAccount, sourceFolder, targetAccount, targetFolder));
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -3011,14 +3035,22 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
continue; continue;
EntityAccount account = db.account().getAccount(message.account);
if (account == null)
continue;
EntityFolder targetFolder = db.folder().getFolderByType(message.account, type);
if (targetFolder == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder); message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages) {
EntityFolder target = db.folder().getFolderByType(message.account, type); EntityFolder sourceFolder = db.folder().getFolder(threaded.folder);
if (target != null) { if (sourceFolder == null)
EntityAccount account = db.account().getAccount(target.account); continue;
result.add(new MessageTarget(threaded, account, target));
} result.add(new MessageTarget(context, threaded, account, sourceFolder, account, targetFolder));
} }
} }
@ -3074,18 +3106,31 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
try { try {
db.beginTransaction(); db.beginTransaction();
EntityFolder target = db.folder().getFolder(tid); EntityFolder targetFolder = db.folder().getFolder(tid);
if (target != null) { if (targetFolder == null)
EntityAccount account = db.account().getAccount(target.account); return result;
for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityAccount targetAccount = db.account().getAccount(targetFolder.account);
if (message == null) if (targetAccount == null)
return result;
for (long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message == null)
continue;
EntityAccount sourceAccount = db.account().getAccount(message.account);
if (sourceAccount == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) {
EntityFolder sourceFolder = db.folder().getFolder(threaded.folder);
if (sourceFolder == null)
continue; continue;
List<EntityMessage> messages = db.message().getMessagesByThread( result.add(new MessageTarget(context, threaded, sourceAccount, sourceFolder, targetAccount, targetFolder, copy));
message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages)
result.add(new MessageTarget(threaded, account, target, copy));
} }
} }
@ -4405,9 +4450,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (MessageTarget target : targets) for (MessageTarget target : targets)
if (message.id.equals(target.id)) { if (message.id.equals(target.id)) {
Log.i("Eval thread target id=" + target.id); Log.i("Eval thread target id=" + target.id);
if (!target.across) { if (!target.isAccross()) {
found = true; found = true;
if (target.folder.id == folder) if (target.targetFolder.id == folder)
count++; count++;
} }
mt.remove(target); mt.remove(target);
@ -4419,7 +4464,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
for (MessageTarget target : mt) for (MessageTarget target : mt)
if (!target.across && target.folder.id == folder && if (!target.isAccross() && target.targetFolder.id == folder &&
(removed == null || !removed.contains(target.id))) (removed == null || !removed.contains(target.id)))
count++; count++;
@ -4720,7 +4765,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putString("question", getResources() aargs.putString("question", getResources()
.getQuantityString(R.plurals.title_moving_messages, .getQuantityString(R.plurals.title_moving_messages,
result.size(), result.size(), getDisplay(result))); result.size(), result.size(),
getDisplay(result, false),
getDisplay(result, true)));
aargs.putString("notagain", key); aargs.putString("notagain", key);
aargs.putParcelableArrayList("result", result); aargs.putParcelableArrayList("result", result);
@ -4752,11 +4799,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
continue; continue;
Log.i("Move id=" + target.id + " target=" + target.folder.name + " copy=" + target.copy); Log.i("Move id=" + target.id + " target=" + target.targetFolder.name + " copy=" + target.copy);
if (target.copy) if (target.copy)
EntityOperation.queue(context, message, EntityOperation.COPY, target.folder.id); EntityOperation.queue(context, message, EntityOperation.COPY, target.targetFolder.id);
else else
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); EntityOperation.queue(context, message, EntityOperation.MOVE, target.targetFolder.id);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -4850,10 +4897,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null || !message.ui_hide) if (message == null || !message.ui_hide)
continue; continue;
Log.i("Move id=" + target.id + " target=" + target.folder.name); Log.i("Move id=" + target.id + " target=" + target.targetFolder.name);
db.message().setMessageUiBusy(target.id, null); db.message().setMessageUiBusy(target.id, null);
db.message().setMessageLastAttempt(target.id, new Date().getTime()); db.message().setMessageLastAttempt(target.id, new Date().getTime());
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); EntityOperation.queue(context, message, EntityOperation.MOVE, target.targetFolder.id);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -4907,7 +4954,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return; return;
} }
String title = getString(R.string.title_move_undo, getDisplay(result), result.size()); String title = getString(R.string.title_move_undo, getDisplay(result, true), result.size());
((ActivityView) activity).undo(title, args, move, show); ((ActivityView) activity).undo(title, args, move, show);
} }
@ -4918,16 +4965,18 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "undo:hide"); }.execute(this, args, "undo:hide");
} }
private String getDisplay(ArrayList<MessageTarget> result) { private String getDisplay(ArrayList<MessageTarget> result, boolean dest) {
boolean across = false; boolean across = false;
for (MessageTarget target : result) for (MessageTarget target : result)
if (target.across) if (target.isAccross())
across = true; across = true;
List<String> displays = new ArrayList<>(); List<String> displays = new ArrayList<>();
for (MessageTarget target : result) { for (MessageTarget target : result) {
String display = (across ? target.account.name + "/" : "") + String display = "";
target.folder.getDisplayName(getContext()); if (across)
display += (dest ? target.targetAccount.name : target.sourceAccount.name) + "/";
display += (dest ? target.targetFolder.display : target.sourceFolder.display);
if (!displays.contains(display)) if (!displays.contains(display))
displays.add(display); displays.add(display);
} }
@ -6497,7 +6546,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private void onMoveAskAcross(final ArrayList<MessageTarget> result) { private void onMoveAskAcross(final ArrayList<MessageTarget> result) {
boolean across = false; boolean across = false;
for (MessageTarget target : result) for (MessageTarget target : result)
if (target.across) { if (target.isAccross()) {
across = true; across = true;
break; break;
} }
@ -6691,20 +6740,29 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
return result; return result;
EntityFolder target = db.folder().getFolder(tid); EntityAccount sourceAccount = db.account().getAccount(message.account);
if (target == null) if (sourceAccount == null)
return result; return result;
EntityAccount account = db.account().getAccount(target.account); EntityFolder targetFolder = db.folder().getFolder(tid);
if (account != null) { if (targetFolder == null)
List<EntityMessage> messages = db.message().getMessagesByThread( return result;
message.account, message.thread, threading && similar ? null : id, message.folder);
for (EntityMessage threaded : messages) EntityAccount targetAccount = db.account().getAccount(targetFolder.account);
if (copy) if (targetAccount == null)
EntityOperation.queue(context, message, EntityOperation.COPY, tid); return result;
else
result.add(new MessageTarget(threaded, account, target)); List<EntityMessage> messages = db.message().getMessagesByThread(
} message.account, message.thread, threading && similar ? null : id, message.folder);
for (EntityMessage threaded : messages)
if (copy)
EntityOperation.queue(context, message, EntityOperation.COPY, tid);
else {
EntityFolder sourceFolder = db.folder().getFolder(threaded.folder);
if (sourceFolder == null)
continue;
result.add(new MessageTarget(context, threaded, sourceAccount, sourceFolder, targetAccount, targetFolder));
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -7036,44 +7094,53 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static class MessageTarget implements Parcelable { private static class MessageTarget implements Parcelable {
long id; long id;
boolean across; Account sourceAccount;
EntityAccount account; Folder sourceFolder;
EntityFolder folder; Account targetAccount;
Folder targetFolder;
boolean copy; boolean copy;
MessageTarget(EntityMessage message, EntityAccount account, EntityFolder folder) { MessageTarget(Context context, EntityMessage message,
this.id = message.id; EntityAccount sourceAccount, EntityFolder sourceFolder,
this.across = !folder.account.equals(message.account); EntityAccount targetAccount, EntityFolder targetFolder) {
this.account = account; this(context, message, sourceAccount, sourceFolder, targetAccount, targetFolder, false);
this.folder = folder;
this.copy = false;
} }
MessageTarget(EntityMessage message, EntityAccount account, EntityFolder folder, boolean copy) { MessageTarget(Context context, EntityMessage message,
EntityAccount sourceAccount, EntityFolder sourceFolder,
EntityAccount targetAccount, EntityFolder targetFolder,
boolean copy) {
this.id = message.id; this.id = message.id;
this.across = !folder.account.equals(message.account); this.sourceAccount = new Account(sourceAccount);
this.account = account; this.sourceFolder = new Folder(context, sourceFolder);
this.folder = folder; this.targetAccount = new Account(targetAccount);
this.targetFolder = new Folder(context, targetFolder);
this.copy = copy; this.copy = copy;
} }
protected MessageTarget(Parcel in) { protected MessageTarget(Parcel in) {
id = in.readLong(); id = in.readLong();
across = (in.readInt() != 0); sourceAccount = (Account) in.readSerializable();
account = (EntityAccount) in.readSerializable(); sourceFolder = (Folder) in.readSerializable();
folder = (EntityFolder) in.readSerializable(); targetAccount = (Account) in.readSerializable();
targetFolder = (Folder) in.readSerializable();
copy = (in.readInt() != 0); copy = (in.readInt() != 0);
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id); dest.writeLong(id);
dest.writeInt(across ? 1 : 0); dest.writeSerializable(sourceAccount);
dest.writeSerializable(account); dest.writeSerializable(sourceFolder);
dest.writeSerializable(folder); dest.writeSerializable(targetAccount);
dest.writeSerializable(targetFolder);
dest.writeInt(copy ? 1 : 0); dest.writeInt(copy ? 1 : 0);
} }
boolean isAccross() {
return (sourceAccount.id != targetAccount.id);
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@ -7090,6 +7157,28 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return new MessageTarget[size]; return new MessageTarget[size];
} }
}; };
static class Account implements Serializable {
long id;
String name;
Account(EntityAccount account) {
this.id = account.id;
this.name = account.name;
}
}
static class Folder implements Serializable {
long id;
String name;
String display;
Folder(Context context, EntityFolder folder) {
this.id = folder.id;
this.name = folder.name;
this.display = folder.getDisplayName(context);
}
}
} }
public static class FragmentDialogReporting extends FragmentDialogBase { public static class FragmentDialogReporting extends FragmentDialogBase {

@ -55,8 +55,8 @@
<item quantity="other">%1$d gesprekken geselecteerd</item> <item quantity="other">%1$d gesprekken geselecteerd</item>
</plurals> </plurals>
<plurals name="title_moving_messages"> <plurals name="title_moving_messages">
<item quantity="one">Eén bericht verplaatsen naar %2$s ?</item> <item quantity="one">Één bericht verplaatsen van %2$s naar %3$s?</item>
<item quantity="other">%1$d berichten verplaatsen naar %2$s?</item> <item quantity="other">%1$d berichten verplaatsen van %2$s naar %3$s?</item>
</plurals> </plurals>
<plurals name="title_deleting_messages"> <plurals name="title_deleting_messages">
<item quantity="one">Verwijder één bericht definitief?</item> <item quantity="one">Verwijder één bericht definitief?</item>
@ -736,7 +736,7 @@
<string name="title_unused_inline">Ongebruikte inline afbeeldingen worden verwijderd bij verzenden</string> <string name="title_unused_inline">Ongebruikte inline afbeeldingen worden verwijderd bij verzenden</string>
<string name="title_accross_remark">Berichten die worden verplaatst tussen accounts worden opnieuw gedownload en veroorzaken extra datagebruik</string> <string name="title_accross_remark">Berichten die worden verplaatst tussen accounts worden opnieuw gedownload en veroorzaken extra datagebruik</string>
<string name="title_raw_saved">Ruw bericht opgeslagen</string> <string name="title_raw_saved">Ruw bericht opgeslagen</string>
<string name="title_attachment_eml" comment="title_attachment_eml&#10;This is a title (heading) for displaying attached messages (EML files)">Bijgevoegd bericht</string> <string name="title_attachment_eml">Bijgevoegd bericht</string>
<string name="title_attachment_saved">Bijlage opgeslagen</string> <string name="title_attachment_saved">Bijlage opgeslagen</string>
<string name="title_attachments_saved">Bijlagen opgeslagen</string> <string name="title_attachments_saved">Bijlagen opgeslagen</string>
<string name="title_attachments_incomplete">Sommige bijlagen of afbeeldingen zijn niet gedownload en konden niet worden toegevoegd</string> <string name="title_attachments_incomplete">Sommige bijlagen of afbeeldingen zijn niet gedownload en konden niet worden toegevoegd</string>
@ -1039,6 +1039,7 @@
<string name="title_legend_download_fetch">Aantal berichtteksten gedownload / koppen opgehaald</string> <string name="title_legend_download_fetch">Aantal berichtteksten gedownload / koppen opgehaald</string>
<string name="title_legend_stop">Stop met het verwerken van regels</string> <string name="title_legend_stop">Stop met het verwerken van regels</string>
<string name="title_legend_thread">Gesprek</string> <string name="title_legend_thread">Gesprek</string>
<string name="title_legend_bookmark">Laatste geopende gesprek</string>
<string name="title_legend_zoom">Tekstgrootte wijzigen</string> <string name="title_legend_zoom">Tekstgrootte wijzigen</string>
<string name="title_legend_draft">Heeft concept</string> <string name="title_legend_draft">Heeft concept</string>
<string name="title_legend_priority">Heeft hoge prioriteit</string> <string name="title_legend_priority">Heeft hoge prioriteit</string>

@ -71,8 +71,8 @@
</plurals> </plurals>
<plurals name="title_moving_messages"> <plurals name="title_moving_messages">
<item quantity="one">Move %1$d message to %2$s?</item> <item quantity="one">Move %1$d message from %2$s to %3$s?</item>
<item quantity="other">Move %1$d messages to %2$s?</item> <item quantity="other">Move %1$d messages from %2$s to %3$s?</item>
</plurals> </plurals>
<plurals name="title_deleting_messages"> <plurals name="title_deleting_messages">

Loading…
Cancel
Save