Search in sources :

Example 1 with RosterContact

use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.

the class ContactViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        // View information about contact from system contact list
        Uri data = getIntent().getData();
        if (data != null && "content".equals(data.getScheme())) {
            List<String> segments = data.getPathSegments();
            if (segments.size() == 2 && "data".equals(segments.get(0))) {
                Long id;
                try {
                    id = Long.valueOf(segments.get(1));
                } catch (NumberFormatException e) {
                    id = null;
                }
                if (id != null)
                    // FIXME: Will be empty while application is loading
                    for (RosterContact rosterContact : RosterManager.getInstance().getContacts()) if (id.equals(rosterContact.getViewId())) {
                        account = rosterContact.getAccount();
                        bareAddress = rosterContact.getUser();
                        break;
                    }
            }
        }
    } else {
        account = getAccount(getIntent());
        bareAddress = getUser(getIntent());
    }
    if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) {
        bareAddress = Jid.getBareAddress(AccountManager.getInstance().getAccount(account).getRealJid());
    }
    if (account == null || bareAddress == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        finish();
        return;
    }
    setContentView(R.layout.contact_viewer);
    if (savedInstanceState == null) {
        Fragment fragment;
        if (MUCManager.getInstance().hasRoom(account, bareAddress)) {
            fragment = ConferenceInfoFragment.newInstance(account, bareAddress);
        } else {
            fragment = ContactVcardViewerFragment.newInstance(account, bareAddress);
        }
        getFragmentManager().beginTransaction().add(R.id.scrollable_container, fragment).commit();
    }
    bestContact = RosterManager.getInstance().getBestContact(account, bareAddress);
    toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(ContactViewer.this);
        }
    });
    StatusBarPainter statusBarPainter = new StatusBarPainter(this);
    statusBarPainter.updateWithAccountName(account);
    final int accountMainColor = ColorManager.getInstance().getAccountPainter().getAccountMainColor(account);
    contactTitleView = findViewById(R.id.contact_title_expanded);
    findViewById(R.id.status_icon).setVisibility(View.GONE);
    contactTitleView.setBackgroundColor(accountMainColor);
    TextView contactNameView = (TextView) findViewById(R.id.name);
    contactNameView.setVisibility(View.INVISIBLE);
    collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(bestContact.getName());
    collapsingToolbar.setBackgroundColor(accountMainColor);
    collapsingToolbar.setContentScrimColor(accountMainColor);
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) StatusBarPainter(com.xabber.android.ui.color.StatusBarPainter) Uri(android.net.Uri) ConferenceInfoFragment(com.xabber.android.ui.fragment.ConferenceInfoFragment) ContactVcardViewerFragment(com.xabber.android.ui.fragment.ContactVcardViewerFragment) Fragment(android.app.Fragment) View(android.view.View) TextView(android.widget.TextView) TextView(android.widget.TextView)

Example 2 with RosterContact

use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.

the class ContactEditor method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Toolbar toolbar = getToolbar();
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(getAccount(), getBareAddress());
    if (rosterContact != null) {
        toolbar.inflateMenu(R.menu.contact_viewer);
        toolbar.setOnMenuItemClickListener(this);
    }
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with RosterContact

use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.

the class ContactListPresenter method buildStructure.

/**
 * Do not call directly. Only from Structure Builder
 */
