Search in sources :

Example 1 with PhoneBookContact

use of im.actor.core.entity.PhoneBookContact in project actor-platform by actorapp.

the class UserRouter method checkIsInPhoneBook.

@Verified
protected Promise<Void> checkIsInPhoneBook(User user) {
    if (!config().isEnableOnClientPrivacy()) {
        return Promise.success(null);
    }
    Log.d("ON_CLIENT_PRIVACY", "checking " + user.getName() + " is in phone book");
    return getPhoneBook().flatMap(new Function<List<PhoneBookContact>, Promise<Void>>() {

        @Override
        public Promise<Void> apply(List<PhoneBookContact> phoneBookContacts) {
            return new Promise<Void>(resolver -> {
                List<ContactRecord> userRecords = user.getRecords();
                Log.d("ON_CLIENT_PRIVACY", "phonebook have " + phoneBookContacts.size() + " records");
                Log.d("ON_CLIENT_PRIVACY", "user have " + userRecords.size() + " records");
                outer: for (ContactRecord record : userRecords) {
                    for (PhoneBookContact phoneBookContact : phoneBookContacts) {
                        for (PhoneBookPhone phone1 : phoneBookContact.getPhones()) {
                            if (record.getRecordType() == ContactRecordType.PHONE) {
                                if (record.getRecordData().equals(phone1.getNumber() + "")) {
                                    context().getContactsModule().markInPhoneBook(user.getUid());
                                    getUserVM(user.getUid()).isInPhoneBook().change(true);
                                    Log.d("ON_CLIENT_PRIVACY", "in record book!");
                                    break outer;
                                }
                            }
                        }
                        for (PhoneBookEmail email : phoneBookContact.getEmails()) {
                            if (record.getRecordType() == ContactRecordType.EMAIL) {
                                if (record.getRecordData().equals(email.getEmail())) {
                                    context().getContactsModule().markInPhoneBook(user.getUid());
                                    getUserVM(user.getUid()).isInPhoneBook().change(true);
                                    Log.d("ON_CLIENT_PRIVACY", "in record book!");
                                    break outer;
                                }
                            }
                        }
                    }
                }
                Log.d("ON_CLIENT_PRIVACY", "finish check");
                resolver.result(null);
            });
        }
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) ContactRecord(im.actor.core.entity.ContactRecord) PhoneBookContact(im.actor.core.entity.PhoneBookContact) ApiUser(im.actor.core.api.ApiUser) UpdateUserContactsChanged(im.actor.core.api.updates.UpdateUserContactsChanged) ApiMapValue(im.actor.core.api.ApiMapValue) ApiBotCommand(im.actor.core.api.ApiBotCommand) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) PromisesArray(im.actor.runtime.promise.PromisesArray) RouterLoadFullUser(im.actor.core.modules.users.router.entity.RouterLoadFullUser) UpdateContactRegistered(im.actor.core.api.updates.UpdateContactRegistered) UpdateUserNameChanged(im.actor.core.api.updates.UpdateUserNameChanged) ContactRecordType(im.actor.core.entity.ContactRecordType) Tuple2(im.actor.runtime.function.Tuple2) UpdateUserBlocked(im.actor.core.api.updates.UpdateUserBlocked) Void(im.actor.runtime.actors.messages.Void) Verified(im.actor.runtime.annotations.Verified) UserPhone(im.actor.core.viewmodel.UserPhone) ResponseLoadFullUsers(im.actor.core.api.rpc.ResponseLoadFullUsers) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) List(java.util.List) UpdateUserAboutChanged(im.actor.core.api.updates.UpdateUserAboutChanged) ModuleActor(im.actor.core.modules.ModuleActor) ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) UpdateUserFullExtChanged(im.actor.core.api.updates.UpdateUserFullExtChanged) UserEmail(im.actor.core.viewmodel.UserEmail) Peer(im.actor.core.entity.Peer) UpdateUserExtChanged(im.actor.core.api.updates.UpdateUserExtChanged) MessageState(im.actor.core.entity.MessageState) Message(im.actor.core.entity.Message) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ApiAvatar(im.actor.core.api.ApiAvatar) ApiContactRecord(im.actor.core.api.ApiContactRecord) UpdateUserTimeZoneChanged(im.actor.core.api.updates.UpdateUserTimeZoneChanged) Function(im.actor.runtime.function.Function) ServiceUserRegistered(im.actor.core.entity.content.ServiceUserRegistered) PhoneBookProvider(im.actor.core.providers.PhoneBookProvider) Promise(im.actor.runtime.promise.Promise) UpdateUserBotCommandsChanged(im.actor.core.api.updates.UpdateUserBotCommandsChanged) UpdateUserNickChanged(im.actor.core.api.updates.UpdateUserNickChanged) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) User(im.actor.core.entity.User) UpdateUserLocalNameChanged(im.actor.core.api.updates.UpdateUserLocalNameChanged) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) JavaUtil.equalsE(im.actor.core.util.JavaUtil.equalsE) UpdateUserUnblocked(im.actor.core.api.updates.UpdateUserUnblocked) RequestLoadFullUsers(im.actor.core.api.rpc.RequestLoadFullUsers) ContactsSyncActor(im.actor.core.modules.contacts.ContactsSyncActor) UserVM(im.actor.core.viewmodel.UserVM) RouterFetchMissingUsers(im.actor.core.modules.users.router.entity.RouterFetchMissingUsers) BookImportStorage(im.actor.core.modules.contacts.entity.BookImportStorage) RouterApplyUsers(im.actor.core.modules.users.router.entity.RouterApplyUsers) UpdateUserPreferredLanguagesChanged(im.actor.core.api.updates.UpdateUserPreferredLanguagesChanged) Log(im.actor.runtime.Log) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) Update(im.actor.core.network.parser.Update) RouterUserUpdate(im.actor.core.modules.users.router.entity.RouterUserUpdate) Promise(im.actor.runtime.promise.Promise) PhoneBookContact(im.actor.core.entity.PhoneBookContact) List(java.util.List) ArrayList(java.util.ArrayList) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) Void(im.actor.runtime.actors.messages.Void) ContactRecord(im.actor.core.entity.ContactRecord) ApiContactRecord(im.actor.core.api.ApiContactRecord) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) Verified(im.actor.runtime.annotations.Verified)

