Search in sources :

Example 36 with AccountJid

use of com.xabber.android.data.entity.AccountJid 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;
    }
    AccountJid 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);
    try {
        accountName.setText(RosterManager.getInstance().getBestContact(account, UserJid.from(accountManager.getVerboseName(account))).getName());
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
    }
    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) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) XabberAccountManager(com.xabber.android.data.xaccount.XabberAccountManager) 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)

Example 37 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ContactListGroupUtils method addContact.

/**
 * Adds contact to specified group.
 */
public static void addContact(AbstractContact abstractContact, String group, boolean online, Map<AccountJid, AccountConfiguration> accounts, Map<String, GroupConfiguration> groups, List<AbstractContact> contacts, boolean showAccounts, boolean showGroups) {
    if (showAccounts) {
        final AccountJid account = abstractContact.getAccount();
        final AccountConfiguration accountConfiguration;
        accountConfiguration = accounts.get(account);
        if (accountConfiguration == null) {
            return;
        }
        if (showGroups) {
            GroupConfiguration groupConfiguration = getGroupConfiguration(accountConfiguration, group);
            // if (accountConfiguration.isExpanded()) {
            // groupConfiguration.setNotEmpty();
            // if (groupConfiguration.isExpanded()) {
            // groupConfiguration.addAbstractContact(abstractContact);
            // }
            // }
            groupConfiguration.setNotEmpty();
            groupConfiguration.addAbstractContact(abstractContact);
            groupConfiguration.increment(online);
        } else {
            // if (accountConfiguration.isExpanded()) {
            // accountConfiguration.addAbstractContact(abstractContact);
            // }
            accountConfiguration.addAbstractContact(abstractContact);
        }
        accountConfiguration.increment(online);
    } else {
        if (showGroups) {
            GroupConfiguration groupConfiguration = getGroupConfiguration(groups, group);
            groupConfiguration.setNotEmpty();
            // if (groupConfiguration.isExpanded()) {
            // groupConfiguration.addAbstractContact(abstractContact);
            // }
            groupConfiguration.addAbstractContact(abstractContact);
            groupConfiguration.increment(online);
        } else {
            contacts.add(abstractContact);
        }
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid)

Example 38 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class AccountAddFragment method addAccount.

public void addAccount() {
    if (useOrbotView.isChecked() && !OrbotHelper.isOrbotInstalled()) {
        OrbotInstallerDialog.newInstance().show(getFragmentManager(), OrbotInstallerDialog.class.getName());
        return;
    }
    if (createAccountCheckBox.isChecked() && !passwordView.getText().toString().contentEquals(passwordConfirmEditText.getText().toString())) {
        Toast.makeText(getActivity(), getString(R.string.CONFIRM_PASSWORD), Toast.LENGTH_LONG).show();
        return;
    }
    AccountJid account;
    try {
        account = AccountManager.getInstance().addAccount(userView.getText().toString().trim(), passwordView.getText().toString(), "", false, storePasswordView.isChecked(), chkSync.isChecked(), useOrbotView.isChecked(), createAccountCheckBox.isChecked(), true);
    } catch (NetworkException e) {
        Application.getInstance().onError(e);
        return;
    }
    // update remote settings
    if (chkSync.isChecked())
        XabberAccountManager.getInstance().updateSettingsWithSaveLastAccount(account);
    getActivity().setResult(Activity.RESULT_OK, AccountAddActivity.createAuthenticatorResult(account));
    startActivity(AccountActivity.createIntent(getActivity(), account));
    getActivity().finish();
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) OrbotInstallerDialog(com.xabber.android.ui.dialog.OrbotInstallerDialog) NetworkException(com.xabber.android.data.NetworkException)

Example 39 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ChatFragment method showResourceChoiceAlert.

public void showResourceChoiceAlert(final AccountJid account, final UserJid user, final boolean restartSession) {
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
    final List<Map<String, String>> items = new ArrayList<>();
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
        String client = "";
        if (clientInfo == null) {
            CapabilitiesManager.getInstance().requestClientInfoByUser(account, fromJid);
        } else if (clientInfo == ClientInfo.INVALID_CLIENT_INFO) {
            client = getString(R.string.unknown);
        } else {
            String name = clientInfo.getName();
            if (name != null) {
                client = name;
            }
            String type = clientInfo.getType();
            if (type != null) {
                if (client.isEmpty()) {
                    client = type;
                } else {
                    client = client + "/" + type;
                }
            }
        }
        Map<String, String> map = new HashMap<>();
        if (!client.isEmpty()) {
            map.put(ResourceAdapter.KEY_CLIENT, client);
        }
        Resourcepart resourceOrNull = fromJid.getResourceOrNull();
        if (resourceOrNull != null) {
            map.put(ResourceAdapter.KEY_RESOURCE, resourceOrNull.toString());
            items.add(map);
        }
    }
    final ResourceAdapter adapter = new ResourceAdapter(getActivity(), items);
    adapter.setCheckedItem(checkedResource);
    if (items.size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.otr_select_resource);
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
            }
        });
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
                try {
                    RegularChat chat = (RegularChat) getChat();
                    if (chat != null) {
                        chat.setOTRresource(Resourcepart.from(items.get(checkedResource).get(ResourceAdapter.KEY_RESOURCE)));
                        if (restartSession)
                            restartEncryption(account, user);
                        else
                            startEncryption(account, user);
                    } else {
                        Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                    }
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                }
            }
        });
        builder.setSingleChoiceItems(adapter, checkedResource, null).show();
    } else {
        Toast.makeText(getActivity(), R.string.otr_select_toast_resources_not_found, Toast.LENGTH_SHORT).show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RegularChat(com.xabber.android.data.message.RegularChat) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Presence(org.jivesoftware.smack.packet.Presence) ResourceAdapter(com.xabber.android.ui.adapter.ResourceAdapter) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 40 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class AttentionManager method sendAttention.

public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    if (!(chat instanceof RegularChat)) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
    }
    Jid to = chat.getTo();
    if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
        final Presence presence = RosterManager.getInstance().getPresence(account, user);
        if (presence == null) {
            to = null;
        } else {
            to = presence.getFrom();
        }
    }
    if (to == null) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    }
    if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.NAMESPACE)) {
        throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
    }
    Message message = new Message();
    message.setTo(to);
    message.setType(Message.Type.headline);
    message.addExtension(new AttentionExtension());
    StanzaSender.sendStanza(account, message);
    chat.newAction(null, null, ChatAction.attention_called);
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) Presence(org.jivesoftware.smack.packet.Presence) NetworkException(com.xabber.android.data.NetworkException) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension) RegularChat(com.xabber.android.data.message.RegularChat)

Aggregations

AccountJid (com.xabber.android.data.entity.AccountJid)74 UserJid (com.xabber.android.data.entity.UserJid)38 AccountItem (com.xabber.android.data.account.AccountItem)21 Jid (org.jxmpp.jid.Jid)13 Intent (android.content.Intent)11 ArrayList (java.util.ArrayList)11 View (android.view.View)10 NetworkException (com.xabber.android.data.NetworkException)9 AbstractChat (com.xabber.android.data.message.AbstractChat)7 Message (org.jivesoftware.smack.packet.Message)7 Presence (org.jivesoftware.smack.packet.Presence)7 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)6 TextView (android.widget.TextView)5 StatusMode (com.xabber.android.data.account.StatusMode)5 Resourcepart (org.jxmpp.jid.parts.Resourcepart)5 ImageView (android.widget.ImageView)4 AccountManager (com.xabber.android.data.account.AccountManager)4 RosterContact (com.xabber.android.data.roster.RosterContact)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 BarPainter (com.xabber.android.ui.color.BarPainter)4