code refactoring to provide shorter account enabled check
This commit is contained in:
parent
fd7ee7c025
commit
aa10b9ff05
|
@ -108,6 +108,10 @@ public class Account extends AbstractEntity {
|
|||
return key == null || Boolean.parseBoolean(key);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return !isOptionSet(Account.OPTION_DISABLED);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
DISABLED(false,false),
|
||||
OFFLINE(false),
|
||||
|
|
|
@ -682,7 +682,7 @@ public class NotificationService {
|
|||
if (account.isOnlineAndConnected()) {
|
||||
connected++;
|
||||
enabled++;
|
||||
} else if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
} else if (account.isEnabled()) {
|
||||
enabled++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -358,7 +358,7 @@ public class XmppConnectionService extends Service {
|
|||
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
|
||||
} else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
|
||||
resetSendingToWaiting(account);
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED) && isInLowPingTimeoutMode(account)) {
|
||||
if (account.isEnabled() && isInLowPingTimeoutMode(account)) {
|
||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": went into offline state during low ping mode. reconnecting now");
|
||||
reconnectAccount(account, true, false);
|
||||
} else {
|
||||
|
@ -2325,7 +2325,7 @@ public class XmppConnectionService extends Service {
|
|||
|
||||
private boolean hasEnabledAccounts() {
|
||||
for (Account account : this.accounts) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3088,7 +3088,7 @@ public class XmppConnectionService extends Service {
|
|||
account.setXmppConnection(connection);
|
||||
}
|
||||
boolean hasInternet = hasInternetConnection();
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED) && hasInternet) {
|
||||
if (account.isEnabled() && hasInternet) {
|
||||
if (!force) {
|
||||
disconnect(account, false);
|
||||
}
|
||||
|
@ -3539,7 +3539,7 @@ public class XmppConnectionService extends Service {
|
|||
public void refreshAllPresences() {
|
||||
boolean includeIdleTimestamp = checkListeners() && broadcastLastActivity();
|
||||
for (Account account : getAccounts()) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
sendPresence(account, includeIdleTimestamp);
|
||||
}
|
||||
}
|
||||
|
@ -3585,7 +3585,7 @@ public class XmppConnectionService extends Service {
|
|||
public List<Contact> findContacts(Jid jid, String accountJid) {
|
||||
ArrayList<Contact> contacts = new ArrayList<>();
|
||||
for (Account account : getAccounts()) {
|
||||
if ((!account.isOptionSet(Account.OPTION_DISABLED) || accountJid != null)
|
||||
if ((account.isEnabled() || accountJid != null)
|
||||
&& (accountJid == null || accountJid.equals(account.getJid().toBareJid().toString()))) {
|
||||
Contact contact = account.getRoster().getContactFromRoster(jid);
|
||||
if (contact != null) {
|
||||
|
@ -3598,8 +3598,7 @@ public class XmppConnectionService extends Service {
|
|||
|
||||
public Conversation findFirstMuc(Jid jid) {
|
||||
for (Conversation conversation : getConversations()) {
|
||||
if (conversation.getJid().toBareJid().equals(jid.toBareJid())
|
||||
&& conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
if (conversation.getAccount().isEnabled() && conversation.getJid().toBareJid().equals(jid.toBareJid()) && conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
return conversation;
|
||||
}
|
||||
}
|
||||
|
@ -3830,7 +3829,7 @@ public class XmppConnectionService extends Service {
|
|||
account.setPresenceStatus(status);
|
||||
account.setPresenceStatusMessage(statusMessage);
|
||||
databaseBackend.updateAccount(account);
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED) && send) {
|
||||
if (account.isEnabled() && send) {
|
||||
sendPresence(account);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
}
|
||||
mHostname.setError(null);
|
||||
mPort.setError(null);
|
||||
if (!mAccount.isOptionSet(Account.OPTION_DISABLED)
|
||||
if (mAccount.isEnabled()
|
||||
&& !registerNewAccount
|
||||
&& !mInitMode) {
|
||||
finish();
|
||||
|
|
|
@ -127,15 +127,15 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
R.menu.manageaccounts_context, menu);
|
||||
AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
||||
this.selectedAccount = accountList.get(acmi.position);
|
||||
if (this.selectedAccount.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (this.selectedAccount.isEnabled()) {
|
||||
menu.findItem(R.id.mgmt_account_enable).setVisible(false);
|
||||
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(Config.supportOpenPgp());
|
||||
menu.findItem(R.id.mgmt_account_change_presence).setVisible(manuallyChangePresence());
|
||||
} else {
|
||||
menu.findItem(R.id.mgmt_account_disable).setVisible(false);
|
||||
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(false);
|
||||
menu.findItem(R.id.mgmt_account_publish_avatar).setVisible(false);
|
||||
menu.findItem(R.id.mgmt_account_change_presence).setVisible(false);
|
||||
} else {
|
||||
menu.findItem(R.id.mgmt_account_enable).setVisible(false);
|
||||
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(Config.supportOpenPgp());
|
||||
menu.findItem(R.id.mgmt_account_change_presence).setVisible(manuallyChangePresence());
|
||||
}
|
||||
menu.setHeaderTitle(this.selectedAccount.getJid().toBareJid().toString());
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
List<Account> list = new ArrayList<>();
|
||||
synchronized (this.accountList) {
|
||||
for (Account account : this.accountList) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
list.add(account);
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
private boolean accountsLeftToDisable() {
|
||||
synchronized (this.accountList) {
|
||||
for (Account account : this.accountList) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
private boolean accountsLeftToEnable() {
|
||||
synchronized (this.accountList) {
|
||||
for (Account account : this.accountList) {
|
||||
if (account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (!account.isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
List<Account> list = new ArrayList<>();
|
||||
synchronized (this.accountList) {
|
||||
for (Account account : this.accountList) {
|
||||
if (account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (!account.isEnabled()) {
|
||||
list.add(account);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||
builder.setTitle(R.string.pref_delete_omemo_identities);
|
||||
final List<CharSequence> accounts = new ArrayList<>();
|
||||
for(Account account : xmppConnectionService.getAccounts()) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
accounts.add(account.getJid().toBareJid().toString());
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||
if (xmppConnectionServiceBound) {
|
||||
for (Account account : xmppConnectionService.getAccounts()) {
|
||||
if (account.setResource(resource)) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
XmppConnection connection = account.getXmppConnection();
|
||||
if (connection != null) {
|
||||
connection.resetStreamId();
|
||||
|
@ -410,7 +410,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||
|
||||
private void reconnectAccounts() {
|
||||
for (Account account : xmppConnectionService.getAccounts()) {
|
||||
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account.isEnabled()) {
|
||||
xmppConnectionService.reconnectAccountInBackground(account);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -867,7 +867,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
|
||||
private boolean handleJid(Invite invite) {
|
||||
Account account = xmppConnectionService.findAccountByJid(invite.getJid());
|
||||
if (account != null && !account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (account != null && account.isEnabled()) {
|
||||
if (invite.hasFingerprints() && xmppConnectionService.verifyFingerprints(account,invite.getFingerprints())) {
|
||||
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ExceptionHelper {
|
|||
List<Account> accounts = service.getAccounts();
|
||||
Account account = null;
|
||||
for (int i = 0; i < accounts.size(); ++i) {
|
||||
if (!accounts.get(i).isOptionSet(Account.OPTION_DISABLED)) {
|
||||
if (accounts.get(i).isEnabled()) {
|
||||
account = accounts.get(i);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue