Java Code Examples for org.telegram.messenger.ContactsController#getInstance()

The following examples show how to use org.telegram.messenger.ContactsController#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InviteContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void fetchContacts() {
    phoneBookContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).phoneBookContacts);
    Collections.sort(phoneBookContacts, new Comparator<ContactsController.Contact>() {
        @Override
        public int compare(ContactsController.Contact o1, ContactsController.Contact o2) {
            if (o1.imported > o2.imported) {
                return -1;
            } else if (o1.imported < o2.imported) {
                return 1;
            }
            return 0;
        }
    });
    if (emptyView != null) {
        emptyView.showTextView();
    }
    if (adapter != null) {
        adapter.notifyDataSetChanged();
    }
}
 
Example 2
Source File: ContactsAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setSortType(int value) {
    sortType = value;
    if (sortType == 2) {
        if (onlineContacts == null) {
            onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
            int selfId = UserConfig.getInstance(currentAccount).clientUserId;
            for (int a = 0, N = onlineContacts.size(); a < N; a++) {
                if (onlineContacts.get(a).user_id == selfId) {
                    onlineContacts.remove(a);
                    break;
                }
            }
        }
        sortOnlineContacts();
    } else {
        notifyDataSetChanged();
    }
}
 
Example 3
Source File: InviteContactsActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void fetchContacts() {
    phoneBookContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).phoneBookContacts);
    Collections.sort(phoneBookContacts, (o1, o2) -> {
        if (o1.imported > o2.imported) {
            return -1;
        } else if (o1.imported < o2.imported) {
            return 1;
        }
        return 0;
    });
    if (emptyView != null) {
        emptyView.showTextView();
    }
    if (adapter != null) {
        adapter.notifyDataSetChanged();
    }
}
 
Example 4
Source File: ContactsAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getSectionCount()
{
    ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).sortedUsersMutualSectionsArray : ContactsController.getInstance(currentAccount).sortedUsersSectionsArray;
    int count = sortedUsersSectionsArray.size();
    if (onlyUsers == 0)
    {
        count++;
    }
    if (isAdmin)
    {
        count++;
    }
    if (needPhonebook)
    {
        count++;
    }
    return count;
}
 
Example 5
Source File: ContactsAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getSectionCount() {
    int count;
    if (sortType == 2) {
        count = 1;
    } else {
        ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).sortedUsersMutualSectionsArray : ContactsController.getInstance(currentAccount).sortedUsersSectionsArray;
        count = sortedUsersSectionsArray.size();
    }
    if (onlyUsers == 0) {
        count++;
    }
    if (isAdmin) {
        count++;
    }
    if (needPhonebook) {
        //count++;
    }
    return count;
}
 
Example 6
Source File: ChatAttachAlertContactsLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isEnabled(int section, int row) {
    if (section == 0 || section == getSectionCount() - 1) {
        return false;
    }
    section--;
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return row < usersSectionsDict.get(sortedUsersSectionsArray.get(section)).size();
}
 
Example 7
Source File: PhonebookAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getLetter(int position) {
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    int section = getSectionForPosition(position);
    if (section == -1) {
        section = sortedUsersSectionsArray.size() - 1;
    }
    if (section >= 0 && section < sortedUsersSectionsArray.size()) {
        return sortedUsersSectionsArray.get(section);
    }
    return null;
}
 
Example 8
Source File: PhonebookAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getCountForSection(int section) {
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    if (section < sortedUsersSectionsArray.size()) {
        ArrayList<Object> arr = usersSectionsDict.get(sortedUsersSectionsArray.get(section));
        int count = arr.size();
        if (section != sortedUsersSectionsArray.size() - 1) {
            count++;
        }
        return count;
    }
    return 0;
}
 
Example 9
Source File: ChatAttachAlertContactsLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isEnabled(int section, int row) {
    if (section == 0 || section == getSectionCount() - 1) {
        return false;
    }
    section--;
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return row < usersSectionsDict.get(sortedUsersSectionsArray.get(section)).size();
}
 
Example 10
Source File: ChatAttachAlertContactsLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getCountForSection(int section) {
    if (section == 0 || section == getSectionCount() - 1) {
        return 1;
    }
    section--;
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    if (section < sortedUsersSectionsArray.size()) {
        return usersSectionsDict.get(sortedUsersSectionsArray.get(section)).size();
    }
    return 0;
}
 
