2018-08-02 13:33:06 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
2018-08-14 05:53:24 +00:00
|
|
|
This file is part of FairEmail.
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-14 05:53:24 +00:00
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
2018-08-02 13:33:06 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
NetGuard is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
2018-08-15 09:50:39 +00:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.room.Entity;
|
|
|
|
import androidx.room.ForeignKey;
|
|
|
|
import androidx.room.Index;
|
|
|
|
import androidx.room.PrimaryKey;
|
|
|
|
|
|
|
|
import static androidx.room.ForeignKey.CASCADE;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
@Entity(
|
|
|
|
tableName = EntityFolder.TABLE_NAME,
|
|
|
|
foreignKeys = {
|
2018-08-08 05:06:54 +00:00
|
|
|
@ForeignKey(childColumns = "account", entity = EntityAccount.class, parentColumns = "id", onDelete = CASCADE)
|
2018-08-02 13:33:06 +00:00
|
|
|
},
|
|
|
|
indices = {
|
2018-08-08 05:06:54 +00:00
|
|
|
@Index(value = {"account", "name"}, unique = true),
|
2018-08-02 13:33:06 +00:00
|
|
|
@Index(value = {"account"}),
|
|
|
|
@Index(value = {"name"}),
|
2018-09-05 09:41:16 +00:00
|
|
|
@Index(value = {"type"}),
|
|
|
|
@Index(value = {"unified"})
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
)
|
2018-09-05 09:41:16 +00:00
|
|
|
|
2018-08-15 09:50:39 +00:00
|
|
|
public class EntityFolder implements Parcelable {
|
2018-08-02 13:33:06 +00:00
|
|
|
static final String TABLE_NAME = "folder";
|
|
|
|
|
2018-08-11 08:28:54 +00:00
|
|
|
@PrimaryKey(autoGenerate = true)
|
|
|
|
public Long id;
|
|
|
|
public Long account; // Outbox = null
|
|
|
|
@NonNull
|
|
|
|
public String name;
|
|
|
|
@NonNull
|
|
|
|
public String type;
|
|
|
|
@NonNull
|
|
|
|
public Boolean synchronize;
|
|
|
|
@NonNull
|
|
|
|
public Integer after; // days
|
2018-09-21 15:19:37 +00:00
|
|
|
public String display;
|
|
|
|
@NonNull
|
|
|
|
public Boolean hide = false;
|
|
|
|
@NonNull
|
|
|
|
public Boolean unified = false;
|
2018-08-13 14:44:47 +00:00
|
|
|
public String state;
|
2018-08-11 08:28:54 +00:00
|
|
|
public String error;
|
|
|
|
|
2018-08-09 07:02:41 +00:00
|
|
|
static final String INBOX = "Inbox";
|
|
|
|
static final String OUTBOX = "Outbox";
|
|
|
|
static final String ARCHIVE = "All";
|
|
|
|
static final String DRAFTS = "Drafts";
|
|
|
|
static final String TRASH = "Trash";
|
|
|
|
static final String JUNK = "Junk";
|
|
|
|
static final String SENT = "Sent";
|
2018-09-16 06:18:33 +00:00
|
|
|
static final String SYSTEM = "System";
|
2018-08-09 07:02:41 +00:00
|
|
|
static final String USER = "User";
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-03 17:09:12 +00:00
|
|
|
static final List<String> SYSTEM_FOLDER_ATTR = Arrays.asList(
|
2018-08-08 05:06:54 +00:00
|
|
|
"All",
|
|
|
|
"Drafts",
|
|
|
|
"Trash",
|
|
|
|
"Junk",
|
2018-09-16 06:18:33 +00:00
|
|
|
"Sent",
|
|
|
|
"Important",
|
|
|
|
"Flagged"
|
2018-08-02 13:33:06 +00:00
|
|
|
);
|
2018-08-03 17:09:12 +00:00
|
|
|
static final List<String> SYSTEM_FOLDER_TYPE = Arrays.asList(
|
2018-08-09 07:02:41 +00:00
|
|
|
ARCHIVE,
|
|
|
|
DRAFTS,
|
|
|
|
TRASH,
|
|
|
|
JUNK,
|
2018-09-16 06:18:33 +00:00
|
|
|
SENT,
|
|
|
|
SYSTEM,
|
|
|
|
SYSTEM
|
2018-08-08 05:06:54 +00:00
|
|
|
); // MUST match SYSTEM_FOLDER_ATTR
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-06 16:01:56 +00:00
|
|
|
static final List<String> FOLDER_SORT_ORDER = Arrays.asList(
|
2018-08-09 07:02:41 +00:00
|
|
|
INBOX,
|
|
|
|
OUTBOX,
|
|
|
|
DRAFTS,
|
|
|
|
SENT,
|
|
|
|
ARCHIVE,
|
|
|
|
TRASH,
|
|
|
|
JUNK,
|
2018-09-16 06:18:33 +00:00
|
|
|
SYSTEM,
|
2018-08-09 07:02:41 +00:00
|
|
|
USER
|
2018-08-06 16:01:56 +00:00
|
|
|
);
|
|
|
|
|
2018-08-08 05:06:54 +00:00
|
|
|
static final int DEFAULT_INBOX_SYNC = 30; // days
|
|
|
|
static final int DEFAULT_SYSTEM_SYNC = 7; // days
|
|
|
|
static final int DEFAULT_USER_SYNC = 7; // days
|
2018-08-06 20:14:11 +00:00
|
|
|
|
|
|
|
static final List<String> SYSTEM_FOLDER_SYNC = Arrays.asList(
|
2018-08-09 07:02:41 +00:00
|
|
|
ARCHIVE,
|
|
|
|
DRAFTS,
|
|
|
|
TRASH,
|
|
|
|
SENT
|
2018-08-06 20:14:11 +00:00
|
|
|
);
|
|
|
|
|
2018-08-15 09:50:39 +00:00
|
|
|
public EntityFolder() {
|
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj instanceof EntityFolder) {
|
|
|
|
EntityFolder other = (EntityFolder) obj;
|
2018-08-15 19:34:22 +00:00
|
|
|
return (this.id.equals(other.id) &&
|
|
|
|
(this.account == null ? other.account == null : this.account.equals(other.account)) &&
|
2018-08-02 13:33:06 +00:00
|
|
|
this.name.equals(other.name) &&
|
|
|
|
this.type.equals(other.type) &&
|
|
|
|
this.synchronize.equals(other.synchronize) &&
|
2018-08-11 08:28:54 +00:00
|
|
|
this.after.equals(other.after) &&
|
2018-09-21 15:19:37 +00:00
|
|
|
(this.display == null ? other.display == null : this.display.equals(other.display)) &&
|
|
|
|
this.hide == other.hide &&
|
|
|
|
this.unified == other.unified &&
|
2018-08-13 14:44:47 +00:00
|
|
|
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
|
2018-08-11 08:28:54 +00:00
|
|
|
(this.error == null ? other.error == null : this.error.equals(other.error)));
|
2018-08-02 13:33:06 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-10 09:45:36 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return name;
|
|
|
|
}
|
2018-08-15 09:50:39 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
|
|
if (id == null) {
|
|
|
|
parcel.writeByte((byte) 0);
|
|
|
|
} else {
|
|
|
|
parcel.writeByte((byte) 1);
|
|
|
|
parcel.writeLong(id);
|
|
|
|
}
|
|
|
|
if (account == null) {
|
|
|
|
parcel.writeByte((byte) 0);
|
|
|
|
} else {
|
|
|
|
parcel.writeByte((byte) 1);
|
|
|
|
parcel.writeLong(account);
|
|
|
|
}
|
|
|
|
parcel.writeString(name);
|
|
|
|
parcel.writeString(type);
|
|
|
|
parcel.writeByte((byte) (synchronize == null ? 0 : synchronize ? 1 : 2));
|
|
|
|
if (after == null) {
|
|
|
|
parcel.writeByte((byte) 0);
|
|
|
|
} else {
|
|
|
|
parcel.writeByte((byte) 1);
|
|
|
|
parcel.writeInt(after);
|
|
|
|
}
|
|
|
|
parcel.writeString(state);
|
|
|
|
parcel.writeString(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected EntityFolder(Parcel in) {
|
|
|
|
if (in.readByte() == 0) {
|
|
|
|
id = null;
|
|
|
|
} else {
|
|
|
|
id = in.readLong();
|
|
|
|
}
|
|
|
|
if (in.readByte() == 0) {
|
|
|
|
account = null;
|
|
|
|
} else {
|
|
|
|
account = in.readLong();
|
|
|
|
}
|
|
|
|
name = in.readString();
|
|
|
|
type = in.readString();
|
|
|
|
byte tmpSynchronize = in.readByte();
|
|
|
|
synchronize = tmpSynchronize == 0 ? null : tmpSynchronize == 1;
|
|
|
|
if (in.readByte() == 0) {
|
|
|
|
after = null;
|
|
|
|
} else {
|
|
|
|
after = in.readInt();
|
|
|
|
}
|
|
|
|
state = in.readString();
|
|
|
|
error = in.readString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final Creator<EntityFolder> CREATOR = new Creator<EntityFolder>() {
|
|
|
|
@Override
|
|
|
|
public EntityFolder createFromParcel(Parcel in) {
|
|
|
|
return new EntityFolder(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EntityFolder[] newArray(int size) {
|
|
|
|
return new EntityFolder[size];
|
|
|
|
}
|
|
|
|
};
|
2018-09-14 11:33:22 +00:00
|
|
|
|
|
|
|
public JSONObject toJSON() throws JSONException {
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
json.put("name", name);
|
|
|
|
json.put("type", type);
|
|
|
|
json.put("unified", unified);
|
|
|
|
json.put("synchronize", synchronize);
|
|
|
|
json.put("after", after);
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static EntityFolder fromJSON(JSONObject json) throws JSONException {
|
|
|
|
EntityFolder folder = new EntityFolder();
|
|
|
|
folder.name = json.getString("name");
|
|
|
|
folder.type = json.getString("type");
|
|
|
|
folder.unified = json.getBoolean("unified");
|
|
|
|
folder.synchronize = json.getBoolean("synchronize");
|
|
|
|
folder.after = json.getInt("after");
|
|
|
|
return folder;
|
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|