mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-24 09:42:17 -05:00
avoid unnecessary thread creation
This commit is contained in:
parent
c5230e081c
commit
f25a824610
@ -1136,7 +1136,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
account.initOtrEngine(this);
|
account.initOtrEngine(this);
|
||||||
databaseBackend.createAccount(account);
|
databaseBackend.createAccount(account);
|
||||||
this.accounts.add(account);
|
this.accounts.add(account);
|
||||||
this.reconnectAccount(account, false);
|
this.reconnectAccountInBackground(account);
|
||||||
updateAccountUi();
|
updateAccountUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1972,24 +1972,29 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reconnectAccount(final Account account, final boolean force) {
|
public void reconnectAccount(final Account account, final boolean force) {
|
||||||
new Thread(new Runnable() {
|
synchronized (account) {
|
||||||
|
if (account.getXmppConnection() != null) {
|
||||||
|
disconnect(account, force);
|
||||||
|
}
|
||||||
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
|
if (account.getXmppConnection() == null) {
|
||||||
|
account.setXmppConnection(createConnection(account));
|
||||||
|
}
|
||||||
|
Thread thread = new Thread(account.getXmppConnection());
|
||||||
|
thread.start();
|
||||||
|
scheduleWakeUpCall(Config.CONNECT_TIMEOUT, account.getUuid().hashCode());
|
||||||
|
} else {
|
||||||
|
account.getRoster().clearPresences();
|
||||||
|
account.setXmppConnection(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reconnectAccountInBackground(final Account account) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (account.getXmppConnection() != null) {
|
reconnectAccount(account,false);
|
||||||
disconnect(account, force);
|
|
||||||
}
|
|
||||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
||||||
if (account.getXmppConnection() == null) {
|
|
||||||
account.setXmppConnection(createConnection(account));
|
|
||||||
}
|
|
||||||
Thread thread = new Thread(account.getXmppConnection());
|
|
||||||
thread.start();
|
|
||||||
scheduleWakeUpCall(Config.CONNECT_TIMEOUT, account.getUuid().hashCode());
|
|
||||||
} else {
|
|
||||||
account.getRoster().clearPresences();
|
|
||||||
account.setXmppConnection(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||||||
for (Account account : xmppConnectionService.getAccounts()) {
|
for (Account account : xmppConnectionService.getAccounts()) {
|
||||||
account.setResource(resource);
|
account.setResource(resource);
|
||||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
xmppConnectionService.reconnectAccount(account, false);
|
xmppConnectionService.reconnectAccountInBackground(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,13 @@ public class XmppConnection implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
|
if (socket != null) {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
} catch (final IOException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user