1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Fix search for Unified Inbox

We don't want to list the Inbox contents of all accounts but the
contents of folders whose "Unify" setting is true.
This commit is contained in:
cketti 2012-10-31 01:45:44 +01:00
parent a54666e020
commit 08b361ed36
6 changed files with 25 additions and 27 deletions

View File

@ -81,6 +81,8 @@ import com.fsck.k9.search.LocalSearch;
import com.fsck.k9.search.SearchAccount;
import com.fsck.k9.search.SearchModifier;
import com.fsck.k9.search.SearchSpecification;
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.Searchfield;
import com.fsck.k9.view.ColorChip;
import com.fsck.k9.preferences.SettingsExporter;
import com.fsck.k9.preferences.SettingsImportExportException;
@ -425,18 +427,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
* Creates and initializes the special accounts ('Unified Inbox' and 'All Messages')
*/
private void createSpecialAccounts() {
// create the unified inbox meta account ( all accounts is default when none specified )
String name = getString(R.string.integrated_inbox_title);
LocalSearch tmpSearch = new LocalSearch(name);
tmpSearch.addAllowedFolder(SearchSpecification.GENERIC_INBOX_NAME);
integratedInboxAccount = new SearchAccount(tmpSearch, name,
getString(R.string.integrated_inbox_detail));
// create the all messages search ( all accounts is default when none specified )
name = getString(R.string.search_all_messages_title);
tmpSearch = new LocalSearch(name);
unreadAccount = new SearchAccount(tmpSearch, name,
getString(R.string.search_all_messages_detail));
integratedInboxAccount = SearchAccount.createUnifiedInboxAccount(this);
unreadAccount = SearchAccount.createAllMessagesAccount(this);
}
@SuppressWarnings("unchecked")

View File

@ -93,10 +93,9 @@ public class LocalStore extends Store implements Serializable {
* in the correct order.
*/
static private String GET_MESSAGES_COLS =
"subject, sender_list, date, uid, flags, id, to_list, cc_list, "
"subject, sender_list, date, uid, flags, messages.id, to_list, cc_list, "
+ "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview, thread_root, thread_parent ";
static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class";
@ -967,7 +966,8 @@ public class LocalStore extends Store implements Serializable {
String where = query.toString();
String[] selectionArgs = queryArgs.toArray(EMPTY_STRING_ARRAY);
String sqlQuery = "SELECT " + GET_MESSAGES_COLS + "FROM messages WHERE " +
String sqlQuery = "SELECT " + GET_MESSAGES_COLS + "FROM messages " +
"LEFT JOIN folders ON (folders.id = messages.id) WHERE " +
"((empty IS NULL OR empty != 1) AND deleted = 0)" +
((!StringUtils.isNullOrEmpty(where)) ? " AND (" + where + ")" : "") +
" ORDER BY date DESC";

View File

@ -95,6 +95,7 @@ public class EmailProvider extends ContentProvider {
public static final String ACCOUNT_UUID = "account_uuid";
public static final String FOLDER_NAME = "name";
public static final String INTEGRATE = "integrate";
}
public interface MessageColumns {
@ -231,6 +232,7 @@ public class EmailProvider extends ContentProvider {
}
final Cursor cursor;
//TODO: check projection and selection for folder columns
if (Utility.arrayContains(projection, SpecialColumns.FOLDER_NAME)) {
StringBuilder query = new StringBuilder();
query.append("SELECT ");
@ -302,6 +304,9 @@ public class EmailProvider extends ContentProvider {
} else if (SpecialColumns.FOLDER_NAME.equals(columnName)) {
query.append("f." + SpecialColumns.FOLDER_NAME + " AS " +
SpecialColumns.FOLDER_NAME);
} else if (SpecialColumns.INTEGRATE.equals(columnName)) {
query.append("f." + SpecialColumns.INTEGRATE + " AS " +
SpecialColumns.INTEGRATE);
} else {
query.append("m.");
query.append(columnName);
@ -314,6 +319,7 @@ public class EmailProvider extends ContentProvider {
" FROM messages h JOIN messages m " +
"ON (h.id = m.thread_root OR h.id = m.id) ");
//TODO: check projection and selection for folder columns
if (Utility.arrayContains(projection, SpecialColumns.FOLDER_NAME)) {
query.append("LEFT JOIN folders f ON (m.folder_id = f.id) ");
}

View File

@ -6,6 +6,8 @@ import android.content.Context;
import com.fsck.k9.BaseAccount;
import com.fsck.k9.R;
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.Searchfield;
/**
* This class is basically a wrapper around a LocalSearch. It allows to expose it as
@ -26,7 +28,7 @@ public class SearchAccount implements BaseAccount {
public static SearchAccount createUnifiedInboxAccount(Context context) {
String name = context.getString(R.string.integrated_inbox_title);
LocalSearch tmpSearch = new LocalSearch(name);
tmpSearch.addAllowedFolder(SearchSpecification.GENERIC_INBOX_NAME);
tmpSearch.and(Searchfield.INTEGRATE, "1", Attribute.EQUALS);
return new SearchAccount(tmpSearch, name,
context.getString(R.string.integrated_inbox_detail));
}

View File

@ -29,7 +29,6 @@ public interface SearchSpecification extends Parcelable {
* Some meta names for certain conditions.
*/
public static final String ALL_ACCOUNTS = "allAccounts";
public static final String GENERIC_INBOX_NAME = "genericInboxName";
///////////////////////////////////////////////////////////////
// ATTRIBUTE enum
@ -78,7 +77,8 @@ public interface SearchSpecification extends Parcelable {
ATTACHMENT_COUNT,
DELETED,
THREAD_ROOT,
ID
ID,
INTEGRATE
}

View File

@ -27,14 +27,7 @@ public class SqlQueryBuilder {
SearchCondition condition = node.mCondition;
switch (condition.field) {
case FOLDER: {
String folderName;
//TODO: Fix the search condition used by the Unified Inbox (we search all
// folders with an enabled "Unify" folder setting).
if (LocalSearch.GENERIC_INBOX_NAME.equals(condition.value)) {
folderName = account.getInboxFolderName();
} else {
folderName = condition.value;
}
String folderName = condition.value;
long folderId = getFolderId(account, folderName);
query.append("folder_id = ?");
selectionArgs.add(Long.toString(folderId));
@ -139,6 +132,10 @@ public class SqlQueryBuilder {
columnName = "uid";
break;
}
case INTEGRATE: {
columnName = "integrate";
break;
}
}
if (columnName == null) {
@ -191,7 +188,7 @@ public class SqlQueryBuilder {
}
case EQUALS: {
if (isNumberColumn(field)) {
query.append("== ?");
query.append("= ?");
} else {
query.append("LIKE ?");
}
@ -214,6 +211,7 @@ public class SqlQueryBuilder {
case DELETED:
case FOLDER:
case ID:
case INTEGRATE:
case THREAD_ROOT: {
return true;
}