Default search for flagged/unseen messages

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

File diff suppressed because it is too large Load Diff

@ -130,7 +130,7 @@ public class AdapterNavSearch extends RecyclerView.Adapter<AdapterNavSearch.View
try { try {
JSONObject json = new JSONObject(search.data); JSONObject json = new JSONObject(search.data);
BoundaryCallbackMessages.SearchCriteria criteria = BoundaryCallbackMessages.SearchCriteria criteria =
BoundaryCallbackMessages.SearchCriteria.fromJSON(json); BoundaryCallbackMessages.SearchCriteria.fromJsonData(json);
criteria.id = search.id; criteria.id = search.id;
criteria.name = search.name; criteria.name = search.name;
criteria.order = search.order; criteria.order = search.order;

@ -1249,7 +1249,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return false; return false;
} }
JSONObject toJson() throws JSONException { JSONObject toJsonData() throws JSONException {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("query", query); json.put("query", query);
json.put("fts", fts); json.put("fts", fts);
@ -1296,7 +1296,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return json; return json;
} }
public static SearchCriteria fromJSON(JSONObject json) throws JSONException { public static SearchCriteria fromJsonData(JSONObject json) throws JSONException {
SearchCriteria criteria = new SearchCriteria(); SearchCriteria criteria = new SearchCriteria();
criteria.query = json.optString("query"); criteria.query = json.optString("query");
criteria.fts = json.optBoolean("fts"); criteria.fts = json.optBoolean("fts");

@ -67,7 +67,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 257, version = 258,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -408,6 +408,11 @@ public abstract class DB extends RoomDatabase {
.setTransactionExecutor(Helper.getParallelExecutor()) .setTransactionExecutor(Helper.getParallelExecutor())
.setJournalMode(wal ? JournalMode.WRITE_AHEAD_LOGGING : JournalMode.TRUNCATE) // using the latest sqlite .setJournalMode(wal ? JournalMode.WRITE_AHEAD_LOGGING : JournalMode.TRUNCATE) // using the latest sqlite
.addCallback(new Callback() { .addCallback(new Callback() {
@Override
public void onCreate(@NonNull SupportSQLiteDatabase db) {
defaultSearches(db, context);
}
@Override @Override
public void onOpen(@NonNull SupportSQLiteDatabase db) { public void onOpen(@NonNull SupportSQLiteDatabase db) {
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
@ -2598,6 +2603,18 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `search` ADD COLUMN `account_uuid` TEXT"); db.execSQL("ALTER TABLE `search` ADD COLUMN `account_uuid` TEXT");
db.execSQL("ALTER TABLE `search` ADD COLUMN `folder_name` TEXT"); db.execSQL("ALTER TABLE `search` ADD COLUMN `folder_name` TEXT");
} }
}).addMigrations(new Migration(257, 258) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
defaultSearches(db, context);
}
}).addMigrations(new Migration(258, 257) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
defaultSearches(db, context);
}
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {
@ -2611,6 +2628,33 @@ public abstract class DB extends RoomDatabase {
}); });
} }
public static void defaultSearches(SupportSQLiteDatabase db, Context context) {
try {
BoundaryCallbackMessages.SearchCriteria criteria;
criteria = new BoundaryCallbackMessages.SearchCriteria();
criteria.with_flagged = true;
db.execSQL("INSERT INTO `search` (`name`, `order`, `data`) VALUES (?, ?, ?)",
new Object[]{
context.getString(R.string.title_search_with_flagged),
0,
criteria.toJsonData().toString()
});
criteria = new BoundaryCallbackMessages.SearchCriteria();
criteria.with_unseen = true;
db.execSQL("INSERT INTO `search` (`name`, `order`, `data`) VALUES (?, ?, ?)",
new Object[]{
context.getString(R.string.title_search_with_unseen),
0,
criteria.toJsonData().toString()
});
} catch (Throwable ex) {
Log.e(ex);
}
}
public static void checkpoint(Context context) { public static void checkpoint(Context context) {
// https://www.sqlite.org/pragma.html#pragma_wal_checkpoint // https://www.sqlite.org/pragma.html#pragma_wal_checkpoint
DB db = getInstance(context); DB db = getInstance(context);

@ -6006,7 +6006,7 @@ public class FragmentMessages extends FragmentBase
search.name = args.getString("name"); search.name = args.getString("name");
search.order = (order < 0 ? null : order); search.order = (order < 0 ? null : order);
search.color = args.getInt("color", Color.TRANSPARENT); search.color = args.getInt("color", Color.TRANSPARENT);
search.data = criteria.toJson().toString(); search.data = criteria.toJsonData().toString();
if (search.color == Color.TRANSPARENT) if (search.color == Color.TRANSPARENT)
search.color = null; search.color = null;

Loading…
Cancel
Save