2012-10-13 14:03:40 -04:00
|
|
|
package com.fsck.k9.search;
|
|
|
|
|
2012-10-13 14:19:50 -04:00
|
|
|
import android.content.Context;
|
|
|
|
|
2012-10-13 14:03:40 -04:00
|
|
|
import com.fsck.k9.BaseAccount;
|
2012-10-13 14:19:50 -04:00
|
|
|
import com.fsck.k9.R;
|
2012-10-30 20:45:44 -04:00
|
|
|
import com.fsck.k9.search.SearchSpecification.Attribute;
|
|
|
|
import com.fsck.k9.search.SearchSpecification.Searchfield;
|
2012-10-13 14:03:40 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is basically a wrapper around a LocalSearch. It allows to expose it as
|
|
|
|
* an account. This is a meta-account containing all the e-mail that matches the search.
|
|
|
|
*/
|
|
|
|
public class SearchAccount implements BaseAccount {
|
2012-11-26 18:50:32 -05:00
|
|
|
public static final String ALL_MESSAGES = "all_messages";
|
|
|
|
public static final String UNIFIED_INBOX = "unified_inbox";
|
|
|
|
|
2012-10-13 14:03:40 -04:00
|
|
|
|
2012-10-13 14:19:50 -04:00
|
|
|
// create the all messages search ( all accounts is default when none specified )
|
2012-10-16 16:42:51 -04:00
|
|
|
public static SearchAccount createAllMessagesAccount(Context context) {
|
2012-10-13 14:19:50 -04:00
|
|
|
String name = context.getString(R.string.search_all_messages_title);
|
2012-12-07 06:55:32 -05:00
|
|
|
|
2012-10-13 14:19:50 -04:00
|
|
|
LocalSearch tmpSearch = new LocalSearch(name);
|
2012-12-07 06:55:32 -05:00
|
|
|
tmpSearch.and(Searchfield.SEARCHABLE, "1", Attribute.EQUALS);
|
|
|
|
|
2012-11-26 18:50:32 -05:00
|
|
|
return new SearchAccount(ALL_MESSAGES, tmpSearch, name,
|
2012-10-16 16:42:51 -04:00
|
|
|
context.getString(R.string.search_all_messages_detail));
|
|
|
|
}
|
2012-10-13 14:19:50 -04:00
|
|
|
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
// create the unified inbox meta account ( all accounts is default when none specified )
|
|
|
|
public static SearchAccount createUnifiedInboxAccount(Context context) {
|
2012-10-13 14:19:50 -04:00
|
|
|
String name = context.getString(R.string.integrated_inbox_title);
|
|
|
|
LocalSearch tmpSearch = new LocalSearch(name);
|
2012-10-30 20:45:44 -04:00
|
|
|
tmpSearch.and(Searchfield.INTEGRATE, "1", Attribute.EQUALS);
|
2012-11-26 18:50:32 -05:00
|
|
|
return new SearchAccount(UNIFIED_INBOX, tmpSearch, name,
|
2012-10-16 16:42:51 -04:00
|
|
|
context.getString(R.string.integrated_inbox_detail));
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:50:32 -05:00
|
|
|
private String mId;
|
2012-10-17 14:52:03 -04:00
|
|
|
private String mEmail;
|
|
|
|
private String mDescription;
|
|
|
|
private LocalSearch mSearch;
|
|
|
|
|
2012-11-26 18:50:32 -05:00
|
|
|
public SearchAccount(String id, LocalSearch search, String description, String email)
|
2012-10-17 14:52:03 -04:00
|
|
|
throws IllegalArgumentException {
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
if (search == null) {
|
|
|
|
throw new IllegalArgumentException("Provided LocalSearch was null");
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:50:32 -05:00
|
|
|
mId = id;
|
2012-10-17 14:52:03 -04:00
|
|
|
mSearch = search;
|
|
|
|
mDescription = description;
|
|
|
|
mEmail = email;
|
2012-10-13 14:03:40 -04:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:50:32 -05:00
|
|
|
public String getId() {
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2012-10-13 14:03:40 -04:00
|
|
|
@Override
|
|
|
|
public synchronized String getEmail() {
|
|
|
|
return mEmail;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void setEmail(String email) {
|
|
|
|
this.mEmail = email;
|
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-13 14:03:40 -04:00
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
return mDescription;
|
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-13 14:03:40 -04:00
|
|
|
@Override
|
|
|
|
public void setDescription(String description) {
|
|
|
|
this.mDescription = description;
|
2012-10-16 16:42:51 -04:00
|
|
|
}
|
2012-10-13 14:03:40 -04:00
|
|
|
|
|
|
|
public LocalSearch getRelatedSearch() {
|
2012-10-16 16:42:51 -04:00
|
|
|
return mSearch;
|
2012-10-13 14:03:40 -04:00
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-12-07 08:06:03 -05:00
|
|
|
/**
|
|
|
|
* Returns the ID of this {@code SearchAccount} instance.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* This isn't really a UUID. But since we don't expose this value to other apps and we only
|
|
|
|
* use the account UUID as opaque string (e.g. as key in a {@code Map}) we're fine.<br>
|
|
|
|
* Using a constant string is necessary to identify the same search account even when the
|
|
|
|
* corresponding {@link SearchAccount} object has been recreated.
|
|
|
|
* </p>
|
2012-10-13 14:03:40 -04:00
|
|
|
*/
|
2012-10-17 14:52:03 -04:00
|
|
|
@Override
|
2012-10-13 14:03:40 -04:00
|
|
|
public String getUuid() {
|
2012-12-07 08:06:03 -05:00
|
|
|
return mId;
|
2012-10-13 14:03:40 -04:00
|
|
|
}
|
|
|
|
}
|