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