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);
});
}
});
}
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);
}
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;
}
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();
}
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);
}
Aggregations