Full search on device

This commit is contained in:
M66B 2019-01-26 15:49:49 +00:00
parent bd07b7b80e
commit b0a605ce9b
3 changed files with 14 additions and 19 deletions

View File

@ -51,9 +51,9 @@ public interface DaoFolder {
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE ((:folder IS NULL AND unified) OR (NOT :folder is NULL AND folder.id = :folder))" +
" WHERE folder.id = :folder" +
" AND (:search OR (account.synchronize AND account.browse))")
List<EntityFolder> getBrowsableFolders(Long folder, boolean search);
EntityFolder getBrowsableFolder(long folder, boolean search);
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", COUNT(message.id) AS messages" +

View File

@ -56,7 +56,7 @@ public interface DaoMessage {
", SUM(CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END) AS drafts" +
", 0 AS duplicate" +
", COUNT(DISTINCT message.msgid) AS visible" +
", MAX(CASE WHEN folder.unified THEN message.received ELSE 0 END) AS dummy" +
", MAX(CASE WHEN :found OR folder.unified THEN message.received ELSE 0 END) AS dummy" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +
@ -66,7 +66,7 @@ public interface DaoMessage {
" AND (:snoozed OR :found OR ui_snoozed IS NULL)" +
" AND (NOT :found OR ui_found = :found)" +
" GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" HAVING SUM(unified) > 0" +
" HAVING :found OR SUM(unified) > 0" +
" ORDER BY" +
" CASE WHEN 'sender' = :sort THEN message.sender ELSE '' END," +
" CASE" +
@ -175,10 +175,10 @@ public interface DaoMessage {
@Query("SELECT id" +
" FROM message" +
" WHERE folder IN (:folders)" +
" WHERE (:folder IS NULL OR folder = :folder)" +
" AND NOT ui_hide" +
" ORDER BY message.received DESC")
List<Long> getMessageByFolders(List<Long> folders);
List<Long> getMessageIdsByFolder(Long folder);
@Query("SELECT *" +
" FROM message" +

View File

@ -59,7 +59,7 @@ public class ViewModelBrowse extends ViewModel {
private class State {
private Context context;
private long fid;
private Long fid;
private String search;
private int pageSize;
@ -76,7 +76,7 @@ public class ViewModelBrowse extends ViewModel {
void set(Context context, long folder, String search, int pageSize) {
currentState = new State();
currentState.context = context;
currentState.fid = folder;
currentState.fid = (folder < 0 ? null : folder);
currentState.search = search;
currentState.pageSize = pageSize;
currentState.index = -1;
@ -94,21 +94,13 @@ public class ViewModelBrowse extends ViewModel {
return;
DB db = DB.getInstance(state.context);
final List<EntityFolder> folders = db.folder().getBrowsableFolders(
state.fid < 0 ? null : state.fid, state.search != null);
Log.i("Search fid=" + (state.fid < 0 ? null : state.fid) + " search=" + (state.search == null) + " count=" + folders.size());
if (folders.size() == 0)
return;
if (state.search != null)
try {
db.beginTransaction();
if (state.messages == null) {
List<Long> fids = new ArrayList<>();
for (EntityFolder folder : folders)
fids.add(folder.id);
state.messages = db.message().getMessageByFolders(fids);
state.messages = db.message().getMessageIdsByFolder(state.fid);
Log.i("Messages=" + state.messages.size());
}
@ -153,10 +145,13 @@ public class ViewModelBrowse extends ViewModel {
db.endTransaction();
}
if (folders.size() > 1)
if (state.fid == null)
return;
final EntityFolder folder = db.folder().getBrowsableFolder(state.fid, state.search != null);
if (folder == null)
return;
final EntityFolder folder = folders.get(0);
if (state.imessages == null) {
EntityAccount account = db.account().getAccount(folder.account);