Example 2 with PhoneBookContact

use of im.actor.core.entity.PhoneBookContact in project actor-platform by actorapp.

the class InviteAdapter method onBindViewHolder.

@Override
protected void onBindViewHolder(ViewHolder<PhoneBookContact> holder, PhoneBookContact obj, int index, Context context) {
    PhoneBookContact item = phoneBook.get(index);
    String fastName = null;
    if (index == 0) {
        fastName = messenger().getFormatter().formatFastName(item.getName());
    } else {
        String prevName = messenger().getFormatter().formatFastName(phoneBook.get(index - 1).getName());
        String currentFastName = messenger().getFormatter().formatFastName(item.getName());
        if (!prevName.equals(currentFastName)) {
            fastName = currentFastName;
        }
    }
    Integer type = selectedContactType.get(item);
    ((InviteContactHolder) holder).bind(item, fastName, "", selectedUsers.contains(item), type == null ? -1 : type, index == getCount() - 1);
}
Also used : PhoneBookContact(im.actor.core.entity.PhoneBookContact)

Example 3 with PhoneBookContact

use of im.actor.core.entity.PhoneBookContact in project actor-platform by actorapp.

the class InviteFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View res = inflater.inflate(R.layout.fragment_list, container, false);
    res.findViewById(R.id.listView).setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    emptyText = (TextView) res.findViewById(R.id.emptyView);
    emptyText.setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    emptyText.setText(R.string.progress_common);
    collection = (RecyclerListView) res.findViewById(R.id.listView);
    AndroidPhoneBook phoneBookLoader = new AndroidPhoneBook();
    phoneBookLoader.useDelay(false);
    res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    phoneBookLoader.loadPhoneBook(contacts -> {
        if (contacts.size() > 0) {
            getActivity().runOnUiThread(() -> {
                InviteFragment.this.contacts = contacts;
                adapter = new InviteAdapter(getActivity(), contacts, new OnItemClickedListener<PhoneBookContact>() {

                    @Override
                    public void onClicked(PhoneBookContact item) {
                        onItemClicked(item);
                    }

                    @Override
                    public boolean onLongClicked(PhoneBookContact item) {
                        return false;
                    }
                });
                collection.setAdapter(adapter);
                hideView(emptyText);
                showView(collection);
                showMenu();
            });
        }
    });
    return res;
}
Also used : PhoneBookContact(im.actor.core.entity.PhoneBookContact) OnItemClickedListener(im.actor.sdk.view.adapters.OnItemClickedListener) TextView(android.widget.TextView) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) AndroidPhoneBook(im.actor.sdk.core.AndroidPhoneBook)

Example 4 with PhoneBookContact

use of im.actor.core.entity.PhoneBookContact in project actor-platform by actorapp.

the class BookImportActor method onPhoneBookLoaded.

