Search in sources :

Example 1 with AccountManager

use of com.xabber.android.data.account.AccountManager in project xabber-android by redsolution.

the class ClientStateManager method sendClientState.

protected static void sendClientState(PlainStreamElement element) {
    AccountManager accountManager = AccountManager.getInstance();
    for (String accountName : accountManager.getAccounts()) {
        AccountItem account = accountManager.getAccount(accountName);
        if (account == null) {
            continue;
        }
        ConnectionThread connectionThread = account.getConnectionThread();
        if (connectionThread == null) {
            continue;
        }
        AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
        if (xmppConnection == null) {
            continue;
        }
        if (xmppConnection.hasFeature("csi", ClientStateIndication.NAMESPACE))
            try {
                xmppConnection.send(element);
            } catch (SmackException.NotConnectedException e) {
            // not connected
            }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) AccountManager(com.xabber.android.data.account.AccountManager) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 2 with AccountManager

use of com.xabber.android.data.account.AccountManager in project xabber-android by redsolution.

the class AccountChooseAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final View view;
    final AccountManager accountManager = AccountManager.getInstance();
    if (convertView == null) {
        view = activity.getLayoutInflater().inflate(R.layout.account_choose_item, parent, false);
    } else {
        view = convertView;
    }
    final String account = (String) getItem(position);
    int accountColor = accountColors[accountManager.getColorLevel(account)];
    ((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
    ((TextView) view.findViewById(R.id.name)).setText(accountManager.getVerboseName(account));
    return view;
}
Also used : AccountManager(com.xabber.android.data.account.AccountManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Example 3 with AccountManager

use of com.xabber.android.data.account.AccountManager 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 AccountManager

use of com.xabber.android.data.account.AccountManager in project xabber-android by redsolution.

the class ConnectionManager method updateConnections.

/**
     * Update connection state.
     * <p/>
     * Start connections in waiting states and stop invalidated connections.
     *
     * @param userRequest
     */
public void updateConnections(boolean userRequest) {
    LogManager.i(this, "updateConnections");
    AccountManager accountManager = AccountManager.getInstance();
    for (String account : accountManager.getAccounts()) {
        final ConnectionItem connectionItem = accountManager.getAccount(account);
        if (connectionItem.updateConnection(userRequest)) {
            AccountManager.getInstance().onAccountChanged(account);
        }
    }
}
Also used : AccountManager(com.xabber.android.data.account.AccountManager)

Example 5 with AccountManager

use of com.xabber.android.data.account.AccountManager in project xabber-android by redsolution.

the class ConnectionManager method forceReconnect.

/**
     * Disconnect and connect using new network.
     */
public void forceReconnect() {
    LogManager.i(this, "forceReconnect");
    AccountManager accountManager = AccountManager.getInstance();
    for (String account : accountManager.getAccounts()) {
        accountManager.getAccount(account).forceReconnect();
        AccountManager.getInstance().onAccountChanged(account);
    }
}
Also used : AccountManager(com.xabber.android.data.account.AccountManager)

Aggregations

AccountManager (com.xabber.android.data.account.AccountManager)6 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 AccountItem (com.xabber.android.data.account.AccountItem)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2 ConnectionState (com.xabber.android.data.connection.ConnectionState)2 SwitchCompat (android.support.v7.widget.SwitchCompat)1 CompoundButton (android.widget.CompoundButton)1 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)1 AbstractXMPPConnection (org.jivesoftware.smack.AbstractXMPPConnection)1