void buildStructure() {
    // listener.hidePlaceholder();
    List<IFlexible> items = new ArrayList<>();
    final Collection<RosterContact> allRosterContacts = RosterManager.getInstance().getAllContacts();
    Map<AccountJid, Collection<UserJid>> blockedContacts = new TreeMap<>();
    for (AccountJid account : AccountManager.getInstance().getEnabledAccounts()) {
        blockedContacts.put(account, BlockingManager.getInstance().getCachedBlockedContacts(account));
    }
    final Collection<RosterContact> rosterContacts = new ArrayList<>();
    for (RosterContact contact : allRosterContacts) {
        if (blockedContacts.containsKey(contact.getAccount())) {
            if (!blockedContacts.get(contact.getAccount()).contains(contact.getUser())) {
                rosterContacts.add(contact);
            }
        }
    }
    final boolean showOffline = SettingsManager.contactsShowOffline();
    final boolean showGroups = SettingsManager.contactsShowGroups();
    final boolean showEmptyGroups = SettingsManager.contactsShowEmptyGroups();
    final boolean showActiveChats = false;
    final boolean stayActiveChats = true;
    final boolean showAccounts = SettingsManager.contactsShowAccounts();
    final Comparator<AbstractContact> comparator = SettingsManager.contactsOrder();
    final CommonState commonState = AccountManager.getInstance().getCommonState();
    final AccountJid selectedAccount = AccountManager.getInstance().getSelectedAccount();
    /**
     * Groups.
     */
    final Map<String, GroupConfiguration> groups;
    /**
     * Contacts.
     */
    final List<AbstractContact> contacts;
    /**
     * Chat list on top of contact list.
     */
    final GroupConfiguration chatsGroup;
    /**
     * Whether there is at least one contact.
     */
    boolean hasContacts = false;
    /**
     * Whether there is at least one visible contact.
     */
    boolean hasVisibleContacts = false;
    final Map<AccountJid, AccountConfiguration> accounts = new TreeMap<>();
    for (AccountJid account : AccountManager.getInstance().getEnabledAccounts()) {
        accounts.put(account, null);
    }
    /**
     * List of rooms and active chats grouped by users inside accounts.
     */
    final Map<AccountJid, Map<UserJid, AbstractChat>> abstractChats = new TreeMap<>();
    for (AbstractChat abstractChat : MessageManager.getInstance().getChats()) {
        if ((abstractChat instanceof RoomChat || abstractChat.isActive()) && accounts.containsKey(abstractChat.getAccount())) {
            final AccountJid account = abstractChat.getAccount();
            Map<UserJid, AbstractChat> users = abstractChats.get(account);
            if (users == null) {
                users = new TreeMap<>();
                abstractChats.put(account, users);
            }
            users.put(abstractChat.getUser(), abstractChat);
        }
    }
    if (filterString == null || filterString.isEmpty()) {
        // Create arrays.
        if (showAccounts) {
            groups = null;
            contacts = null;
            for (Map.Entry<AccountJid, AccountConfiguration> entry : accounts.entrySet()) {
                entry.setValue(new AccountConfiguration(entry.getKey(), GroupManager.IS_ACCOUNT, GroupManager.getInstance()));
            }
        } else {
            if (showGroups) {
                groups = new TreeMap<>();
                contacts = null;
            } else {
                groups = null;
                contacts = new ArrayList<>();
            }
        }
        // chats on top
        Collection<AbstractChat> chats = MessageManager.getInstance().getChatsOfEnabledAccount();
        chatsGroup = getChatsGroup(chats, currentChatsState);
        // Build structure.
        for (RosterContact rosterContact : rosterContacts) {
            if (!rosterContact.isEnabled()) {
                continue;
            }
            hasContacts = true;
            final boolean online = rosterContact.getStatusMode().isOnline();
            final AccountJid account = rosterContact.getAccount();
            final Map<UserJid, AbstractChat> users = abstractChats.get(account);
            final AbstractChat abstractChat;
            if (users == null) {
                abstractChat = null;
            } else {
                abstractChat = users.remove(rosterContact.getUser());
            }
            if (selectedAccount != null && !selectedAccount.equals(account)) {
                continue;
            }
            if (ContactListGroupUtils.addContact(rosterContact, online, accounts, groups, contacts, showAccounts, showGroups, showOffline)) {
                hasVisibleContacts = true;
            }
        }
        for (Map<UserJid, AbstractChat> users : abstractChats.values()) for (AbstractChat abstractChat : users.values()) {
            final AbstractContact abstractContact;
            if (abstractChat instanceof RoomChat) {
                abstractContact = new RoomContact((RoomChat) abstractChat);
            } else {
                abstractContact = new ChatContact(abstractChat);
            }
            if (selectedAccount != null && !selectedAccount.equals(abstractChat.getAccount())) {
                continue;
            }
            final String group;
            final boolean online;
            if (abstractChat instanceof RoomChat) {
                group = GroupManager.IS_ROOM;
                online = abstractContact.getStatusMode().isOnline();
            } else if (MUCManager.getInstance().isMucPrivateChat(abstractChat.getAccount(), abstractChat.getUser())) {
                group = GroupManager.IS_ROOM;
                online = abstractContact.getStatusMode().isOnline();
            } else {
                group = GroupManager.NO_GROUP;
                online = false;
            }
            hasVisibleContacts = true;
            ContactListGroupUtils.addContact(abstractContact, group, online, accounts, groups, contacts, showAccounts, showGroups);
        }
        // BUILD STRUCTURE //
        // Remove empty groups, sort and apply structure.
        items.clear();
        items.add(new ToolbarVO(context, this));
        if (hasVisibleContacts) {
            if (currentChatsState == ChatListState.recent) {
                // add recent chats
                int i = 0;
                for (AbstractContact contact : chatsGroup.getAbstractContacts()) {
                    if (i == MAX_RECENT_ITEMS - 1) {
                        if (getAllChatsSize() > MAX_RECENT_ITEMS)
                            items.add(ChatWithButtonVO.convert(contact, this));
                        else
                            items.add(ChatVO.convert(contact, this, null));
                    } else
                        items.add(ChatVO.convert(contact, this, null));
                    i++;
                }
                if (showAccounts) {
                    // boolean isFirst = items.isEmpty();
                    for (AccountConfiguration rosterAccount : accounts.values()) {
                        if (rosterAccount.getTotal() != 0) {
                            if (showGroups) {
                                createContactListWithAccountsAndGroups(items, rosterAccount, showEmptyGroups, comparator);
                            } else {
                                createContactListWithAccounts(items, rosterAccount, comparator);
                            }
                        } else {
                            AccountWithButtonsVO account = AccountWithButtonsVO.convert(rosterAccount, this);
                            ButtonVO button = ButtonVO.convert(rosterAccount, context.getString(R.string.contact_add), ButtonVO.ACTION_ADD_CONTACT);
                            account.addSubItem(button);
                            items.add(account);
                        }
                    }
                } else {
                    if (showGroups) {
                        createContactListWithGroups(items, showEmptyGroups, groups, comparator);
                    } else {
                        createContactList(items, contacts, comparator);
                    }
                }
            } else
                items.addAll(ChatVO.convert(chatsGroup.getAbstractContacts(), this, null));
        }
    } else {
        // Search
        final ArrayList<AbstractContact> baseEntities = getSearchResults(rosterContacts, comparator, abstractChats);
        items.clear();
        items.add(new CategoryVO(context.getString(R.string.category_title_contacts)));
        items.addAll(SettingsManager.contactsShowMessages() ? ExtContactVO.convert(baseEntities, this) : ContactVO.convert(baseEntities, this));
        hasVisibleContacts = baseEntities.size() > 0;
    }
    if (view != null)
        view.onContactListChanged(commonState, hasContacts, hasVisibleContacts, filterString != null);
    if (view != null) {
        if (items.size() == 1 && (filterString == null || filterString.isEmpty())) {
            if (currentChatsState == ChatListState.unread)
                view.showPlaceholder(context.getString(R.string.placeholder_no_unread));
            if (currentChatsState == ChatListState.archived)
                view.showPlaceholder(context.getString(R.string.placeholder_no_archived));
        } else
            view.hidePlaceholder();
        view.updateItems(items);
    }
}
Also used : CommonState(com.xabber.android.data.account.CommonState) RosterContact(com.xabber.android.data.roster.RosterContact) ChatWithButtonVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ChatWithButtonVO) ButtonVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ButtonVO) ArrayList(java.util.ArrayList) RoomChat(com.xabber.android.data.extension.muc.RoomChat) CategoryVO(com.xabber.android.presentation.ui.contactlist.viewobjects.CategoryVO) AccountJid(com.xabber.android.data.entity.AccountJid) ToolbarVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ToolbarVO) ChatContact(com.xabber.android.data.message.ChatContact) AbstractChat(com.xabber.android.data.message.AbstractChat) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) UserJid(com.xabber.android.data.entity.UserJid) GroupConfiguration(com.xabber.android.ui.adapter.contactlist.GroupConfiguration) TreeMap(java.util.TreeMap) AbstractContact(com.xabber.android.data.roster.AbstractContact) RoomContact(com.xabber.android.data.extension.muc.RoomContact) Collection(java.util.Collection) AccountConfiguration(com.xabber.android.ui.adapter.contactlist.AccountConfiguration) AccountWithButtonsVO(com.xabber.android.presentation.ui.contactlist.viewobjects.AccountWithButtonsVO) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with RosterContact

