Java Code Examples for org.telegram.tgnet.TLRPC#TL_contact

The following examples show how to use org.telegram.tgnet.TLRPC#TL_contact . 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: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int getContactsHash(ArrayList<TLRPC.TL_contact> contacts) {
    long acc = 0;
    contacts = new ArrayList<>(contacts);
    Collections.sort(contacts, new Comparator<TLRPC.TL_contact>() {
        @Override
        public int compare(TLRPC.TL_contact tl_contact, TLRPC.TL_contact tl_contact2) {
            if (tl_contact.user_id > tl_contact2.user_id) {
                return 1;
            } else if (tl_contact.user_id < tl_contact2.user_id) {
                return -1;
            }
            return 0;
        }
    });
    int count = contacts.size();
    for (int a = -1; a < count; a++) {
        if (a == -1) {
            acc = ((acc * 20261) + 0x80000000L + UserConfig.getInstance(currentAccount).contactsSavedCount) % 0x80000000L;
        } else {
            TLRPC.TL_contact set = contacts.get(a);
            acc = ((acc * 20261) + 0x80000000L + set.user_id) % 0x80000000L;
        }
    }
    return (int) acc;
}
 
Example 2
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int getContactsHash(ArrayList<TLRPC.TL_contact> contacts) {
    long acc = 0;
    contacts = new ArrayList<>(contacts);
    Collections.sort(contacts, new Comparator<TLRPC.TL_contact>() {
        @Override
        public int compare(TLRPC.TL_contact tl_contact, TLRPC.TL_contact tl_contact2) {
            if (tl_contact.user_id > tl_contact2.user_id) {
                return 1;
            } else if (tl_contact.user_id < tl_contact2.user_id) {
                return -1;
            }
            return 0;
        }
    });
    int count = contacts.size();
    for (int a = -1; a < count; a++) {
        if (a == -1) {
            acc = ((acc * 20261) + 0x80000000L + UserConfig.getInstance(currentAccount).contactsSavedCount) % 0x80000000L;
        } else {
            TLRPC.TL_contact set = contacts.get(a);
            acc = ((acc * 20261) + 0x80000000L + set.user_id) % 0x80000000L;
        }
    }
    return (int) acc;
}
 
Example 3
Source File: ContactsController.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private int getContactsHash(ArrayList<TLRPC.TL_contact> contacts) {
    long acc = 0;
    contacts = new ArrayList<>(contacts);
    Collections.sort(contacts, (tl_contact, tl_contact2) -> {
        if (tl_contact.user_id > tl_contact2.user_id) {
            return 1;
        } else if (tl_contact.user_id < tl_contact2.user_id) {
            return -1;
        }
        return 0;
    });
    int count = contacts.size();
    for (int a = -1; a < count; a++) {
        if (a == -1) {
            acc = ((acc * 20261) + 0x80000000L + getUserConfig().contactsSavedCount) % 0x80000000L;
        } else {
            TLRPC.TL_contact set = contacts.get(a);
            acc = ((acc * 20261) + 0x80000000L + set.user_id) % 0x80000000L;
        }
    }
    return (int) acc;
}
 
Example 4
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private int getContactsHash(ArrayList<TLRPC.TL_contact> contacts) {
    long acc = 0;
    contacts = new ArrayList<>(contacts);
    Collections.sort(contacts, (tl_contact, tl_contact2) -> {
        if (tl_contact.user_id > tl_contact2.user_id) {
            return 1;
        } else if (tl_contact.user_id < tl_contact2.user_id) {
            return -1;
        }
        return 0;
    });
    int count = contacts.size();
    for (int a = -1; a < count; a++) {
        if (a == -1) {
            acc = ((acc * 20261) + 0x80000000L + getUserConfig().contactsSavedCount) % 0x80000000L;
        } else {
            TLRPC.TL_contact set = contacts.get(a);
            acc = ((acc * 20261) + 0x80000000L + set.user_id) % 0x80000000L;
        }
    }
    return (int) acc;
}
 
Example 5
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
    Cursor cursor = null;
    try {
        if (!hasContactsPermission()) {
            return;
        }
        Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, systemAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, systemAccount.type).build();
        cursor = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
        SparseLongArray bookContacts = new SparseLongArray();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                bookContacts.put(cursor.getInt(1), cursor.getLong(0));
            }
            cursor.close();
            cursor = null;

            for (int a = 0; a < contactsArray.size(); a++) {
                TLRPC.TL_contact u = contactsArray.get(a);
                if (bookContacts.indexOfKey(u.user_id) < 0) {
                    TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(u.user_id);
                    addContactToPhoneBook(user, false);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 6
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void performWriteContactsToPhoneBook() {
    final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<>(contacts);
    Utilities.phoneBookQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            performWriteContactsToPhoneBookInternal(contactsArray);
        }
    });
}
 
