use of com.xabber.android.data.connection.ConnectionState in project xabber-android by redsolution.
the class AccountManager method getCommonState.
public CommonState getCommonState() {
boolean disabled = false;
boolean offline = false;
boolean waiting = false;
boolean connecting = false;
boolean roster = false;
boolean online = false;
for (AccountItem accountItem : accountItems.values()) {
ConnectionState state = accountItem.getState();
if (state == ConnectionState.connected) {
online = true;
}
if (RosterManager.getInstance().isRosterReceived(accountItem.getAccount())) {
roster = true;
}
if (state == ConnectionState.connecting || state == ConnectionState.authentication) {
connecting = true;
}
if (state == ConnectionState.waiting) {
waiting = true;
}
if (accountItem.isEnabled()) {
offline = true;
}
disabled = true;
}
if (online) {
return CommonState.online;
} else if (roster) {
return CommonState.roster;
} else if (connecting) {
return CommonState.connecting;
}
if (waiting) {
return CommonState.waiting;
} else if (offline) {
return CommonState.offline;
} else if (disabled) {
return CommonState.disabled;
} else {
return CommonState.empty;
}
}
use of com.xabber.android.data.connection.ConnectionState in project xabber-android by redsolution.
the class NotificationManager method updatePersistentNotification.
private void updatePersistentNotification() {
if (!SettingsManager.eventsPersistent()) {
return;
}
int waiting = 0;
int connecting = 0;
int connected = 0;
Collection<String> accountList = AccountManager.getInstance().getAccounts();
for (String account : accountList) {
ConnectionState state = AccountManager.getInstance().getAccount(account).getState();
if (RosterManager.getInstance().isRosterReceived(account)) {
connected++;
} else if (state == ConnectionState.connecting || state == ConnectionState.authentication) {
connecting++;
} else if (state == ConnectionState.waiting) {
waiting++;
}
}
final Intent persistentIntent;
if (waiting > 0 && application.isInitialized()) {
persistentIntent = ReconnectionActivity.createIntent(application);
} else {
persistentIntent = ContactList.createPersistentIntent(application);
}
if (connected > 0) {
persistentNotificationBuilder.setColor(persistentNotificationColor);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_online);
} else {
persistentNotificationBuilder.setColor(NotificationCompat.COLOR_DEFAULT);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_offline);
}
persistentNotificationBuilder.setContentText(getConnectionState(waiting, connecting, connected, accountList.size()));
persistentNotificationBuilder.setContentIntent(PendingIntent.getActivity(application, 0, persistentIntent, PendingIntent.FLAG_UPDATE_CURRENT));
notify(PERSISTENT_NOTIFICATION_ID, persistentNotificationBuilder.build());
}
use of com.xabber.android.data.connection.ConnectionState in project xabber-android by redsolution.
the class AccountListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
AccountManager accountManager = AccountManager.getInstance();
if (convertView == null) {
view = getActivity().getLayoutInflater().inflate(R.layout.account_list_item, parent, false);
} else {
view = convertView;
}
final String account = getItem(position);
((ImageView) view.findViewById(R.id.color)).setImageDrawable(new ColorDrawable(ColorManager.getInstance().getAccountPainter().getAccountMainColor(account)));
((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
((TextView) view.findViewById(R.id.name)).setText(accountManager.getVerboseName(account));
SwitchCompat accountSwitch = (SwitchCompat) view.findViewById(R.id.account_switch);
final AccountItem accountItem = accountManager.getAccount(account);
accountSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AccountManager.getInstance().setEnabled(account, isChecked);
}
});
ConnectionState state;
if (accountItem == null) {
state = ConnectionState.offline;
accountSwitch.setChecked(false);
} else {
state = accountItem.getState();
accountSwitch.setChecked(accountItem.isEnabled());
}
((TextView) view.findViewById(R.id.status)).setText(getActivity().getString(state.getStringId()));
return view;
}
use of com.xabber.android.data.connection.ConnectionState in project xabber-android by redsolution.
the class ContextMenuHelper method setUpAccountMenu.
public static void setUpAccountMenu(final FragmentActivity activity, final UpdatableAdapter adapter, final String account, Menu menu) {
final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
ConnectionState state = accountItem.getState();
if (state == ConnectionState.waiting) {
menu.findItem(R.id.action_reconnect_account).setVisible(true).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (accountItem.updateConnection(true))
AccountManager.getInstance().onAccountChanged(account);
return true;
}
});
}
menu.findItem(R.id.action_edit_account_status).setIntent(StatusEditor.createIntent(activity, account));
menu.findItem(R.id.action_edit_account).setIntent(AccountViewer.createAccountPreferencesIntent(activity, account));
if (state.isConnected()) {
menu.findItem(R.id.action_contact_info).setVisible(true).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
activity.startActivity(AccountViewer.createAccountInfoIntent(activity, account));
return true;
}
});
menu.findItem(R.id.action_add_contact).setVisible(true).setIntent(ContactAdd.createIntent(activity, account));
}
if (SettingsManager.contactsShowAccounts()) {
menu.findItem(R.id.action_set_up_offline_contacts).setVisible(true).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ContextMenuHelper.createOfflineContactsDialog(activity, adapter, account, GroupManager.IS_ACCOUNT).show();
return true;
}
});
}
}
use of com.xabber.android.data.connection.ConnectionState in project xabber-android by redsolution.
the class NavigationDrawerAccountAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
AccountManager accountManager = AccountManager.getInstance();
if (convertView == null) {
view = getActivity().getLayoutInflater().inflate(R.layout.contact_list_drawer_account_item, parent, false);
} else {
view = convertView;
}
String account = getItem(position);
((ImageView) view.findViewById(R.id.color)).setImageDrawable(new ColorDrawable((ColorManager.getInstance().getAccountPainter().getAccountMainColor(account))));
((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
TextView accountName = (TextView) view.findViewById(R.id.name);
accountName.setText(RosterManager.getInstance().getBestContact(account, accountManager.getVerboseName(account)).getName());
accountName.setTextColor(ColorManager.getInstance().getAccountPainter().getAccountTextColor(account));
((TextView) view.findViewById(R.id.account_jid)).setText(accountManager.getVerboseName(account));
AccountItem accountItem = accountManager.getAccount(account);
ConnectionState state;
if (accountItem == null) {
state = ConnectionState.offline;
} else {
state = accountItem.getState();
}
((TextView) view.findViewById(R.id.status)).setText(getActivity().getString(state.getStringId()));
return view;
}
Aggregations