use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.

the class CapabilitiesManager method updateClientInfo.

@SuppressWarnings("WeakerAccess")
void updateClientInfo(final AccountJid account, final Jid jid) {
    DiscoverInfo discoverInfo = EntityCapsManager.getDiscoverInfoByUser(jid);
    if (discoverInfo != null) {
        return;
    }
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return;
    }
    try {
        discoverInfo = ServiceDiscoveryManager.getInstanceFor(accountItem.getConnection()).discoverInfo(jid);
        EntityCapsManager.NodeVerHash nodeVerHashByJid = EntityCapsManager.getNodeVerHashByJid(jid);
        if (nodeVerHashByJid == null) {
            discoverInfoCache.put(jid, discoverInfo);
        }
        if (discoverInfo != null) {
            clientInfoCache.put(jid, ClientInfo.fromDiscoveryInfo(discoverInfo));
        }
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
        LogManager.exception(this, e);
        clientInfoCache.put(jid, ClientInfo.INVALID_CLIENT_INFO);
    }
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, jid.asBareJid());
    if (rosterContact != null) {
        final ArrayList<RosterContact> rosterContacts = new ArrayList<>();
        rosterContacts.add(rosterContact);
        Application.getInstance().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                for (OnContactChangedListener onContactChangedListener : Application.getInstance().getUIListeners(OnContactChangedListener.class)) {
                    onContactChangedListener.onContactsChanged(rosterContacts);
                }
            }
        });
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) RosterContact(com.xabber.android.data.roster.RosterContact) AccountItem(com.xabber.android.data.account.AccountItem) ArrayList(java.util.ArrayList) EntityCapsManager(org.jivesoftware.smackx.caps.EntityCapsManager) OnContactChangedListener(com.xabber.android.data.roster.OnContactChangedListener)