Example 11
Source File: DialogsAdapter.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemCount() {
    ArrayList<TLRPC.Dialog> array = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
    int dialogsCount = array.size();
    if (dialogsType != 7 && dialogsType != 8 && dialogsCount == 0 && (folderId != 0 || MessagesController.getInstance(currentAccount).isLoadingDialogs(folderId))) {
        onlineContacts = null;
        if (folderId == 1 && showArchiveHint) {
            return (currentCount = 2);
        }
        return (currentCount = 0);
    }
    int count = dialogsCount;
    if (dialogsType == 7 || dialogsType == 8) {
        if (dialogsCount == 0) {
            count++;
        }
    } else {
        if (!MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId) || dialogsCount == 0) {
            count++;
        }
    }
    boolean hasContacts = false;
    if (hasHints) {
        count += 2 + MessagesController.getInstance(currentAccount).hintDialogs.size();
    } else if (dialogsType == 0 && dialogsCount == 0 && folderId == 0) {
        if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && ContactsController.getInstance(currentAccount).isLoadingContacts()) {
            onlineContacts = null;
            return (currentCount = 0);
        }

        if (!ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
            if (onlineContacts == null || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
                onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
                prevContactsCount = onlineContacts.size();
                int selfId = UserConfig.getInstance(currentAccount).clientUserId;
                for (int a = 0, N = onlineContacts.size(); a < N; a++) {
                    if (onlineContacts.get(a).user_id == selfId) {
                        onlineContacts.remove(a);
                        break;
                    }
                }
                sortOnlineContacts(false);
            }
            count += onlineContacts.size() + 2;
            hasContacts = true;
        }
    }
    if (!hasContacts && onlineContacts != null) {
        onlineContacts = null;
    }
    if (folderId == 1 && showArchiveHint) {
        count += 2;
    }
    if (folderId == 0 && dialogsCount != 0) {
        count++;
    }
    currentCount = count;
    return count;
}
 
Example 12
Source File: ChatAttachAlertContactsLayout.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getSectionCount() {
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return sortedUsersSectionsArray.size() + 2;
}
 
Example 13
Source File: DialogsAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemCount() {
    ArrayList<TLRPC.Dialog> array = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
    int dialogsCount = array.size();
    if (dialogsType != 7 && dialogsType != 8 && dialogsCount == 0 && (folderId != 0 || MessagesController.getInstance(currentAccount).isLoadingDialogs(folderId))) {
        onlineContacts = null;
        if (folderId == 1 && showArchiveHint) {
            return (currentCount = 2);
        }
        return (currentCount = 0);
    }
    int count = dialogsCount;
    if (dialogsType == 7 || dialogsType == 8) {
        if (dialogsCount == 0) {
            count++;
        }
    } else {
        if (!MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId) || dialogsCount == 0) {
            count++;
        }
    }
    boolean hasContacts = false;
    if (hasHints) {
        count += 2 + MessagesController.getInstance(currentAccount).hintDialogs.size();
    } else if (dialogsType == 0 && dialogsCount == 0 && folderId == 0) {
        if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && ContactsController.getInstance(currentAccount).isLoadingContacts()) {
            onlineContacts = null;
            return (currentCount = 0);
        }

        if (!ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
            if (onlineContacts == null || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
                onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
                prevContactsCount = onlineContacts.size();
                int selfId = UserConfig.getInstance(currentAccount).clientUserId;
                for (int a = 0, N = onlineContacts.size(); a < N; a++) {
                    if (onlineContacts.get(a).user_id == selfId) {
                        onlineContacts.remove(a);
                        break;
                    }
                }
                sortOnlineContacts(false);
            }
            count += onlineContacts.size() + 2;
            hasContacts = true;
        }
    }
    if (!hasContacts && onlineContacts != null) {
        onlineContacts = null;
    }
    if (folderId == 1 && showArchiveHint) {
        count += 2;
    }
    if (folderId == 0 && dialogsCount != 0) {
        count++;
    }
    currentCount = count;
    return count;
}
 
Example 14
Source File: PhonebookAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getSectionCount() {
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return sortedUsersSectionsArray.size();
}
 
