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.
|
|
|
|
|
|
2018-10-29 10:46:49 +00:00
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
2018-08-02 13:33:06 +00:00
|
|
|
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
|
2018-10-29 10:46:49 +00:00
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2021-01-01 08:56:36 +01:00
|
|
|
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
2018-08-02 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
|
2018-12-10 12:26:50 +01:00
|
|
|
import android.app.Notification;
|
|
|
|
|
import android.app.NotificationChannel;
|
2019-05-28 16:55:03 +02:00
|
|
|
import android.app.NotificationChannelGroup;
|
2018-12-10 12:26:50 +01:00
|
|
|
import android.app.NotificationManager;
|
|
|
|
|
import android.content.Context;
|
2020-12-26 16:41:34 +01:00
|
|
|
import android.content.SharedPreferences;
|
2019-06-08 09:34:29 +02:00
|
|
|
import android.os.Build;
|
2018-12-10 12:26:50 +01:00
|
|
|
|
2019-04-17 20:21:44 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2019-06-08 09:34:29 +02:00
|
|
|
import androidx.annotation.RequiresApi;
|
2020-12-26 16:41:34 +01:00
|
|
|
import androidx.preference.PreferenceManager;
|
2019-11-23 13:48:59 +01:00
|
|
|
import androidx.room.ColumnInfo;
|
2019-04-17 20:21:44 +02:00
|
|
|
import androidx.room.Entity;
|
|
|
|
|
import androidx.room.PrimaryKey;
|
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
2019-01-23 18:52:52 +00:00
|
|
|
import java.io.Serializable;
|
2019-05-06 22:34:18 +02:00
|
|
|
import java.text.Collator;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.Locale;
|
2019-02-26 11:05:21 +01:00
|
|
|
import java.util.Objects;
|
2019-01-23 18:52:52 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Entity(
|
|
|
|
|
tableName = EntityAccount.TABLE_NAME,
|
|
|
|
|
indices = {
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-01 07:58:45 +02:00
|
|
|
public class EntityAccount extends EntityOrder implements Serializable {
|
2018-08-02 13:33:06 +00:00
|
|
|
static final String TABLE_NAME = "account";
|
|
|
|
|
|
2019-07-08 19:23:07 +02:00
|
|
|
// https://tools.ietf.org/html/rfc2177
|
2019-12-28 18:36:15 +01:00
|
|
|
static final int DEFAULT_KEEP_ALIVE_INTERVAL = 15; // minutes
|
|
|
|
|
static final int DEFAULT_POLL_INTERVAL = 15; // minutes
|
2020-04-16 17:09:33 +02:00
|
|
|
static final int DEFAULT_MAX_MESSAGES = 100; // POP3
|
2019-03-14 10:47:19 +00:00
|
|
|
|
2019-11-23 13:48:59 +01:00
|
|
|
static final int TYPE_IMAP = 0;
|
|
|
|
|
static final int TYPE_POP = 1;
|
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@PrimaryKey(autoGenerate = true)
|
|
|
|
|
public Long id;
|
2018-12-26 11:34:05 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@NonNull
|
2019-11-23 13:48:59 +01:00
|
|
|
@ColumnInfo(name = "pop")
|
|
|
|
|
public Integer protocol = TYPE_IMAP;
|
2019-02-09 21:03:53 +00:00
|
|
|
@NonNull
|
|
|
|
|
public String host; // POP3/IMAP
|
2018-08-02 13:33:06 +00:00
|
|
|
@NonNull
|
2020-08-23 09:28:10 +02:00
|
|
|
@ColumnInfo(name = "starttls")
|
|
|
|
|
public Integer encryption;
|
2018-10-23 07:52:20 +00:00
|
|
|
@NonNull
|
2019-09-18 16:34:07 +02:00
|
|
|
public Boolean insecure = false;
|
2018-10-23 07:52:20 +00:00
|
|
|
@NonNull
|
2018-08-02 13:33:06 +00:00
|
|
|
public Integer port;
|
|
|
|
|
@NonNull
|
2019-12-07 15:14:35 +01:00
|
|
|
public Integer auth_type; // immutable
|
2019-12-21 16:03:57 +01:00
|
|
|
public String provider;
|
2019-09-18 16:34:07 +02:00
|
|
|
@NonNull
|
2018-08-02 13:33:06 +00:00
|
|
|
public String user;
|
|
|
|
|
@NonNull
|
|
|
|
|
public String password;
|
2020-02-09 13:58:16 +01:00
|
|
|
@NonNull
|
2020-02-10 17:16:06 +01:00
|
|
|
public Boolean certificate = false; // obsolete
|
2020-02-10 16:35:14 +01:00
|
|
|
public String certificate_alias;
|
2019-01-10 18:24:20 +00:00
|
|
|
public String realm;
|
2019-12-16 19:09:49 +01:00
|
|
|
public String fingerprint;
|
2018-12-26 11:34:05 +00:00
|
|
|
|
|
|
|
|
public String name;
|
|
|
|
|
public String signature; // obsolete
|
|
|
|
|
public Integer color;
|
|
|
|
|
|
2018-08-27 14:31:45 +00:00
|
|
|
@NonNull
|
2018-08-02 13:33:06 +00:00
|
|
|
public Boolean synchronize;
|
2018-10-07 06:53:09 +00:00
|
|
|
@NonNull
|
2019-12-08 15:00:15 +01:00
|
|
|
public Boolean ondemand = false;
|
2019-02-17 18:29:00 +00:00
|
|
|
@NonNull
|
2020-01-12 18:48:26 +01:00
|
|
|
public Boolean poll_exempted = false;
|
|
|
|
|
@NonNull
|
2018-10-07 06:53:09 +00:00
|
|
|
public Boolean primary;
|
2018-12-23 18:20:08 +00:00
|
|
|
@NonNull
|
2019-09-18 16:34:07 +02:00
|
|
|
public Boolean notify = false;
|
2018-11-24 09:26:34 +01:00
|
|
|
@NonNull
|
2020-01-21 15:15:48 +01:00
|
|
|
public Boolean browse = true;
|
|
|
|
|
@NonNull
|
|
|
|
|
public Boolean leave_on_server = true;
|
|
|
|
|
@NonNull
|
2020-03-24 08:43:31 +01:00
|
|
|
public Boolean leave_deleted = false;
|
|
|
|
|
@NonNull
|
2020-01-21 15:15:48 +01:00
|
|
|
public Boolean leave_on_device = false;
|
2020-02-26 13:16:09 +01:00
|
|
|
public Integer max_messages; // POP3
|
2019-09-23 15:58:53 +02:00
|
|
|
@NonNull
|
|
|
|
|
public Boolean auto_seen = true;
|
2019-06-26 08:13:39 +02:00
|
|
|
public Character separator;
|
2019-01-20 15:22:21 +00:00
|
|
|
public Long swipe_left;
|
|
|
|
|
public Long swipe_right;
|
2019-10-23 12:51:20 +02:00
|
|
|
public Long move_to;
|
2018-12-26 11:34:05 +00:00
|
|
|
@NonNull
|
2019-12-28 20:35:41 +01:00
|
|
|
public Integer poll_interval = DEFAULT_KEEP_ALIVE_INTERVAL;
|
|
|
|
|
@NonNull
|
|
|
|
|
public Boolean keep_alive_ok = false;
|
|
|
|
|
@NonNull
|
|
|
|
|
public Integer keep_alive_failed = 0;
|
2019-06-14 18:29:17 +02:00
|
|
|
@NonNull
|
2020-04-01 08:57:27 +02:00
|
|
|
public Integer keep_alive_succeeded = 0;
|
|
|
|
|
@NonNull
|
2019-06-14 18:29:17 +02:00
|
|
|
public Boolean partial_fetch = true;
|
2019-10-09 14:01:26 +02:00
|
|
|
@NonNull
|
|
|
|
|
public Boolean ignore_size = false;
|
2019-12-01 14:18:24 +01:00
|
|
|
@NonNull
|
2020-07-22 14:57:47 +02:00
|
|
|
public Boolean use_date = false; // Date header
|
|
|
|
|
@NonNull
|
|
|
|
|
public Boolean use_received = false; // Received header
|
2019-05-28 13:42:19 +02:00
|
|
|
public String prefix; // namespace, obsolete
|
2018-12-26 11:34:05 +00:00
|
|
|
|
2020-01-07 17:43:27 +01:00
|
|
|
public Long quota_usage;
|
|
|
|
|
public Long quota_limit;
|
|
|
|
|
|
2018-11-06 16:45:52 +00:00
|
|
|
public Long created;
|
2018-12-06 13:43:00 +01:00
|
|
|
public Boolean tbd;
|
2020-03-08 11:08:28 +01:00
|
|
|
public Long thread;
|
2018-08-13 14:44:47 +00:00
|
|
|
public String state;
|
2019-03-27 08:19:11 +00:00
|
|
|
public String warning;
|
2018-08-11 08:28:54 +00:00
|
|
|
public String error;
|
2018-11-19 14:14:02 +01:00
|
|
|
public Long last_connected;
|
2020-10-29 20:03:09 +01:00
|
|
|
public Long backoff_until;
|
2020-07-03 09:57:43 +02:00
|
|
|
public Long max_size;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2020-04-26 18:02:18 +02:00
|
|
|
boolean isGmail() {
|
|
|
|
|
return "imap.gmail.com".equalsIgnoreCase(host);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-26 16:41:34 +01:00
|
|
|
boolean isTransient(Context context) {
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
boolean enabled = prefs.getBoolean("enabled", true);
|
2020-12-27 16:35:48 +01:00
|
|
|
int pollInterval = prefs.getInt("poll_interval", ServiceSynchronize.DEFAULT_POLL_INTERVAL);
|
2020-12-26 16:41:34 +01:00
|
|
|
return (!enabled || this.ondemand || (pollInterval > 0 && !this.poll_exempted));
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 21:03:53 +00:00
|
|
|
String getProtocol() {
|
2019-11-23 13:48:59 +01:00
|
|
|
switch (protocol) {
|
|
|
|
|
case TYPE_IMAP:
|
2020-05-01 21:47:59 +02:00
|
|
|
if (isGmail())
|
|
|
|
|
return "gimaps";
|
|
|
|
|
else
|
2020-08-23 09:28:10 +02:00
|
|
|
return "imap" + (encryption == EmailService.ENCRYPTION_SSL ? "s" : "");
|
2019-11-23 13:48:59 +01:00
|
|
|
case TYPE_POP:
|
2020-08-23 09:28:10 +02:00
|
|
|
return "pop3" + (encryption == EmailService.ENCRYPTION_SSL ? "s" : "");
|
2019-11-23 13:48:59 +01:00
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("Unknown protocol=" + protocol);
|
|
|
|
|
}
|
2019-02-09 21:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 09:08:06 +02:00
|
|
|
static String getNotificationChannelId(long id) {
|
|
|
|
|
return "notification" + (id == 0 ? "" : "." + id);
|
2018-12-10 12:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-08 09:34:29 +02:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
2018-12-10 12:26:50 +01:00
|
|
|
void createNotificationChannel(Context context) {
|
2019-06-08 09:34:29 +02:00
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
|
2019-06-08 09:51:00 +02:00
|
|
|
NotificationChannelGroup group = new NotificationChannelGroup("group." + id, name);
|
2019-06-08 09:34:29 +02:00
|
|
|
nm.createNotificationChannelGroup(group);
|
|
|
|
|
|
|
|
|
|
NotificationChannel channel = new NotificationChannel(
|
|
|
|
|
getNotificationChannelId(id), name,
|
|
|
|
|
NotificationManager.IMPORTANCE_HIGH);
|
2019-06-08 09:51:00 +02:00
|
|
|
channel.setGroup(group.getId());
|
2019-06-08 09:34:29 +02:00
|
|
|
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
|
|
|
|
channel.enableLights(true);
|
|
|
|
|
nm.createNotificationChannel(channel);
|
2018-12-10 12:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-08 09:34:29 +02:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
2018-12-10 12:26:50 +01:00
|
|
|
void deleteNotificationChannel(Context context) {
|
2019-06-08 09:34:29 +02:00
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
nm.deleteNotificationChannel(getNotificationChannelId(id));
|
2018-12-10 12:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-01 07:58:45 +02:00
|
|
|
@Override
|
|
|
|
|
Long getSortId() {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-01 13:08:15 +02:00
|
|
|
@Override
|
|
|
|
|
String[] getSortTitle(Context context) {
|
|
|
|
|
return new String[]{name, null};
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
public JSONObject toJSON() throws JSONException {
|
|
|
|
|
JSONObject json = new JSONObject();
|
2019-02-07 08:29:39 +00:00
|
|
|
json.put("id", id);
|
2019-06-13 22:08:43 +02:00
|
|
|
json.put("order", order);
|
2019-11-23 13:48:59 +01:00
|
|
|
json.put("protocol", protocol);
|
2018-09-14 11:33:22 +00:00
|
|
|
json.put("host", host);
|
2020-08-23 09:28:10 +02:00
|
|
|
json.put("encryption", encryption);
|
2018-10-24 11:14:56 +00:00
|
|
|
json.put("insecure", insecure);
|
2018-09-14 11:33:22 +00:00
|
|
|
json.put("port", port);
|
2019-09-18 16:34:07 +02:00
|
|
|
json.put("auth_type", auth_type);
|
2020-01-13 08:51:37 +01:00
|
|
|
json.put("provider", provider);
|
2018-09-14 11:33:22 +00:00
|
|
|
json.put("user", user);
|
2019-03-11 14:19:33 +00:00
|
|
|
json.put("password", password);
|
2020-02-10 16:35:14 +01:00
|
|
|
json.put("certificate_alias", certificate_alias);
|
2019-02-17 11:34:29 +00:00
|
|
|
json.put("realm", realm);
|
2020-01-13 08:51:37 +01:00
|
|
|
json.put("fingerprint", fingerprint);
|
2019-02-02 19:49:25 +00:00
|
|
|
|
|
|
|
|
json.put("name", name);
|
|
|
|
|
json.put("color", color);
|
|
|
|
|
|
2018-11-14 20:00:38 +01:00
|
|
|
json.put("synchronize", synchronize);
|
2019-12-10 20:37:12 +01:00
|
|
|
json.put("ondemand", ondemand);
|
2020-01-13 08:51:37 +01:00
|
|
|
json.put("poll_exempted", poll_exempted);
|
2018-10-07 08:08:01 +00:00
|
|
|
json.put("primary", primary);
|
2019-02-02 19:49:25 +00:00
|
|
|
json.put("notify", notify);
|
2018-12-23 18:20:08 +00:00
|
|
|
json.put("browse", browse);
|
2020-01-21 15:15:48 +01:00
|
|
|
json.put("leave_on_server", leave_on_server);
|
2020-05-03 11:24:20 +02:00
|
|
|
json.put("leave_deleted", leave_deleted);
|
2020-01-21 15:15:48 +01:00
|
|
|
json.put("leave_on_device", leave_on_device);
|
2020-04-16 15:54:10 +02:00
|
|
|
json.put("max_messages", max_messages);
|
2019-09-23 17:39:45 +02:00
|
|
|
json.put("auto_seen", auto_seen);
|
|
|
|
|
// not separator
|
2019-02-02 19:49:25 +00:00
|
|
|
|
2019-01-20 15:22:21 +00:00
|
|
|
json.put("swipe_left", swipe_left);
|
|
|
|
|
json.put("swipe_right", swipe_right);
|
2019-02-02 19:49:25 +00:00
|
|
|
|
2019-10-23 15:29:22 +02:00
|
|
|
json.put("move_to", move_to);
|
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
json.put("poll_interval", poll_interval);
|
2019-06-14 18:29:17 +02:00
|
|
|
json.put("partial_fetch", partial_fetch);
|
2019-10-09 14:01:26 +02:00
|
|
|
json.put("ignore_size", ignore_size);
|
2020-01-13 08:51:37 +01:00
|
|
|
json.put("use_date", use_date);
|
2020-07-22 14:57:47 +02:00
|
|
|
json.put("use_received", use_received);
|
2019-09-23 17:39:45 +02:00
|
|
|
// not prefix
|
2018-11-10 10:45:03 +00:00
|
|
|
// not created
|
2019-09-23 17:39:45 +02:00
|
|
|
// not tbd
|
2018-11-10 10:45:03 +00:00
|
|
|
// not state
|
2019-09-23 17:39:45 +02:00
|
|
|
// not warning
|
2018-11-10 10:45:03 +00:00
|
|
|
// not error
|
2018-11-19 14:14:02 +01:00
|
|
|
// not last connected
|
2018-09-14 11:33:22 +00:00
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static EntityAccount fromJSON(JSONObject json) throws JSONException {
|
|
|
|
|
EntityAccount account = new EntityAccount();
|
2019-07-29 20:05:23 +02:00
|
|
|
if (json.has("id"))
|
|
|
|
|
account.id = json.getLong("id");
|
2019-06-13 22:08:43 +02:00
|
|
|
|
|
|
|
|
if (json.has("order"))
|
|
|
|
|
account.order = json.getInt("order");
|
|
|
|
|
|
2019-11-23 13:48:59 +01:00
|
|
|
if (json.has("protocol"))
|
|
|
|
|
account.protocol = json.getInt("protocol");
|
|
|
|
|
else if (json.has("pop"))
|
|
|
|
|
account.protocol = (json.getBoolean("pop") ? TYPE_POP : TYPE_IMAP);
|
2019-09-19 17:41:26 +02:00
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
account.host = json.getString("host");
|
2020-08-23 09:28:10 +02:00
|
|
|
if (json.has("starttls"))
|
|
|
|
|
account.encryption = (json.getBoolean("starttls")
|
|
|
|
|
? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL);
|
|
|
|
|
else
|
|
|
|
|
account.encryption = json.getInt("encryption");
|
2018-10-24 11:14:56 +00:00
|
|
|
account.insecure = (json.has("insecure") && json.getBoolean("insecure"));
|
2018-09-14 11:33:22 +00:00
|
|
|
account.port = json.getInt("port");
|
2019-09-18 16:34:07 +02:00
|
|
|
account.auth_type = json.getInt("auth_type");
|
2020-01-13 08:51:37 +01:00
|
|
|
if (json.has("provider"))
|
|
|
|
|
account.provider = json.getString("provider");
|
2018-09-14 11:33:22 +00:00
|
|
|
account.user = json.getString("user");
|
2019-03-11 14:19:33 +00:00
|
|
|
account.password = json.getString("password");
|
2020-02-11 08:10:01 +01:00
|
|
|
if (json.has("certificate_alias"))
|
|
|
|
|
account.certificate_alias = json.getString("certificate_alias");
|
2019-02-02 19:49:25 +00:00
|
|
|
if (json.has("realm"))
|
|
|
|
|
account.realm = json.getString("realm");
|
2020-01-13 08:51:37 +01:00
|
|
|
if (json.has("fingerprint"))
|
|
|
|
|
account.fingerprint = json.getString("fingerprint");
|
2019-02-02 19:49:25 +00:00
|
|
|
|
2019-03-14 17:52:15 +00:00
|
|
|
if (json.has("name") && !json.isNull("name"))
|
2019-02-02 19:49:25 +00:00
|
|
|
account.name = json.getString("name");
|
|
|
|
|
if (json.has("color"))
|
|
|
|
|
account.color = json.getInt("color");
|
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
account.synchronize = json.getBoolean("synchronize");
|
2019-12-10 20:37:12 +01:00
|
|
|
if (json.has("ondemand"))
|
|
|
|
|
account.ondemand = json.getBoolean("ondemand");
|
2020-01-13 08:51:37 +01:00
|
|
|
if (json.has("poll_exempted"))
|
|
|
|
|
account.poll_exempted = json.getBoolean("poll_exempted");
|
2018-10-07 08:08:01 +00:00
|
|
|
account.primary = json.getBoolean("primary");
|
2019-02-02 19:49:25 +00:00
|
|
|
if (json.has("notify"))
|
|
|
|
|
account.notify = json.getBoolean("notify");
|
2018-12-23 18:20:08 +00:00
|
|
|
if (json.has("browse"))
|
|
|
|
|
account.browse = json.getBoolean("browse");
|
2020-01-21 15:15:48 +01:00
|
|
|
if (json.has("leave_on_server"))
|
|
|
|
|
account.leave_on_server = json.getBoolean("leave_on_server");
|
2020-05-03 11:24:20 +02:00
|
|
|
if (json.has("leave_deleted"))
|
|
|
|
|
account.leave_deleted = json.getBoolean("leave_deleted");
|
2020-01-21 15:15:48 +01:00
|
|
|
if (json.has("leave_on_device"))
|
|
|
|
|
account.leave_on_device = json.getBoolean("leave_on_device");
|
2020-04-16 15:54:10 +02:00
|
|
|
if (json.has("max_messages"))
|
|
|
|
|
account.max_messages = json.getInt("max_messages");
|
2019-09-23 17:39:45 +02:00
|
|
|
if (json.has("auto_seen"))
|
|
|
|
|
account.auto_seen = json.getBoolean("auto_seen");
|
2019-01-20 15:22:21 +00:00
|
|
|
|
|
|
|
|
if (json.has("swipe_left"))
|
|
|
|
|
account.swipe_left = json.getLong("swipe_left");
|
|
|
|
|
if (json.has("swipe_right"))
|
|
|
|
|
account.swipe_right = json.getLong("swipe_right");
|
|
|
|
|
|
2019-10-23 15:29:22 +02:00
|
|
|
if (json.has("move_to"))
|
|
|
|
|
account.move_to = json.getLong("move_to");
|
|
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
account.poll_interval = json.getInt("poll_interval");
|
2019-02-02 19:49:25 +00:00
|
|
|
|
2019-10-09 14:01:26 +02:00
|
|
|
account.partial_fetch = json.optBoolean("partial_fetch", true);
|
|
|
|
|
account.ignore_size = json.optBoolean("ignore_size", false);
|
2020-01-13 08:51:37 +01:00
|
|
|
account.use_date = json.optBoolean("use_date", false);
|
2020-07-22 14:57:47 +02:00
|
|
|
account.use_received = json.optBoolean("use_received", false);
|
2019-06-14 18:29:17 +02:00
|
|
|
|
2018-09-14 11:33:22 +00:00
|
|
|
return account;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-10 10:45:03 +00:00
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
|
if (obj instanceof EntityAccount) {
|
|
|
|
|
EntityAccount other = (EntityAccount) obj;
|
2019-09-23 17:39:45 +02:00
|
|
|
return (Objects.equals(this.order, other.order) &&
|
2019-11-23 13:48:59 +01:00
|
|
|
this.protocol.equals(other.protocol) &&
|
2019-09-23 17:39:45 +02:00
|
|
|
this.host.equals(other.host) &&
|
2020-08-23 09:28:10 +02:00
|
|
|
this.encryption.equals(other.encryption) &&
|
2018-11-10 10:45:03 +00:00
|
|
|
this.insecure == other.insecure &&
|
|
|
|
|
this.port.equals(other.port) &&
|
2019-09-18 16:34:07 +02:00
|
|
|
this.auth_type.equals(other.auth_type) &&
|
2018-11-10 10:45:03 +00:00
|
|
|
this.user.equals(other.user) &&
|
2019-03-11 14:19:33 +00:00
|
|
|
this.password.equals(other.password) &&
|
2019-02-26 11:05:21 +01:00
|
|
|
Objects.equals(this.realm, other.realm) &&
|
|
|
|
|
Objects.equals(this.name, other.name) &&
|
|
|
|
|
Objects.equals(this.color, other.color) &&
|
2018-11-10 10:45:03 +00:00
|
|
|
this.synchronize.equals(other.synchronize) &&
|
|
|
|
|
this.primary.equals(other.primary) &&
|
2018-11-24 09:26:34 +01:00
|
|
|
this.notify.equals(other.notify) &&
|
2019-01-23 09:16:33 +00:00
|
|
|
this.browse.equals(other.browse) &&
|
2020-01-21 15:15:48 +01:00
|
|
|
this.leave_on_server.equals(other.leave_on_server) &&
|
|
|
|
|
this.leave_on_device.equals(other.leave_on_device) &&
|
2020-04-16 15:54:10 +02:00
|
|
|
Objects.equals(this.max_messages, other.max_messages) &&
|
2019-09-23 17:39:45 +02:00
|
|
|
this.auto_seen.equals(other.auto_seen) &&
|
2019-02-26 11:05:21 +01:00
|
|
|
Objects.equals(this.swipe_left, other.swipe_left) &&
|
|
|
|
|
Objects.equals(this.swipe_right, other.swipe_right) &&
|
2018-11-10 10:45:03 +00:00
|
|
|
this.poll_interval.equals(other.poll_interval) &&
|
2019-06-14 18:29:17 +02:00
|
|
|
this.partial_fetch == other.partial_fetch &&
|
2019-10-09 14:01:26 +02:00
|
|
|
this.ignore_size == other.ignore_size &&
|
2020-07-21 20:47:47 +02:00
|
|
|
this.use_date == other.use_date &&
|
2020-07-22 14:57:47 +02:00
|
|
|
this.use_received == other.use_received &&
|
2020-01-07 17:43:27 +01:00
|
|
|
Objects.equals(this.quota_usage, other.quota_usage) &&
|
|
|
|
|
Objects.equals(this.quota_limit, other.quota_limit) &&
|
2019-02-26 11:05:21 +01:00
|
|
|
Objects.equals(this.created, other.created) &&
|
|
|
|
|
Objects.equals(this.tbd, other.tbd) &&
|
|
|
|
|
Objects.equals(this.state, other.state) &&
|
2019-03-27 08:19:11 +00:00
|
|
|
Objects.equals(this.warning, other.warning) &&
|
2019-02-26 11:05:21 +01:00
|
|
|
Objects.equals(this.error, other.error) &&
|
2020-07-03 09:57:43 +02:00
|
|
|
Objects.equals(this.last_connected, other.last_connected) &&
|
2020-10-29 20:03:09 +01:00
|
|
|
Objects.equals(this.backoff_until, other.backoff_until) &&
|
2020-07-03 09:57:43 +02:00
|
|
|
Objects.equals(this.max_size, other.max_size));
|
2018-11-10 10:45:03 +00:00
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-28 07:40:27 +00:00
|
|
|
|
2019-05-06 22:34:18 +02:00
|
|
|
@Override
|
|
|
|
|
Comparator getComparator(final Context context) {
|
|
|
|
|
final Collator collator = Collator.getInstance(Locale.getDefault());
|
|
|
|
|
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
|
|
|
|
|
|
|
|
|
return new Comparator() {
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(Object o1, Object o2) {
|
|
|
|
|
EntityAccount a1 = (EntityAccount) o1;
|
|
|
|
|
EntityAccount a2 = (EntityAccount) o2;
|
|
|
|
|
|
|
|
|
|
int o = Integer.compare(
|
|
|
|
|
a1.order == null ? -1 : a1.order,
|
|
|
|
|
a2.order == null ? -1 : a2.order);
|
|
|
|
|
if (o != 0)
|
|
|
|
|
return o;
|
|
|
|
|
|
|
|
|
|
String name1 = (a1.name == null ? "" : a1.name);
|
|
|
|
|
String name2 = (a2.name == null ? "" : a2.name);
|
|
|
|
|
return collator.compare(name1, name2);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 07:40:27 +00:00
|
|
|
@NonNull
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return name + (primary ? " ★" : "");
|
|
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|