2012-10-12 06:30:26 -04:00
|
|
|
package com.fsck.k9.search;
|
2010-04-21 22:20:35 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
public interface SearchSpecification extends Parcelable {
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the uuids of accounts this search acts on.
|
|
|
|
* @return Array of uuids.
|
|
|
|
*/
|
2012-10-12 07:22:54 -04:00
|
|
|
public String[] getAccountUuids();
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
/**
|
|
|
|
* Returns the search's name if it was named.
|
|
|
|
* @return Name of the search.
|
|
|
|
*/
|
2012-10-16 16:42:51 -04:00
|
|
|
public String getName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the root node of the condition tree accompanying
|
|
|
|
* the search.
|
|
|
|
*
|
|
|
|
* @return Root node of conditions tree.
|
|
|
|
*/
|
|
|
|
public ConditionsTreeNode getConditions();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some meta names for certain conditions.
|
|
|
|
*/
|
2012-10-12 07:22:54 -04:00
|
|
|
public static final String ALL_ACCOUNTS = "allAccounts";
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// ATTRIBUTE enum
|
|
|
|
///////////////////////////////////////////////////////////////
|
2012-10-17 14:52:03 -04:00
|
|
|
public enum Attribute {
|
2012-10-28 21:27:34 -04:00
|
|
|
CONTAINS,
|
|
|
|
NOT_CONTAINS,
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-28 21:27:34 -04:00
|
|
|
EQUALS,
|
|
|
|
NOT_EQUALS,
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-28 21:27:34 -04:00
|
|
|
STARTSWITH,
|
|
|
|
NOT_STARTSWITH,
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-28 21:27:34 -04:00
|
|
|
ENDSWITH,
|
|
|
|
NOT_ENDSWITH
|
2012-10-17 14:52:03 -04:00
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// SEARCHFIELD enum
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
/*
|
|
|
|
* Using an enum in order to have more robust code. Users ( & coders )
|
|
|
|
* are prevented from passing illegal fields. No database overhead
|
2012-10-12 07:22:54 -04:00
|
|
|
* when invalid fields passed.
|
|
|
|
*
|
|
|
|
* By result, only the fields in here are searchable.
|
|
|
|
*
|
|
|
|
* Fields not in here at this moment ( and by effect not searchable ):
|
2014-09-14 05:18:57 -04:00
|
|
|
* id, html_content, internal_date, message_id,
|
|
|
|
* preview, mime_type
|
2012-10-16 16:42:51 -04:00
|
|
|
*
|
2012-10-12 07:22:54 -04:00
|
|
|
*/
|
2012-10-17 14:52:03 -04:00
|
|
|
public enum Searchfield {
|
2012-10-28 21:27:34 -04:00
|
|
|
SUBJECT,
|
|
|
|
DATE,
|
|
|
|
UID,
|
|
|
|
FLAG,
|
|
|
|
SENDER,
|
|
|
|
TO,
|
|
|
|
CC,
|
|
|
|
FOLDER,
|
|
|
|
BCC,
|
|
|
|
REPLY_TO,
|
|
|
|
MESSAGE_CONTENTS,
|
|
|
|
ATTACHMENT_COUNT,
|
|
|
|
DELETED,
|
2013-01-10 21:40:35 -05:00
|
|
|
THREAD_ID,
|
2012-10-30 20:45:44 -04:00
|
|
|
ID,
|
2012-12-03 23:13:58 -05:00
|
|
|
INTEGRATE,
|
|
|
|
READ,
|
2012-12-07 06:03:04 -05:00
|
|
|
FLAGGED,
|
2012-12-07 06:55:32 -05:00
|
|
|
DISPLAY_CLASS,
|
|
|
|
SEARCHABLE
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2012-10-16 16:42:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// SearchCondition class
|
|
|
|
///////////////////////////////////////////////////////////////
|
2012-10-12 07:22:54 -04:00
|
|
|
/**
|
|
|
|
* This class represents 1 value for a certain search field. One
|
2012-10-16 16:42:51 -04:00
|
|
|
* value consists of three things:
|
2014-09-14 05:18:57 -04:00
|
|
|
* an attribute: equals, starts with, contains,...
|
|
|
|
* a searchfield: date, flags, sender, subject,...
|
|
|
|
* a value: "apple", "jesse",..
|
2012-10-16 16:42:51 -04:00
|
|
|
*
|
2012-10-12 07:22:54 -04:00
|
|
|
* @author dzan
|
|
|
|
*/
|
2012-10-17 14:52:03 -04:00
|
|
|
public class SearchCondition implements Parcelable {
|
2012-10-28 21:27:34 -04:00
|
|
|
public final String value;
|
|
|
|
public final Attribute attribute;
|
|
|
|
public final Searchfield field;
|
2012-10-16 16:42:51 -04:00
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
public SearchCondition(Searchfield field, Attribute attribute, String value) {
|
2012-10-12 07:22:54 -04:00
|
|
|
this.value = value;
|
|
|
|
this.attribute = attribute;
|
|
|
|
this.field = field;
|
|
|
|
}
|
2010-04-21 22:20:35 -04:00
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
private SearchCondition(Parcel in) {
|
2012-10-16 16:42:51 -04:00
|
|
|
this.value = in.readString();
|
2012-10-17 14:52:03 -04:00
|
|
|
this.attribute = Attribute.values()[in.readInt()];
|
|
|
|
this.field = Searchfield.values()[in.readInt()];
|
2012-10-16 16:42:51 -04:00
|
|
|
}
|
|
|
|
|
2012-10-26 22:48:37 -04:00
|
|
|
@Override
|
|
|
|
public SearchCondition clone() {
|
|
|
|
return new SearchCondition(field, attribute, value);
|
|
|
|
}
|
|
|
|
|
2012-10-16 16:42:51 -04:00
|
|
|
public String toHumanString() {
|
|
|
|
return field.toString() + attribute.toString();
|
|
|
|
}
|
|
|
|
|
2012-10-12 07:22:54 -04:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (o instanceof SearchCondition) {
|
|
|
|
SearchCondition tmp = (SearchCondition) o;
|
2012-10-17 14:52:03 -04:00
|
|
|
if (tmp.attribute == attribute &&
|
|
|
|
tmp.field == field &&
|
|
|
|
tmp.value.equals(value)) {
|
2012-10-12 07:22:54 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-10-17 14:52:03 -04:00
|
|
|
|
|
|
|
return false;
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2015-01-02 20:46:36 -05:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int result = 1;
|
|
|
|
result = 31 * result + attribute.hashCode();
|
|
|
|
result = 31 * result + field.hashCode();
|
|
|
|
result = 31 * result + value.hashCode();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-16 16:42:51 -04:00
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeString(value);
|
|
|
|
dest.writeInt(attribute.ordinal());
|
|
|
|
dest.writeInt(field.ordinal());
|
|
|
|
}
|
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
public static final Parcelable.Creator<SearchCondition> CREATOR =
|
|
|
|
new Parcelable.Creator<SearchCondition>() {
|
|
|
|
|
|
|
|
@Override
|
2012-10-16 16:42:51 -04:00
|
|
|
public SearchCondition createFromParcel(Parcel in) {
|
|
|
|
return new SearchCondition(in);
|
|
|
|
}
|
|
|
|
|
2012-10-17 14:52:03 -04:00
|
|
|
@Override
|
2012-10-16 16:42:51 -04:00
|
|
|
public SearchCondition[] newArray(int size) {
|
|
|
|
return new SearchCondition[size];
|
|
|
|
}
|
|
|
|
};
|
2012-10-12 07:22:54 -04:00
|
|
|
}
|
2015-01-02 20:46:36 -05:00
|
|
|
}
|