Example 15
Source File: ContactsAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder)
{
    switch (holder.getItemViewType())
    {
        case 0:
            UserCell userCell = (UserCell) holder.itemView;
            HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).usersMutualSectionsDict : ContactsController.getInstance(currentAccount).usersSectionsDict;
            ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).sortedUsersMutualSectionsArray : ContactsController.getInstance(currentAccount).sortedUsersSectionsArray;

            ArrayList<TLRPC.TL_contact> arr = usersSectionsDict.get(sortedUsersSectionsArray.get(section - (onlyUsers != 0 && !isAdmin ? 0 : 1)));
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(arr.get(position).user_id);
            userCell.setData(user, null, null, 0);
            if (checkedMap != null)
            {
                userCell.setChecked(checkedMap.indexOfKey(user.id) >= 0, !scrolling);
            }
            if (ignoreUsers != null)
            {
                if (ignoreUsers.indexOfKey(user.id) >= 0)
                {
                    userCell.setAlpha(0.5f);
                }
                else
                {
                    userCell.setAlpha(1.0f);
                }
            }
            break;
        case 1:
            TextCell textCell = (TextCell) holder.itemView;
            if (section == 0)
            {
                if (needPhonebook)
                {
                    textCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite);
                }
                else if (isAdmin)
                {
                    textCell.setTextAndIcon(LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink), R.drawable.menu_invite);
                }
                else
                {
                    if (position == 0)
                    {
                        textCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup);
                    }
                    else if (position == 1)
                    {
                        textCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret);
                    }
                    else if (position == 2)
                    {
                        textCell.setTextAndIcon(LocaleController.getString("NewChannel", R.string.NewChannel), R.drawable.menu_broadcast);
                    }
                }
            }
            else
            {
                ContactsController.Contact contact = ContactsController.getInstance(currentAccount).phoneBookContacts.get(position);
                if (contact.first_name != null && contact.last_name != null)
                {
                    textCell.setText(contact.first_name + " " + contact.last_name);
                }
                else if (contact.first_name != null && contact.last_name == null)
                {
                    textCell.setText(contact.first_name);
                }
                else
                {
                    textCell.setText(contact.last_name);
                }
            }
            break;
    }
}
 
Example 16
Source File: PhonebookAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemViewType(int section, int position) {
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return position < usersSectionsDict.get(sortedUsersSectionsArray.get(section)).size() ? 0 : 1;
}
 
Example 17
Source File: PhonebookAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemViewType(int section, int position) {
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return position < usersSectionsDict.get(sortedUsersSectionsArray.get(section)).size() ? 0 : 1;
}
 
Example 18
Source File: ContactsAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder)
{
    switch (holder.getItemViewType())
    {
        case 0:
            UserCell userCell = (UserCell) holder.itemView;
            HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).usersMutualSectionsDict : ContactsController.getInstance(currentAccount).usersSectionsDict;
            ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).sortedUsersMutualSectionsArray : ContactsController.getInstance(currentAccount).sortedUsersSectionsArray;

            ArrayList<TLRPC.TL_contact> arr = usersSectionsDict.get(sortedUsersSectionsArray.get(section - (onlyUsers != 0 && !isAdmin ? 0 : 1)));
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(arr.get(position).user_id);
            userCell.setData(user, null, null, 0);
            if (checkedMap != null)
            {
                userCell.setChecked(checkedMap.indexOfKey(user.id) >= 0, !scrolling);
            }
            if (ignoreUsers != null)
            {
                if (ignoreUsers.indexOfKey(user.id) >= 0)
                {
                    userCell.setAlpha(0.5f);
                }
                else
                {
                    userCell.setAlpha(1.0f);
                }
            }
            break;
        case 1:
            TextCell textCell = (TextCell) holder.itemView;
            if (section == 0)
            {
                if (needPhonebook)
                {
                    textCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite);
                }
                else if (isAdmin)
                {
                    textCell.setTextAndIcon(LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink), R.drawable.menu_invite);
                }
                else
                {
                    if (position == 0)
                    {
                        textCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup);
                    }
                    else if (position == 1)
                    {
                        textCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret);
                    }
                    else if (position == 2)
                    {
                        textCell.setTextAndIcon(LocaleController.getString("NewChannel", R.string.NewChannel), R.drawable.menu_broadcast);
                    }
                }
            }
            else
            {
                ContactsController.Contact contact = ContactsController.getInstance(currentAccount).phoneBookContacts.get(position);
                if (contact.first_name != null && contact.last_name != null)
                {
                    textCell.setText(contact.first_name + " " + contact.last_name);
                }
                else if (contact.first_name != null && contact.last_name == null)
                {
                    textCell.setText(contact.first_name);
                }
                else
                {
                    textCell.setText(contact.last_name);
                }
            }
            break;
    }
}
 
