Save search with account uuid / folder name

pull/210/head
M66B 2 years ago
parent bd3a963f96
commit ea2fc9f09d

File diff suppressed because it is too large Load Diff

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -107,20 +108,46 @@ public class AdapterNavSearch extends RecyclerView.Adapter<AdapterNavSearch.View
if (search == null)
return;
try {
JSONObject json = new JSONObject(search.data);
BoundaryCallbackMessages.SearchCriteria criteria =
BoundaryCallbackMessages.SearchCriteria.fromJSON(json);
criteria.id = search.id;
criteria.name = search.name;
criteria.order = search.order;
criteria.color = search.color;
FragmentMessages.search(
context, owner, manager,
-1L, -1L, false, criteria);
} catch (Throwable ex) {
Log.e(ex);
}
Bundle args = new Bundle();
args.putString("account_uuid", search.account_uuid);
args.putString("folder_name", search.folder_name);
new SimpleTask<Long[]>() {
@Override
protected Long[] onExecute(Context context, Bundle args) throws Throwable {
String account_uuid = args.getString("account_uuid");
String folder_name = args.getString("folder_name");
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccountByUUID(account_uuid);
EntityFolder folder = db.folder().getFolderByName(account == null ? -1L : account.id, folder_name);
return new Long[]{account == null ? -1L : account.id, folder == null ? -1L : folder.id};
}
@Override
protected void onExecuted(Bundle args, Long[] data) {
try {
JSONObject json = new JSONObject(search.data);
BoundaryCallbackMessages.SearchCriteria criteria =
BoundaryCallbackMessages.SearchCriteria.fromJSON(json);
criteria.id = search.id;
criteria.name = search.name;
criteria.order = search.order;
criteria.color = search.color;
FragmentMessages.search(
context, owner, manager,
data[0], data[1], false, criteria);
} catch (Throwable ex) {
Log.e(ex);
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(manager, ex);
}
}.execute(context, owner, args, "search");
}
}

@ -67,7 +67,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 256,
version = 257,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -2591,6 +2591,13 @@ public abstract class DB extends RoomDatabase {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `capability_uidl` INTEGER");
}
}).addMigrations(new Migration(256, 257) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `search` ADD COLUMN `account_uuid` TEXT");
db.execSQL("ALTER TABLE `search` ADD COLUMN `folder_name` TEXT");
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -40,6 +40,8 @@ public class EntitySearch {
@PrimaryKey(autoGenerate = true)
public Long id;
public String account_uuid;
public String folder_name;
@NonNull
public String name;
public Integer order;
@ -50,6 +52,8 @@ public class EntitySearch {
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("account", account_uuid);
json.put("folder", folder_name);
json.put("name", name);
json.put("order", order);
json.put("color", color);
@ -60,6 +64,10 @@ public class EntitySearch {
public static EntitySearch fromJSON(JSONObject json) throws JSONException {
EntitySearch search = new EntitySearch();
// id
if (json.has("account"))
search.account_uuid = json.getString("account");
if (json.has("folder"))
search.folder_name = json.getString("folder");
search.name = json.getString("name");
if (json.has("order"))
search.order = json.getInt("order");

@ -5575,6 +5575,8 @@ public class FragmentMessages extends FragmentBase
private void onMenuSaveSearch() {
Bundle args = new Bundle();
args.putLong("account", account);
args.putLong("folder", folder);
args.putSerializable("criteria", criteria);
FragmentDialogSaveSearch fragment = new FragmentDialogSaveSearch();
@ -5988,6 +5990,9 @@ public class FragmentMessages extends FragmentBase
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(args.getLong("account"));
EntityFolder folder = db.folder().getFolder(args.getLong("folder"));
EntitySearch search = null;
if (criteria.id != null)
search = db.search().getSearch(criteria.id);
@ -5996,6 +6001,8 @@ public class FragmentMessages extends FragmentBase
int order = args.getInt("order");
search.account_uuid = (account == null ? null : account.uuid);
search.folder_name = (folder == null ? null : folder.name);
search.name = args.getString("name");
search.order = (order < 0 ? null : order);
search.color = args.getInt("color", Color.TRANSPARENT);

Loading…
Cancel
Save