aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java113
1 files changed, 64 insertions, 49 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index fd580649..ea6c0187 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -41,25 +41,70 @@ public class Account extends AbstractEntity {
public static final int OPTION_REGISTER = 2;
public static final int OPTION_USECOMPRESSION = 3;
- public static final int STATUS_CONNECTING = 0;
- public static final int STATUS_DISABLED = -2;
- public static final int STATUS_OFFLINE = -1;
- public static final int STATUS_ONLINE = 1;
- public static final int STATUS_NO_INTERNET = 2;
- public static final int STATUS_UNAUTHORIZED = 3;
- public static final int STATUS_SERVER_NOT_FOUND = 5;
-
- public static final int STATUS_REGISTRATION_FAILED = 7;
- public static final int STATUS_REGISTRATION_CONFLICT = 8;
- public static final int STATUS_REGISTRATION_SUCCESSFULL = 9;
- public static final int STATUS_REGISTRATION_NOT_SUPPORTED = 10;
+ public static enum State {
+ DISABLED,
+ OFFLINE,
+ CONNECTING,
+ ONLINE,
+ NO_INTERNET,
+ UNAUTHORIZED(true),
+ SERVER_NOT_FOUND(true),
+ REGISTRATION_FAILED(true),
+ REGISTRATION_CONFLICT(true),
+ REGISTRATION_SUCCESSFUL,
+ REGISTRATION_NOT_SUPPORTED(true);
+
+ private boolean isError;
+
+ public boolean isError() {
+ return this.isError;
+ }
+
+ private State(final boolean isError) {
+ this.isError = isError;
+ }
+
+ private State() {
+ this(false);
+ }
+
+ public int getReadableId() {
+ switch (this) {
+ case DISABLED:
+ return R.string.account_status_disabled;
+ case ONLINE:
+ return R.string.account_status_online;
+ case CONNECTING:
+ return R.string.account_status_connecting;
+ case OFFLINE:
+ return R.string.account_status_offline;
+ case UNAUTHORIZED:
+ return R.string.account_status_unauthorized;
+ case SERVER_NOT_FOUND:
+ return R.string.account_status_not_found;
+ case NO_INTERNET:
+ return R.string.account_status_no_internet;
+ case REGISTRATION_FAILED:
+ return R.string.account_status_regis_fail;
+ case REGISTRATION_CONFLICT:
+ return R.string.account_status_regis_conflict;
+ case REGISTRATION_SUCCESSFUL:
+ return R.string.account_status_regis_success;
+ case REGISTRATION_NOT_SUPPORTED:
+ return R.string.account_status_regis_not_sup;
+ default:
+ return R.string.account_status_unknown;
+ }
+ }
+ }
+
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<>();
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<>();
protected Jid jid;
protected String password;
protected int options = 0;
protected String rosterVersion;
- protected int status = -1;
+ protected State status = State.OFFLINE;
protected JSONObject keys = new JSONObject();
protected String avatar;
protected boolean online = false;
@@ -151,28 +196,24 @@ public class Account extends AbstractEntity {
this.password = password;
}
- public int getStatus() {
+ public State getStatus() {
if (isOptionSet(OPTION_DISABLED)) {
- return STATUS_DISABLED;
+ return State.DISABLED;
} else {
return this.status;
}
}
- public void setStatus(final int status) {
+ public void setStatus(final State status) {
this.status = status;
}
public boolean errorStatus() {
- int s = getStatus();
- return (s == STATUS_REGISTRATION_FAILED
- || s == STATUS_REGISTRATION_CONFLICT
- || s == STATUS_REGISTRATION_NOT_SUPPORTED
- || s == STATUS_SERVER_NOT_FOUND || s == STATUS_UNAUTHORIZED);
+ return getStatus().isError();
}
public boolean hasErrorStatus() {
- return getXmppConnection() != null && getStatus() > STATUS_NO_INTERNET && (getXmppConnection().getAttempt() >= 2);
+ return getXmppConnection() != null && getStatus().isError() && getXmppConnection().getAttempt() >= 2;
}
public String getResource() {
@@ -353,33 +394,7 @@ public class Account extends AbstractEntity {
}
public int getReadableStatusId() {
- switch (getStatus()) {
-
- case Account.STATUS_DISABLED:
- return R.string.account_status_disabled;
- case Account.STATUS_ONLINE:
- return R.string.account_status_online;
- case Account.STATUS_CONNECTING:
- return R.string.account_status_connecting;
- case Account.STATUS_OFFLINE:
- return R.string.account_status_offline;
- case Account.STATUS_UNAUTHORIZED:
- return R.string.account_status_unauthorized;
- case Account.STATUS_SERVER_NOT_FOUND:
- return R.string.account_status_not_found;
- case Account.STATUS_NO_INTERNET:
- return R.string.account_status_no_internet;
- case Account.STATUS_REGISTRATION_FAILED:
- return R.string.account_status_regis_fail;
- case Account.STATUS_REGISTRATION_CONFLICT:
- return R.string.account_status_regis_conflict;
- case Account.STATUS_REGISTRATION_SUCCESSFULL:
- return R.string.account_status_regis_success;
- case Account.STATUS_REGISTRATION_NOT_SUPPORTED:
- return R.string.account_status_regis_not_sup;
- default:
- return R.string.account_status_unknown;
- }
+ return this.getStatus().getReadableId();
}
public void activateGracePeriod() {