Example 19
Source File: ContactsAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder) {
    switch (holder.getItemViewType()) {
        case 0:
            UserCell userCell = (UserCell) holder.itemView;
            userCell.setAvatarPadding(sortType == 2 || disableSections ? 6 : 58);
            ArrayList<TLRPC.TL_contact> arr;
            if (sortType == 2) {
                arr = onlineContacts;
            } else {
                HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).usersMutualSectionsDict : ContactsController.getInstance(currentAccount).usersSectionsDict;
                ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).sortedUsersMutualSectionsArray : ContactsController.getInstance(currentAccount).sortedUsersSectionsArray;
                arr = usersSectionsDict.get(sortedUsersSectionsArray.get(section - (onlyUsers != 0 && !isAdmin ? 0 : 1)));
            }
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(arr.get(position).user_id);
            userCell.setData(user, null, null, 0);
            if (checkedMap != null) {
                userCell.setChecked(checkedMap.indexOfKey(user.id) >= 0, !scrolling);
            }
            if (ignoreUsers != null) {
                if (ignoreUsers.indexOfKey(user.id) >= 0) {
                    userCell.setAlpha(0.5f);
                } else {
                    userCell.setAlpha(1.0f);
                }
            }
            break;
        case 1:
            TextCell textCell = (TextCell) holder.itemView;
            if (section == 0) {
                if (needPhonebook) {
                    if (position == 0) {
                        textCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite, false);
                    } else if (position == 1) {
                        textCell.setTextAndIcon(LocaleController.getString("AddPeopleNearby", R.string.AddPeopleNearby), R.drawable.menu_location, false);
                    }
                } else if (isAdmin) {
                    if (isChannel) {
                        textCell.setTextAndIcon(LocaleController.getString("ChannelInviteViaLink", R.string.ChannelInviteViaLink), R.drawable.profile_link, false);
                    } else {
                        textCell.setTextAndIcon(LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink), R.drawable.profile_link, false);
                    }
                } else {
                    if (position == 0) {
                        textCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_groups, false);
                    } else if (position == 1) {
                        textCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret, false);
                    } else if (position == 2) {
                        textCell.setTextAndIcon(LocaleController.getString("NewChannel", R.string.NewChannel), R.drawable.menu_broadcast, false);
                    }
                }
            } else {
                ContactsController.Contact contact = ContactsController.getInstance(currentAccount).phoneBookContacts.get(position);
                if (contact.first_name != null && contact.last_name != null) {
                    textCell.setText(contact.first_name + " " + contact.last_name, false);
                } else if (contact.first_name != null && contact.last_name == null) {
                    textCell.setText(contact.first_name, false);
                } else {
                    textCell.setText(contact.last_name, false);
                }
            }
            break;
        case 2:
            GraySectionCell sectionCell = (GraySectionCell) holder.itemView;
            if (sortType == 0) {
                sectionCell.setText(LocaleController.getString("Contacts", R.string.Contacts));
            } else if (sortType == 1) {
                sectionCell.setText(LocaleController.getString("SortedByName", R.string.SortedByName));
            } else {
                sectionCell.setText(LocaleController.getString("SortedByLastSeen", R.string.SortedByLastSeen));
            }
            break;
    }
}
 
Example 20
Source File: PhonebookAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isEnabled(int section, int row) {
    HashMap<String, ArrayList<Object>> usersSectionsDict = ContactsController.getInstance(currentAccount).phoneBookSectionsDict;
    ArrayList<String> sortedUsersSectionsArray = ContactsController.getInstance(currentAccount).phoneBookSectionsArray;
    return row < usersSectionsDict.get(sortedUsersSectionsArray.get(section)).size();
}