diff options
author | Sam Whited <sam@samwhited.com> | 2014-11-15 11:09:02 -0500 |
---|---|---|
committer | Sam Whited <sam@samwhited.com> | 2014-11-15 11:12:41 -0500 |
commit | d94b07c916757b351c5d85762b9441ad5e7354f0 (patch) | |
tree | 6fbb06dc80a708a30f9efe8b5353d42a4204aed6 /src/main/java/eu/siacs/conversations/xmpp | |
parent | 847877f9d2954130a73860118cb7b6fe073aafe8 (diff) |
Make account status an enum
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xmpp')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 50 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java | 2 |
2 files changed, 26 insertions, 26 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 24e42c7b..16ef1b50 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -120,15 +120,15 @@ public class XmppConnection implements Runnable { applicationContext = service.getApplicationContext(); } - protected void changeStatus(int nextStatus) { + protected void changeStatus(final Account.State nextStatus) { if (account.getStatus() != nextStatus) { - if ((nextStatus == Account.STATUS_OFFLINE) - && (account.getStatus() != Account.STATUS_CONNECTING) - && (account.getStatus() != Account.STATUS_ONLINE) - && (account.getStatus() != Account.STATUS_DISABLED)) { + if ((nextStatus == Account.State.OFFLINE) + && (account.getStatus() != Account.State.CONNECTING) + && (account.getStatus() != Account.State.ONLINE) + && (account.getStatus() != Account.State.DISABLED)) { return; - } - if (nextStatus == Account.STATUS_ONLINE) { + } + if (nextStatus == Account.State.ONLINE) { this.attempt = 0; } account.setStatus(nextStatus); @@ -151,12 +151,12 @@ public class XmppConnection implements Runnable { tagReader = new XmlReader(wakeLock); tagWriter = new TagWriter(); packetCallbacks.clear(); - this.changeStatus(Account.STATUS_CONNECTING); + this.changeStatus(Account.State.CONNECTING); Bundle result = DNSHelper.getSRVRecord(account.getServer()); ArrayList<Parcelable> values = result.getParcelableArrayList("values"); if ("timeout".equals(result.getString("error"))) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": dns timeout"); - this.changeStatus(Account.STATUS_OFFLINE); + this.changeStatus(Account.State.OFFLINE); return; } else if (values != null) { int i = 0; @@ -197,7 +197,7 @@ public class XmppConnection implements Runnable { } } if (socketError) { - this.changeStatus(Account.STATUS_SERVER_NOT_FOUND); + this.changeStatus(Account.State.SERVER_NOT_FOUND); if (wakeLock.isHeld()) { try { wakeLock.release(); @@ -212,7 +212,7 @@ public class XmppConnection implements Runnable { } else { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": timeout in DNS resolution"); - changeStatus(Account.STATUS_OFFLINE); + changeStatus(Account.State.OFFLINE); return; } OutputStream out = socket.getOutputStream(); @@ -236,7 +236,7 @@ public class XmppConnection implements Runnable { socket.close(); } } catch (UnknownHostException e) { - this.changeStatus(Account.STATUS_SERVER_NOT_FOUND); + this.changeStatus(Account.State.SERVER_NOT_FOUND); if (wakeLock.isHeld()) { try { wakeLock.release(); @@ -245,7 +245,7 @@ public class XmppConnection implements Runnable { } } catch (final IOException | XmlPullParserException e) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); - this.changeStatus(Account.STATUS_OFFLINE); + this.changeStatus(Account.State.OFFLINE); if (wakeLock.isHeld()) { try { wakeLock.release(); @@ -254,7 +254,7 @@ public class XmppConnection implements Runnable { } } catch (NoSuchAlgorithmException e) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); - this.changeStatus(Account.STATUS_OFFLINE); + this.changeStatus(Account.State.OFFLINE); Log.d(Config.LOGTAG, "compression exception " + e.getMessage()); if (wakeLock.isHeld()) { try { @@ -294,14 +294,14 @@ public class XmppConnection implements Runnable { } Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": logged in"); account.setKey(Account.PINNED_MECHANISM_KEY, - String.valueOf(saslMechanism.getPriority())); + String.valueOf(saslMechanism.getPriority())); tagReader.reset(); sendStartStream(); processStream(tagReader.readTag()); break; } else if (nextTag.isStart("failure")) { tagReader.readElement(nextTag); - changeStatus(Account.STATUS_UNAUTHORIZED); + changeStatus(Account.State.UNAUTHORIZED); } else if (nextTag.isStart("challenge")) { final String challenge = tagReader.readElement(nextTag).getContent(); final Element response = new Element("response"); @@ -377,7 +377,7 @@ public class XmppConnection implements Runnable { tagReader.readElement(nextTag); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": resumption failed"); streamId = null; - if (account.getStatus() != Account.STATUS_ONLINE) { + if (account.getStatus() != Account.State.ONLINE) { sendBindRequest(); } } else if (nextTag.isStart("iq")) { @@ -389,8 +389,8 @@ public class XmppConnection implements Runnable { } nextTag = tagReader.readTag(); } - if (account.getStatus() == Account.STATUS_ONLINE) { - account. setStatus(Account.STATUS_OFFLINE); + if (account.getStatus() == Account.State.ONLINE) { + account. setStatus(Account.State.OFFLINE); if (statusListener != null) { statusListener.onStatusChanged(account); } @@ -408,7 +408,7 @@ public class XmppConnection implements Runnable { public void onIqPacketReceived(Account account, IqPacket packet) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": online with resource " + account.getResource()); - changeStatus(Account.STATUS_ONLINE); + changeStatus(Account.State.ONLINE); } }); } @@ -625,7 +625,7 @@ public class XmppConnection implements Runnable { sendRegistryRequest(); } else if (!this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { - changeStatus(Account.STATUS_REGISTRATION_NOT_SUPPORTED); + changeStatus(Account.State.REGISTRATION_NOT_SUPPORTED); disconnect(true); } else if (this.streamFeatures.hasChild("mechanisms") && shouldAuthenticate && usingEncryption) { @@ -731,20 +731,20 @@ public class XmppConnection implements Runnable { if (packet.getType() == IqPacket.TYPE_RESULT) { account.setOption(Account.OPTION_REGISTER, false); - changeStatus(Account.STATUS_REGISTRATION_SUCCESSFULL); + changeStatus(Account.State.REGISTRATION_SUCCESSFUL); } else if (packet.hasChild("error") && (packet.findChild("error") .hasChild("conflict"))) { - changeStatus(Account.STATUS_REGISTRATION_CONFLICT); + changeStatus(Account.State.REGISTRATION_CONFLICT); } else { - changeStatus(Account.STATUS_REGISTRATION_FAILED); + changeStatus(Account.State.REGISTRATION_FAILED); Log.d(Config.LOGTAG, packet.toString()); } disconnect(true); } }); } else { - changeStatus(Account.STATUS_REGISTRATION_FAILED); + changeStatus(Account.State.REGISTRATION_FAILED); disconnect(true); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not register. instructions are" diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index e4e00e43..3a1ba778 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -917,7 +917,7 @@ public class JingleConnection implements Downloadable { } public boolean start() { - if (account.getStatus() == Account.STATUS_ONLINE) { + if (account.getStatus() == Account.State.ONLINE) { if (mJingleStatus == JINGLE_STATUS_INITIATED) { new Thread(new Runnable() { |