Search in sources :

Example 76 with AccountItem

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

the class BookmarksManager method cleanCache.

public void cleanCache(AccountJid accountJid) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
    if (accountItem != null) {
        BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(accountItem.getConnection());
        bookmarkManager.cleanCache();
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) BookmarkManager(org.jivesoftware.smackx.bookmarks.BookmarkManager)

Example 77 with AccountItem

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

the class ContactListDrawerFragment method setupAccountList.

private void setupAccountList() {
    List<AccountItem> accountItems = new ArrayList<>();
    for (AccountItem accountItem : AccountManager.getInstance().getAllAccountItems()) {
        accountItems.add(accountItem);
    }
    accountListAdapter.setAccountItems(accountItems);
    if (accountItems.size() > 1)
        ivReorder.setVisibility(View.VISIBLE);
    else
        ivReorder.setVisibility(View.GONE);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ArrayList(java.util.ArrayList)

Example 78 with AccountItem

use of com.xabber.android.data.account.AccountItem 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.setImageResource(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 79 with AccountItem

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

the class ContextMenuHelper method setUpAccountMenu.

public static void setUpAccountMenu(final Activity activity, final ContactListPresenter presenter, final AccountJid account, Menu menu) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return;
    }
    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) {
                accountItem.disconnect();
                AccountManager.getInstance().onAccountChanged(account);
                return true;
            }
        });
    }
    menu.findItem(R.id.action_edit_account_status).setIntent(StatusEditActivity.createIntent(activity, account));
    menu.findItem(R.id.action_edit_account).setIntent(AccountActivity.createIntent(activity, account));
    menu.add(R.string.configure_notifications).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            activity.startActivity(CustomNotifySettings.createIntent(activity, account));
            return true;
        }
    });
    if (state.isConnected()) {
        menu.findItem(R.id.action_add_contact).setVisible(true).setIntent(ContactAddActivity.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, presenter, 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 80 with AccountItem

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

the class AccountHistorySettingsFragment method getValues.

@Override
protected Map<String, Object> getValues() {
    Map<String, Object> source = new HashMap<>();
    AccountItem accountItem = AccountManager.getInstance().getAccount(this.account);
    if (accountItem != null) {
        putValue(source, R.string.account_clear_history_on_exit_key, accountItem.isClearHistoryOnExit());
        // order of enum fields is very important!
        putValue(source, R.string.account_mam_default_behavior_key, accountItem.getMamDefaultBehaviour().ordinal());
        putValue(source, R.string.account_mam_sync_key, accountItem.getLoadHistorySettings().ordinal());
    }
    return source;
}
Also used : HashMap(java.util.HashMap) AccountItem(com.xabber.android.data.account.AccountItem)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)96 AccountJid (com.xabber.android.data.entity.AccountJid)24 UserJid (com.xabber.android.data.entity.UserJid)14 View (android.view.View)12 NetworkException (com.xabber.android.data.NetworkException)11 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Message (org.jivesoftware.smack.packet.Message)11 Presence (org.jivesoftware.smack.packet.Presence)10 TextView (android.widget.TextView)9 XMPPException (org.jivesoftware.smack.XMPPException)9 Jid (org.jxmpp.jid.Jid)9 ImageView (android.widget.ImageView)8 StatusMode (com.xabber.android.data.account.StatusMode)6 ConnectionState (com.xabber.android.data.connection.ConnectionState)5 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)5 Realm (io.realm.Realm)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 AccountManager (com.xabber.android.data.account.AccountManager)4