Search in sources :

Example 1 with ConnectionState

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;
    }
}
Also used : ConnectionState(com.xabber.android.data.connection.ConnectionState)

Example 2 with ConnectionState

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());
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ConnectionState(com.xabber.android.data.connection.ConnectionState)

Example 3 with ConnectionState

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;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) AccountManager(com.xabber.android.data.account.AccountManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ConnectionState(com.xabber.android.data.connection.ConnectionState) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 4 with ConnectionState

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;
            }
        });
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) MenuItem(android.view.MenuItem) ConnectionState(com.xabber.android.data.connection.ConnectionState)

Example 5 with ConnectionState

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;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) AccountItem(com.xabber.android.data.account.AccountItem) AccountManager(com.xabber.android.data.account.AccountManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ConnectionState(com.xabber.android.data.connection.ConnectionState) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

ConnectionState (com.xabber.android.data.connection.ConnectionState)5 AccountItem (com.xabber.android.data.account.AccountItem)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AccountManager (com.xabber.android.data.account.AccountManager)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 MenuItem (android.view.MenuItem)1 CompoundButton (android.widget.CompoundButton)1