Example 5 with RosterContact

use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.

the class NextMamManager method runMigrationToNewArchive.

private void runMigrationToNewArchive(AccountItem accountItem, Realm realm) {
    LogManager.d(LOG_TAG, "run migration for account: " + accountItem.getAccount().toString());
    Collection<RosterContact> contacts = RosterManager.getInstance().getAccountRosterContacts(accountItem.getAccount());
    for (RosterContact contact : contacts) {
        AbstractChat chat = MessageManager.getInstance().getOrCreateChat(contact.getAccount(), contact.getUser());
        MessageItem firstMessage = getFirstMessageForMigration(chat, realm);
        SyncInfo syncInfo = realm.where(SyncInfo.class).equalTo(SyncInfo.FIELD_ACCOUNT, accountItem.getAccount().toString()).equalTo(SyncInfo.FIELD_USER, chat.getUser().toString()).findFirst();
        if (firstMessage != null && syncInfo != null) {
            realm.beginTransaction();
            firstMessage.setArchivedId(syncInfo.getFirstMamMessageMamId());
            firstMessage.setPreviousId(null);
            realm.commitTransaction();
        }
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RosterContact(com.xabber.android.data.roster.RosterContact) AbstractChat(com.xabber.android.data.message.AbstractChat) SyncInfo(com.xabber.android.data.database.messagerealm.SyncInfo)

Aggregations

RosterContact (com.xabber.android.data.roster.RosterContact)24 AbstractChat (com.xabber.android.data.message.AbstractChat)11 ArrayList (java.util.ArrayList)8 RoomChat (com.xabber.android.data.extension.muc.RoomChat)6 AccountJid (com.xabber.android.data.entity.AccountJid)5 UserJid (com.xabber.android.data.entity.UserJid)5 RoomContact (com.xabber.android.data.extension.muc.RoomContact)5 ChatContact (com.xabber.android.data.message.ChatContact)5 AbstractContact (com.xabber.android.data.roster.AbstractContact)5 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 EditText (android.widget.EditText)3 CommonState (com.xabber.android.data.account.CommonState)3 EntityIntentBuilder (com.xabber.android.data.intent.EntityIntentBuilder)3 Collection (java.util.Collection)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Intent (android.content.Intent)2 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 BaseEntity (com.xabber.android.data.entity.BaseEntity)2