private void onPhoneBookLoaded(List<PhoneBookContact> phoneBook) {
    phoneBookReadingIsInProgress = false;
    if (ENABLE_LOG) {
        Log.d(TAG, "Book load completed");
    }
    int newPhones = 0;
    int newEmails = 0;
    for (PhoneBookContact record : phoneBook) {
        for (PhoneBookPhone phone : record.getPhones()) {
            if (storage.isImported(phone.getNumber())) {
                continue;
            }
            if (importingPhones.contains(phone.getNumber())) {
                continue;
            }
            importingPhones.add(phone.getNumber());
            importQueue.add(new ImportPhoneQueueItem(phone.getNumber(), record.getName()));
            newPhones++;
        }
        for (PhoneBookEmail email : record.getEmails()) {
            if (storage.isImported(email.getEmail().toLowerCase())) {
                continue;
            }
            if (importingEmails.contains(email.getEmail().toLowerCase())) {
                continue;
            }
            importingEmails.add(email.getEmail().toLowerCase());
            importQueue.add(new ImportEmailQueueItem(email.getEmail().toLowerCase(), record.getName()));
            newEmails++;
        }
    }
    if (ENABLE_LOG) {
        if (newPhones == 0 && newEmails == 0) {
            Log.d(TAG, "No new contacts found");
        } else {
            Log.d(TAG, "Founded new " + (newPhones + newEmails) + " contact records");
        }
    }
    performImportIfRequired();
}
Also used : PhoneBookContact(im.actor.core.entity.PhoneBookContact) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone)

Example 5 with PhoneBookContact

use of im.actor.core.entity.PhoneBookContact in project actor-platform by actorapp.

the class InviteFragment method sendInvites.

private void sendInvites() {
    ArrayList<Long> phones = new ArrayList<Long>();
    ArrayList<String> emails = new ArrayList<String>();
    PhoneBookContact[] selected = getAdapter().getSelected();
    HashMap<PhoneBookContact, Integer> selectedTypes = getAdapter().getSelectedContactsTypes();
    Integer selectedType;
    // Prepare email/phones lists
    String phoneNumbersStrings = "";
    String emailsString = "";
    String email;
    long number;
    for (PhoneBookContact contact : selected) {
        selectedType = selectedTypes.get(contact);
        selectedType = selectedType != null ? selectedType : InviteContactHolder.TYPE_PHONE;
        if ((selectedType == InviteContactHolder.TYPE_EMAIL && contact.getEmails().size() > 0) || contact.getPhones().size() == 0) {
            email = contact.getEmails().get(0).getEmail();
            emails.add(email);
            emailsString += email + ";";
        } else {
            number = contact.getPhones().get(0).getNumber();
            phones.add(number);
            phoneNumbersStrings += number + ";";
        }
    }
    String inviteMessage = getResources().getString(R.string.invite_message).replace("{inviteUrl}", ActorSDK.sharedActor().getInviteUrl()).replace("{appName}", ActorSDK.sharedActor().getAppName());
    if (phones.size() > 0 && emails.size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        String[] options = new String[] { getString(R.string.invite_options_sms), getString(R.string.invite_options_email) };
        final String finalPhoneNumbersStrings = phoneNumbersStrings;
        final String finalEmailsString = emailsString;
        builder.setItems(options, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == 0) {
                    sendSmsInvites(finalPhoneNumbersStrings, inviteMessage);
                } else {
                    sendEmailInvites(finalEmailsString, inviteMessage);
                }
                dialog.dismiss();
            }
        }).show();
    } else if (phones.size() > 0) {
        sendSmsInvites(phoneNumbersStrings, inviteMessage);
    } else {
        sendEmailInvites(emailsString, inviteMessage);
    }
// SmsManager smsManager = SmsManager.getDefault();
// smsManager.sendTextMessage(phoneNumbers, null, inviteMessage, null, null);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) PhoneBookContact(im.actor.core.entity.PhoneBookContact) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList)

Aggregations

PhoneBookContact (im.actor.core.entity.PhoneBookContact)6 PhoneBookEmail (im.actor.core.entity.PhoneBookEmail)3 PhoneBookPhone (im.actor.core.entity.PhoneBookPhone)3 ArrayList (java.util.ArrayList)2 ContentResolver (android.content.ContentResolver)1 DialogInterface (android.content.DialogInterface)1 Cursor (android.database.Cursor)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 TextView (android.widget.TextView)1 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)1 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)1 ApiAvatar (im.actor.core.api.ApiAvatar)1 ApiBotCommand (im.actor.core.api.ApiBotCommand)1 ApiContactRecord (im.actor.core.api.ApiContactRecord)1 ApiMapValue (im.actor.core.api.ApiMapValue)1 ApiUser (im.actor.core.api.ApiUser)1 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)1 RequestLoadFullUsers (im.actor.core.api.rpc.RequestLoadFullUsers)1 ResponseLoadFullUsers (im.actor.core.api.rpc.ResponseLoadFullUsers)1