Example 7
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
    Cursor cursor = null;
    try {
        if (!hasContactsPermission()) {
            return;
        }
        Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, systemAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, systemAccount.type).build();
        cursor = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
        SparseLongArray bookContacts = new SparseLongArray();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                bookContacts.put(cursor.getInt(1), cursor.getLong(0));
            }
            cursor.close();
            cursor = null;

            for (int a = 0; a < contactsArray.size(); a++) {
                TLRPC.TL_contact u = contactsArray.get(a);
                if (bookContacts.indexOfKey(u.user_id) < 0) {
                    TLRPC.User user = getMessagesController().getUser(u.user_id);
                    addContactToPhoneBook(user, false);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 8
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
    Cursor cursor = null;
    try {
        if (!hasContactsPermission()) {
            return;
        }
        Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, systemAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, systemAccount.type).build();
        cursor = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
        SparseLongArray bookContacts = new SparseLongArray();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                bookContacts.put(cursor.getInt(1), cursor.getLong(0));
            }
            cursor.close();
            cursor = null;

            for (int a = 0; a < contactsArray.size(); a++) {
                TLRPC.TL_contact u = contactsArray.get(a);
                if (bookContacts.indexOfKey(u.user_id) < 0) {
                    TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(u.user_id);
                    addContactToPhoneBook(user, false);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 9
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void performWriteContactsToPhoneBook() {
    final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<>(contacts);
    Utilities.phoneBookQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            performWriteContactsToPhoneBookInternal(contactsArray);
        }
    });
}
 
