1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-10 03:25:04 -05:00
k-9/src/com/fsck/k9/search/SearchAccount.java

104 lines
3.1 KiB
Java
Raw Normal View History

package com.fsck.k9.search;
import java.util.UUID;
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
* an account. This is a meta-account containing all the e-mail that matches the search.
*/
public class SearchAccount implements BaseAccount {
public static final String ALL_MESSAGES = "all_messages";
public static final String UNIFIED_INBOX = "unified_inbox";
// 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) {
String name = context.getString(R.string.search_all_messages_title);
LocalSearch tmpSearch = new LocalSearch(name);
tmpSearch.and(Searchfield.SEARCHABLE, "1", Attribute.EQUALS);
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-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) {
String name = context.getString(R.string.integrated_inbox_title);
LocalSearch tmpSearch = new LocalSearch(name);
tmpSearch.and(Searchfield.INTEGRATE, "1", Attribute.EQUALS);
return new SearchAccount(UNIFIED_INBOX, tmpSearch, name,
2012-10-16 16:42:51 -04:00
context.getString(R.string.integrated_inbox_detail));
}
private String mId;
2012-10-17 14:52:03 -04:00
private String mEmail;
private String mDescription;
private LocalSearch mSearch;
private String mFakeUuid;
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");
}
mId = id;
2012-10-17 14:52:03 -04:00
mSearch = search;
mDescription = description;
mEmail = email;
}
public String getId() {
return mId;
}
@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
@Override
public String getDescription() {
return mDescription;
}
2012-10-16 16:42:51 -04:00
@Override
public void setDescription(String description) {
this.mDescription = description;
2012-10-16 16:42:51 -04:00
}
public LocalSearch getRelatedSearch() {
2012-10-16 16:42:51 -04:00
return mSearch;
}
2012-10-16 16:42:51 -04:00
/*
* This will only be used when accessed as an Account. If that
2012-10-16 16:42:51 -04:00
* is the case we don't want to return the uuid of a real account since
* this is posing as a fake meta-account. If this object is accesed as
2012-10-16 16:42:51 -04:00
* a Search then methods from LocalSearch will be called which do handle
* things nice.
*/
2012-10-17 14:52:03 -04:00
@Override
public String getUuid() {
2012-10-17 14:52:03 -04:00
if (mFakeUuid == null) {
2012-10-16 16:42:51 -04:00
mFakeUuid = UUID.randomUUID().toString();
}
return mFakeUuid;
}
}