Search in sources :

Example 51 with AccountJid

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

the class ContactVcardViewerFragment method fillResourceList.

private void fillResourceList(AccountJid account, Jid bareAddress, List<View> resourcesList) {
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, bareAddress);
    boolean isAccount = account.getFullJid().asBareJid().equals(user.getBareJid());
    Resourcepart accountResource = null;
    if (isAccount) {
        // TODO: probably not the best way to get own resource
        AccountItem accountItem = AccountManager.getInstance().getAccount(account);
        if (accountItem != null) {
            accountResource = accountItem.getConnection().getConfiguration().getResource();
        }
    }
    PresenceManager.sortPresencesByPriority(allPresences);
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
        String client = "";
        if (clientInfo == null) {
            client = getString(R.string.please_wait);
            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;
                }
            }
        }
        int priorityValue = presence.getPriority();
        String priorityString;
        if (priorityValue == Integer.MIN_VALUE) {
            priorityString = getString(R.string.account_priority) + ": " + getString(R.string.unknown);
        } else {
            priorityString = getString(R.string.account_priority) + ": " + priorityValue;
        }
        if (!client.isEmpty()) {
            client = getString(R.string.contact_viewer_client) + ": " + client;
        }
        Resourcepart resourceOrNull = fromJid.getResourceOrNull();
        String resource = getString(R.string.account_resource) + ": " + resourceOrNull;
        final StatusMode statusMode = StatusMode.createStatusMode(presence);
        String status = presence.getStatus();
        if (TextUtils.isEmpty(status)) {
            status = getString(statusMode.getStringID());
        }
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View resourceView = inflater.inflate(R.layout.item_contact_info, xmppItems, false);
        resourceView.findViewById(R.id.contact_info_item_secondary);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_secondary)).setText(client);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_main)).setText(status);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_second_line)).setText(resource);
        resourceView.findViewById(R.id.contact_info_item_secondary_second_line).setVisibility(View.VISIBLE);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_third_line)).setText(priorityString);
        resourceView.findViewById(R.id.contact_info_item_secondary_third_line).setVisibility(View.VISIBLE);
        if (isAccount && resourceOrNull != null && resourceOrNull.equals(accountResource)) {
            TextView thisDeviceIndicatorTextView = (TextView) resourceView.findViewById(R.id.contact_info_item_secondary_forth_line);
            thisDeviceIndicatorTextView.setTextColor(ColorManager.getInstance().getAccountPainter().getAccountSendButtonColor(account));
            thisDeviceIndicatorTextView.setText(R.string.contact_viewer_this_device);
            thisDeviceIndicatorTextView.setVisibility(View.VISIBLE);
        }
        ImageView statusIcon = (ImageView) resourceView.findViewById(R.id.contact_info_right_icon);
        statusIcon.setVisibility(View.VISIBLE);
        statusIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_status));
        statusIcon.setImageLevel(statusMode.getStatusLevel());
        resourcesList.add(resourceView);
    }
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Jid(org.jxmpp.jid.Jid) AccountItem(com.xabber.android.data.account.AccountItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Resourcepart(org.jxmpp.jid.parts.Resourcepart) LayoutInflater(android.view.LayoutInflater) Presence(org.jivesoftware.smack.packet.Presence) TextView(android.widget.TextView) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) ImageView(android.widget.ImageView)

Example 52 with AccountJid

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

the class ContextMenuHelper method createContactContextMenu.

public static void createContactContextMenu(final Activity activity, ContactListPresenter presenter, AbstractContact abstractContact, ContextMenu menu) {
    final AccountJid account = abstractContact.getAccount();
    final UserJid user = abstractContact.getUser();
    menu.setHeaderTitle(abstractContact.getName());
    MenuInflater inflater = activity.getMenuInflater();
    inflater.inflate(R.menu.item_contact, menu);
    setContactContextMenuActions(activity, presenter, menu, account, user);
    setContactContextMenuItemsVisibilty(abstractContact, menu, account, user);
}
Also used : MenuInflater(android.view.MenuInflater) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid)

Example 53 with AccountJid

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

the class AccountInfoEditorActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_toolbar_and_container);
    Intent intent = getIntent();
    AccountJid account = getAccount(intent);
    String vCard = intent.getStringExtra(ARG_VCARD);
    if (AccountManager.getInstance().getAccount(account) == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        setResult(RESULT_CANCELED);
        finish();
    }
    toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    toolbar.setTitle(R.string.edit_account_user_info);
    BarPainter barPainter = new BarPainter(this, toolbar);
    barPainter.updateWithAccountName(account);
    toolbar.inflateMenu(SAVE_MENU);
    toolbar.setOnMenuItemClickListener(this);
    boolean isSaveButtonEnabled = false;
    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction().add(R.id.fragment_container, AccountInfoEditorFragment.newInstance(account, vCard)).commit();
    } else {
        isSaveButtonEnabled = savedInstanceState.getBoolean(ARGUMENT_SAVE_BUTTON_ENABLED);
    }
    toolbar.getMenu().findItem(R.id.action_save).setEnabled(isSaveButtonEnabled);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) Intent(android.content.Intent) View(android.view.View) BarPainter(com.xabber.android.ui.color.BarPainter)

Example 54 with AccountJid

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

the class ChatActivity method getInitialChatFromIntent.

private void getInitialChatFromIntent() {
    Intent intent = getIntent();
    AccountJid newAccount = getAccount(intent);
    UserJid newUser = getUser(intent);
    if (newAccount != null) {
        this.account = newAccount;
    }
    if (newUser != null) {
        this.user = newUser;
    }
    LogManager.i(LOG_TAG, "getInitialChatFromIntent " + this.user);
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent)

Example 55 with AccountJid

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

the class ChatActivity method getAccount.

@Nullable
private static AccountJid getAccount(Intent intent) {
    AccountJid value = EntityIntentBuilder.getAccount(intent);
    if (value != null)
        return value;
    // Backward compatibility.
    String stringExtra = intent.getStringExtra("com.xabber.android.data.account");
    if (stringExtra == null) {
        return null;
    }
    try {
        return AccountJid.from(stringExtra);
    } catch (XmppStringprepException e) {
        LogManager.exception(LOG_TAG, e);
        return null;
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Nullable(android.support.annotation.Nullable)

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