Refactoring

pull/172/head
M66B 5 years ago
parent ef5a63c0ff
commit f0192b46e8

@ -95,14 +95,14 @@ public class AdapterKeyword extends RecyclerView.Adapter<AdapterKeyword.ViewHold
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", keyword.name);
args.putBoolean("selected", keyword.selected);
args.putBoolean("set", keyword.selected);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
String name = args.getString("name");
boolean selected = args.getBoolean("selected");
boolean set = args.getBoolean("set");
DB db = DB.getInstance(context);
@ -110,7 +110,7 @@ public class AdapterKeyword extends RecyclerView.Adapter<AdapterKeyword.ViewHold
if (message == null)
return null;
EntityOperation.queue(context, message, EntityOperation.KEYWORD, name, selected);
EntityOperation.queue(context, message, EntityOperation.KEYWORD, name, set);
return null;
}

@ -655,24 +655,6 @@ class Core {
Flags flags = new Flags(keyword);
imessage.setFlags(flags, set);
try {
db.beginTransaction();
message = db.message().getMessage(message.id);
List<String> keywords = new ArrayList<>(Arrays.asList(message.keywords));
while (keywords.remove(keyword))
;
if (set)
keywords.add(keyword);
db.message().setMessageKeywords(message.id, DB.Converters.fromStringArray(keywords.toArray(new String[0])));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
private static void onAdd(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder) throws MessagingException, IOException {

@ -35,8 +35,12 @@ import org.json.JSONException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -145,6 +149,19 @@ public class EntityOperation {
}
return;
} else if (KEYWORD.equals(name)) {
String keyword = jargs.getString(0);
boolean set = jargs.getBoolean(1);
List<String> keywords = new ArrayList<>(Arrays.asList(message.keywords));
while (keywords.remove(keyword))
;
if (set)
keywords.add(keyword);
Collections.sort(keywords);
db.message().setMessageKeywords(message.id, DB.Converters.fromStringArray(keywords.toArray(new String[0])));
} else if (MOVE.equals(name)) {
// Parameters:
// 0: target folder

Loading…
Cancel
Save