mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 17:57:16 +00:00
Rule import/export restore folder type
This commit is contained in:
parent
7b146ededa
commit
bbd66a22bb
2 changed files with 35 additions and 5 deletions
|
@ -63,7 +63,6 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static eu.faircode.email.EntityRule.TYPE_MOVE;
|
||||
|
||||
public class FragmentRules extends FragmentBase {
|
||||
private long account;
|
||||
|
@ -337,8 +336,21 @@ public class FragmentRules extends FragmentBase {
|
|||
|
||||
DB db = DB.getInstance(context);
|
||||
JSONArray jrules = new JSONArray();
|
||||
for (EntityRule rule : db.rule().getRules(fid))
|
||||
for (EntityRule rule : db.rule().getRules(fid)) {
|
||||
JSONObject jaction = new JSONObject(rule.action);
|
||||
|
||||
int type = jaction.getInt("type");
|
||||
if (type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY) {
|
||||
long target = jaction.optLong("target", -1);
|
||||
EntityFolder f = db.folder().getFolder(target);
|
||||
if (f != null)
|
||||
jaction.put("folderType", f.type);
|
||||
}
|
||||
|
||||
rule.action = jaction.toString();
|
||||
|
||||
jrules.put(rule.toJSON());
|
||||
}
|
||||
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
try (OutputStream os = resolver.openOutputStream(uri)) {
|
||||
|
@ -403,9 +415,29 @@ public class FragmentRules extends FragmentBase {
|
|||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityFolder folder = db.folder().getFolder(fid);
|
||||
if (folder == null)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < jrules.length(); i++) {
|
||||
JSONObject jrule = jrules.getJSONObject(i);
|
||||
EntityRule rule = EntityRule.fromJSON(jrule);
|
||||
|
||||
JSONObject jaction = new JSONObject(rule.action);
|
||||
|
||||
int type = jaction.getInt("type");
|
||||
if (type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY) {
|
||||
String folderType = jaction.optString("folderType");
|
||||
if (!EntityFolder.SYSTEM.equals(folderType) &&
|
||||
!EntityFolder.USER.equals(folderType)) {
|
||||
EntityFolder f = db.folder().getFolderByType(folder.account, folderType);
|
||||
if (f != null)
|
||||
jaction.put("target", f.id);
|
||||
}
|
||||
}
|
||||
|
||||
rule.action = jaction.toString();
|
||||
|
||||
rule.folder = fid;
|
||||
rule.applied = 0;
|
||||
rule.id = db.rule().insertRule(rule);
|
||||
|
@ -485,7 +517,7 @@ public class FragmentRules extends FragmentBase {
|
|||
JSONObject jaction = new JSONObject(rule.action);
|
||||
int type = jaction.optInt("type", -1);
|
||||
long target = jaction.optLong("target", -1);
|
||||
if (type == TYPE_MOVE && target == junk.id)
|
||||
if (type == EntityRule.TYPE_MOVE && target == junk.id)
|
||||
db.rule().deleteRule(rule.id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,11 @@
|
|||
<item
|
||||
android:id="@+id/menu_export"
|
||||
android:title="@string/title_rules_export"
|
||||
android:visible="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_import"
|
||||
android:title="@string/title_rules_import"
|
||||
android:visible="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
|
|
Loading…
Reference in a new issue