Example 10
Source File: ContactsController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
    Cursor cursor = null;
    try {
        if (!hasContactsPermission()) {
            return;
        }
        Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, systemAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, systemAccount.type).build();
        cursor = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
        SparseLongArray bookContacts = new SparseLongArray();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                bookContacts.put(cursor.getInt(1), cursor.getLong(0));
            }
            cursor.close();
            cursor = null;

            for (int a = 0; a < contactsArray.size(); a++) {
                TLRPC.TL_contact u = contactsArray.get(a);
                if (bookContacts.indexOfKey(u.user_id) < 0) {
                    TLRPC.User user = getMessagesController().getUser(u.user_id);
                    addContactToPhoneBook(user, false);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 11
Source File: ContactsAdapter.java    From Telegram 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 12
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void performWriteContactsToPhoneBook() {
    final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<>(contacts);
    Utilities.phoneBookQueue.postRunnable(() -> performWriteContactsToPhoneBookInternal(contactsArray));
}
 
Example 13
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void buildContactsSectionsArrays(boolean sort) {
    if (sort) {
        Collections.sort(contacts, (tl_contact, tl_contact2) -> {
            TLRPC.User user1 = getMessagesController().getUser(tl_contact.user_id);
            TLRPC.User user2 = getMessagesController().getUser(tl_contact2.user_id);
            String name1 = UserObject.getFirstName(user1);
            String name2 = UserObject.getFirstName(user2);
            return name1.compareTo(name2);
        });
    }

    final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
    final ArrayList<String> sortedSectionsArray = new ArrayList<>();

    for (int a = 0; a < contacts.size(); a++) {
        TLRPC.TL_contact value = contacts.get(a);
        TLRPC.User user = getMessagesController().getUser(value.user_id);
        if (user == null) {
            continue;
        }

        String key = UserObject.getFirstName(user);
        if (key.length() > 1) {
            key = key.substring(0, 1);
        }
        if (key.length() == 0) {
            key = "#";
        } else {
            key = key.toUpperCase();
        }
        String replace = sectionsToReplace.get(key);
        if (replace != null) {
            key = replace;
        }
        ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
        if (arr == null) {
            arr = new ArrayList<>();
            sectionsDict.put(key, arr);
            sortedSectionsArray.add(key);
        }
        arr.add(value);
    }

    Collections.sort(sortedSectionsArray, (s, s2) -> {
        char cv1 = s.charAt(0);
        char cv2 = s2.charAt(0);
        if (cv1 == '#') {
            return 1;
        } else if (cv2 == '#') {
            return -1;
        }
        return s.compareTo(s2);
    });

    usersSectionsDict = sectionsDict;
    sortedUsersSectionsArray = sortedSectionsArray;
}
 
Example 14
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 15
Source File: ContactsController.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void performWriteContactsToPhoneBook() {
    final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<>(contacts);
    Utilities.phoneBookQueue.postRunnable(() -> performWriteContactsToPhoneBookInternal(contactsArray));
}
 
Example 16
Source File: ContactsController.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void buildContactsSectionsArrays(boolean sort) {
    if (sort) {
        Collections.sort(contacts, (tl_contact, tl_contact2) -> {
            TLRPC.User user1 = getMessagesController().getUser(tl_contact.user_id);
            TLRPC.User user2 = getMessagesController().getUser(tl_contact2.user_id);
            String name1 = UserObject.getFirstName(user1);
            String name2 = UserObject.getFirstName(user2);
            return name1.compareTo(name2);
        });
    }

    final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
    final ArrayList<String> sortedSectionsArray = new ArrayList<>();

    for (int a = 0; a < contacts.size(); a++) {
        TLRPC.TL_contact value = contacts.get(a);
        TLRPC.User user = getMessagesController().getUser(value.user_id);
        if (user == null) {
            continue;
        }

        String key = UserObject.getFirstName(user);
        if (key.length() > 1) {
            key = key.substring(0, 1);
        }
        if (key.length() == 0) {
            key = "#";
        } else {
            key = key.toUpperCase();
        }
        String replace = sectionsToReplace.get(key);
        if (replace != null) {
            key = replace;
        }
        ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
        if (arr == null) {
            arr = new ArrayList<>();
            sectionsDict.put(key, arr);
            sortedSectionsArray.add(key);
        }
        arr.add(value);
    }

    Collections.sort(sortedSectionsArray, (s, s2) -> {
        char cv1 = s.charAt(0);
        char cv2 = s2.charAt(0);
        if (cv1 == '#') {
            return 1;
        } else if (cv2 == '#') {
            return -1;
        }
        return s.compareTo(s2);
    });

    usersSectionsDict = sectionsDict;
    sortedUsersSectionsArray = sortedSectionsArray;
}
 
Example 17
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 18
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void buildContactsSectionsArrays(boolean sort) {
    if (sort) {
        Collections.sort(contacts, new Comparator<TLRPC.TL_contact>() {
            @Override
            public int compare(TLRPC.TL_contact tl_contact, TLRPC.TL_contact tl_contact2) {
                TLRPC.User user1 = MessagesController.getInstance(currentAccount).getUser(tl_contact.user_id);
                TLRPC.User user2 = MessagesController.getInstance(currentAccount).getUser(tl_contact2.user_id);
                String name1 = UserObject.getFirstName(user1);
                String name2 = UserObject.getFirstName(user2);
                return name1.compareTo(name2);
            }
        });
    }

    final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
    final ArrayList<String> sortedSectionsArray = new ArrayList<>();

    for (int a = 0; a < contacts.size(); a++) {
        TLRPC.TL_contact value = contacts.get(a);
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(value.user_id);
        if (user == null) {
            continue;
        }

        String key = UserObject.getFirstName(user);
        if (key.length() > 1) {
            key = key.substring(0, 1);
        }
        if (key.length() == 0) {
            key = "#";
        } else {
            key = key.toUpperCase();
        }
        String replace = sectionsToReplace.get(key);
        if (replace != null) {
            key = replace;
        }
        ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
        if (arr == null) {
            arr = new ArrayList<>();
            sectionsDict.put(key, arr);
            sortedSectionsArray.add(key);
        }
        arr.add(value);
    }

    Collections.sort(sortedSectionsArray, new Comparator<String>() {
        @Override
        public int compare(String s, String s2) {
            char cv1 = s.charAt(0);
            char cv2 = s2.charAt(0);
            if (cv1 == '#') {
                return 1;
            } else if (cv2 == '#') {
                return -1;
            }
            return s.compareTo(s2);
        }
    });

    usersSectionsDict = sectionsDict;
    sortedUsersSectionsArray = sortedSectionsArray;
}
 
Example 19
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 20
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void buildContactsSectionsArrays(boolean sort) {
    if (sort) {
        Collections.sort(contacts, new Comparator<TLRPC.TL_contact>() {
            @Override
            public int compare(TLRPC.TL_contact tl_contact, TLRPC.TL_contact tl_contact2) {
                TLRPC.User user1 = MessagesController.getInstance(currentAccount).getUser(tl_contact.user_id);
                TLRPC.User user2 = MessagesController.getInstance(currentAccount).getUser(tl_contact2.user_id);
                String name1 = UserObject.getFirstName(user1);
                String name2 = UserObject.getFirstName(user2);
                return name1.compareTo(name2);
            }
        });
    }

    final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
    final ArrayList<String> sortedSectionsArray = new ArrayList<>();

    for (int a = 0; a < contacts.size(); a++) {
        TLRPC.TL_contact value = contacts.get(a);
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(value.user_id);
        if (user == null) {
            continue;
        }

        String key = UserObject.getFirstName(user);
        if (key.length() > 1) {
            key = key.substring(0, 1);
        }
        if (key.length() == 0) {
            key = "#";
        } else {
            key = key.toUpperCase();
        }
        String replace = sectionsToReplace.get(key);
        if (replace != null) {
            key = replace;
        }
        ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
        if (arr == null) {
            arr = new ArrayList<>();
            sectionsDict.put(key, arr);
            sortedSectionsArray.add(key);
        }
        arr.add(value);
    }

    Collections.sort(sortedSectionsArray, new Comparator<String>() {
        @Override
        public int compare(String s, String s2) {
            char cv1 = s.charAt(0);
            char cv2 = s2.charAt(0);
            if (cv1 == '#') {
                return 1;
            } else if (cv2 == '#') {
                return -1;
            }
            return s.compareTo(s2);
        }
    });

    usersSectionsDict = sectionsDict;
    sortedUsersSectionsArray = sortedSectionsArray;
}