use of im.actor.core.viewmodel.UserPhone in project actor-platform by actorapp.
the class ProfileFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
uid = getArguments().getInt(EXTRA_UID);
final UserVM user = users().get(uid);
ArrayList<UserPhone> phones = user.getPhones().get();
ArrayList<UserEmail> emails = user.getEmails().get();
String about = user.getAbout().get();
final String userName = user.getNick().get();
final View res = inflater.inflate(R.layout.fragment_profile, container, false);
//
// Style Background
//
res.findViewById(R.id.container).setBackgroundColor(style.getMainBackgroundColor());
res.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
//
// User Avatar
//
avatarView = (AvatarView) res.findViewById(R.id.avatar);
avatarView.init(Screen.dp(48), 22);
avatarView.bind(user.getAvatar().get(), user.getName().get(), user.getId());
avatarView.setOnClickListener(v -> {
startActivity(ViewAvatarActivity.viewAvatar(user.getId(), getActivity()));
});
//
// User Name
//
TextView nameText = (TextView) res.findViewById(R.id.name);
nameText.setTextColor(style.getProfileTitleColor());
bind(nameText, user.getName());
//
// User Last Seen
//
TextView lastSeen = (TextView) res.findViewById(R.id.lastSeen);
lastSeen.setTextColor(style.getProfileSubtitleColor());
bind(lastSeen, user);
//
// Fab
//
FloatingActionButton fab = (FloatingActionButton) res.findViewById(R.id.fab);
fab.setBackgroundTintList(new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, StateSet.WILD_CARD }, new int[] { ActorSDK.sharedActor().style.getFabPressedColor(), ActorSDK.sharedActor().style.getFabColor() }));
fab.setRippleColor(ActorSDK.sharedActor().style.getFabPressedColor());
fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), ComposeActivity.class)));
//
// Remove Contact
//
final View removeContact = res.findViewById(R.id.addContact);
final TextView addContactTitle = (TextView) removeContact.findViewById(R.id.addContactTitle);
addContactTitle.setText(getString(R.string.profile_contacts_added));
addContactTitle.setTextColor(style.getTextPrimaryColor());
removeContact.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().removeContact(user.getId()));
});
bind(user.isContact(), (isContact, valueModel) -> {
if (isContact) {
removeContact.setVisibility(View.VISIBLE);
//fab
fab.setImageResource(R.drawable.ic_message_white_24dp);
fab.setOnClickListener(view -> startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity())));
} else {
removeContact.setVisibility(View.GONE);
//fab
fab.setImageResource(R.drawable.ic_person_add_white_24dp);
fab.setOnClickListener(view -> execute(ActorSDK.sharedActor().getMessenger().addContact(user.getId())));
}
});
//
// New Message
//
View newMessageView = res.findViewById(R.id.newMessage);
ImageView newMessageIcon = (ImageView) newMessageView.findViewById(R.id.newMessageIcon);
TextView newMessageTitle = (TextView) newMessageView.findViewById(R.id.newMessageText);
{
Drawable drawable = getResources().getDrawable(R.drawable.ic_chat_black_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
newMessageIcon.setImageDrawable(drawable);
newMessageTitle.setTextColor(style.getTextPrimaryColor());
}
newMessageView.setOnClickListener(v -> {
startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity()));
});
//
// Voice Call
//
View voiceCallDivider = res.findViewById(R.id.voiceCallDivider);
View voiceCallView = res.findViewById(R.id.voiceCall);
if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
ImageView voiceViewIcon = (ImageView) voiceCallView.findViewById(R.id.actionIcon);
TextView voiceViewTitle = (TextView) voiceCallView.findViewById(R.id.actionText);
Drawable drawable = getResources().getDrawable(R.drawable.ic_phone_white_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
voiceViewIcon.setImageDrawable(drawable);
voiceViewTitle.setTextColor(style.getTextPrimaryColor());
voiceCallView.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().doCall(user.getId()));
});
} else {
voiceCallView.setVisibility(View.GONE);
voiceCallDivider.setVisibility(View.GONE);
}
//
// Video Call
//
View videoCallDivider = res.findViewById(R.id.videoCallDivider);
View videoCallView = res.findViewById(R.id.videoCall);
if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
ImageView voiceViewIcon = (ImageView) videoCallView.findViewById(R.id.videoCallIcon);
TextView voiceViewTitle = (TextView) videoCallView.findViewById(R.id.videoCallText);
Drawable drawable = getResources().getDrawable(R.drawable.ic_videocam_white_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
voiceViewIcon.setImageDrawable(drawable);
voiceViewTitle.setTextColor(style.getTextPrimaryColor());
videoCallView.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().doVideoCall(user.getId()));
});
} else {
videoCallView.setVisibility(View.GONE);
videoCallDivider.setVisibility(View.GONE);
}
//
// Contact Information
//
final LinearLayout contactsContainer = (LinearLayout) res.findViewById(R.id.contactsContainer);
String aboutString = user.getAbout().get();
boolean isFirstContact = aboutString == null || aboutString.isEmpty();
//
// About
//
bind(user.getAbout(), new ValueChangedListener<String>() {
private View userAboutRecord;
@Override
public void onChanged(final String newUserAbout, Value<String> valueModel) {
if (newUserAbout != null && newUserAbout.length() > 0) {
if (userAboutRecord == null) {
userAboutRecord = buildRecordBig(newUserAbout, R.drawable.ic_info_outline_black_24dp, true, false, inflater, contactsContainer);
} else {
((TextView) userAboutRecord.findViewById(R.id.value)).setText(newUserAbout);
}
if (recordFieldWithIcon != null) {
recordFieldWithIcon.findViewById(R.id.recordIcon).setVisibility(View.INVISIBLE);
}
}
}
});
if (!ActorSDK.sharedActor().isOnClientPrivacyEnabled() || user.isInPhoneBook().get()) {
for (int i = 0; i < phones.size(); i++) {
final UserPhone userPhone = phones.get(i);
// Formatting Phone Number
String _phoneNumber;
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + userPhone.getPhone(), "us");
_phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
_phoneNumber = "+" + userPhone.getPhone();
}
final String phoneNumber = _phoneNumber;
String phoneTitle = userPhone.getTitle();
// Trying to localize this
if (phoneTitle.toLowerCase().equals("mobile phone")) {
phoneTitle = getString(R.string.settings_mobile_phone);
}
View view = buildRecord(phoneTitle, phoneNumber, R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
if (isFirstContact) {
recordFieldWithIcon = view;
}
view.setOnClickListener(v -> {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.phone_menu_call).replace("{0}", phoneNumber), getString(R.string.phone_menu_sms).replace("{0}", phoneNumber), getString(R.string.phone_menu_share).replace("{0}", phoneNumber), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + userPhone.getPhone())));
} else if (which == 1) {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + userPhone.getPhone())));
} else if (which == 2) {
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text).replace("{0}", phoneNumber).replace("{1}", user.getName().get())));
} else if (which == 3) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
}
}).show().setCanceledOnTouchOutside(true);
});
view.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", "+" + userPhone.getPhone());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
isFirstContact = false;
}
for (int i = 0; i < emails.size(); i++) {
final UserEmail userEmail = emails.get(i);
View view = buildRecord(userEmail.getTitle(), userEmail.getEmail(), R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
if (isFirstContact) {
recordFieldWithIcon = view;
}
view.setOnClickListener(v -> {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", userEmail.getEmail()), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", userEmail.getEmail(), null)));
} else if (which == 1) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", userEmail.getEmail());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
}
}).show().setCanceledOnTouchOutside(true);
});
view.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", "+" + userEmail.getEmail());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
isFirstContact = false;
}
}
//
// Username
//
final boolean finalIsFirstContact = isFirstContact;
bind(user.getNick(), new ValueChangedListener<String>() {
private View userNameRecord;
@Override
public void onChanged(final String newUserName, Value<String> valueModel) {
if (newUserName != null && newUserName.length() > 0) {
if (userNameRecord == null) {
userNameRecord = buildRecord(getString(R.string.nickname), "@" + newUserName, R.drawable.ic_import_contacts_black_24dp, finalIsFirstContact, false, inflater, contactsContainer);
} else {
((TextView) userNameRecord.findViewById(R.id.value)).setText(newUserName);
}
userNameRecord.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Username", newUserName);
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_nickname_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
if (finalIsFirstContact) {
recordFieldWithIcon = userNameRecord;
}
}
}
});
//
// Settings
//
{
//
// Notifications
//
View notificationContainer = res.findViewById(R.id.notificationsCont);
View notificationPickerContainer = res.findViewById(R.id.notificationsPickerCont);
((TextView) notificationContainer.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
final SwitchCompat notificationEnable = (SwitchCompat) res.findViewById(R.id.enableNotifications);
Peer peer = Peer.user(user.getId());
notificationEnable.setChecked(messenger().isNotificationsEnabled(peer));
if (messenger().isNotificationsEnabled(peer)) {
ViewUtils.showView(notificationPickerContainer, false);
} else {
ViewUtils.goneView(notificationPickerContainer, false);
}
notificationEnable.setOnCheckedChangeListener((buttonView, isChecked) -> {
messenger().changeNotificationsEnabled(Peer.user(user.getId()), isChecked);
if (isChecked) {
ViewUtils.showView(notificationPickerContainer, false);
} else {
ViewUtils.goneView(notificationPickerContainer, false);
}
});
notificationContainer.setOnClickListener(v -> notificationEnable.setChecked(!notificationEnable.isChecked()));
ImageView iconView = (ImageView) res.findViewById(R.id.settings_notification_icon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_list_black_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
iconView.setImageDrawable(drawable);
((TextView) notificationPickerContainer.findViewById(R.id.settings_notifications_picker_title)).setTextColor(style.getTextPrimaryColor());
notificationPickerContainer.setOnClickListener(view -> {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Uri currentSound = null;
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
String path = messenger().getPreferences().getString("userNotificationSound_" + uid);
if (path == null) {
path = defaultPath;
}
if (path != null && !path.equals("none")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(intent, SOUND_PICKER_REQUEST_CODE);
});
//
// Block
//
View blockContainer = res.findViewById(R.id.blockCont);
final TextView blockTitle = (TextView) blockContainer.findViewById(R.id.settings_block_title);
blockTitle.setTextColor(style.getTextPrimaryColor());
bind(user.getIsBlocked(), (val, valueModel) -> {
blockTitle.setText(val ? R.string.profile_settings_unblock : R.string.profile_settings_block);
});
blockContainer.setOnClickListener(v -> {
if (!user.getIsBlocked().get()) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.profile_settings_block_confirm).replace("{user}", user.getName().get())).setPositiveButton(R.string.dialog_yes, (dialog, which) -> {
execute(messenger().blockUser(user.getId()));
dialog.dismiss();
}).setNegativeButton(R.string.dialog_cancel, (dialog, which) -> {
dialog.dismiss();
}).show();
} else {
execute(messenger().unblockUser(user.getId()));
}
});
ImageView blockIconView = (ImageView) res.findViewById(R.id.settings_block_icon);
Drawable blockDrawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_block_white_24dp));
drawable.mutate();
DrawableCompat.setTint(blockDrawable, style.getSettingsIconColor());
blockIconView.setImageDrawable(blockDrawable);
}
//
// Scroll Coordinate
//
final ScrollView scrollView = ((ScrollView) res.findViewById(R.id.scrollContainer));
scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> updateBar(scrollView.getScrollY()));
updateBar(scrollView.getScrollY());
return res;
}
use of im.actor.core.viewmodel.UserPhone in project actor-platform by actorapp.
the class MembersAdapter method onMemberClick.
public void onMemberClick(GroupVM groupVM, UserVM userVM, boolean isAdministrator, boolean isInvitedByMe, BaseActivity activity) {
AlertListBuilder alertListBuilder = new AlertListBuilder();
final ArrayList<UserPhone> phones = userVM.getPhones().get();
alertListBuilder.addItem(activity.getString(R.string.group_context_message).replace("{0}", userVM.getName().get()), () -> activity.startActivity(Intents.openPrivateDialog(userVM.getId(), true, activity)));
if (phones.size() != 0) {
alertListBuilder.addItem(activity.getString(R.string.group_context_call).replace("{0}", userVM.getName().get()), () -> {
if (phones.size() == 1) {
activity.startActivity(Intents.call(phones.get(0).getPhone()));
} else {
CharSequence[] sequences = new CharSequence[phones.size()];
for (int i = 0; i < sequences.length; i++) {
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + phones.get(i).getPhone(), "us");
sequences[i] = phones.get(i).getTitle() + ": " + PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
sequences[i] = phones.get(i).getTitle() + ": +" + phones.get(i).getPhone();
}
}
new AlertDialog.Builder(activity).setItems(sequences, (dialog1, which1) -> {
activity.startActivity(Intents.call(phones.get(which1).getPhone()));
}).show().setCanceledOnTouchOutside(true);
}
});
}
alertListBuilder.addItem(activity.getString(R.string.group_context_view).replace("{0}", userVM.getName().get()), () -> ActorSDKLauncher.startProfileActivity(activity, userVM.getId()));
if (groupVM.getIsCanKickAnyone().get() || (groupVM.getIsCanKickInvited().get() && isInvitedByMe)) {
alertListBuilder.addItem(activity.getString(R.string.group_context_remove).replace("{0}", userVM.getName().get()), () -> {
new AlertDialog.Builder(activity).setMessage(activity.getString(R.string.alert_group_remove_text).replace("{0}", userVM.getName().get())).setPositiveButton(R.string.alert_group_remove_yes, (dialog2, which1) -> {
activity.execute(messenger().kickMember(groupVM.getId(), userVM.getId()), R.string.progress_common, new CommandCallback<Void>() {
@Override
public void onResult(Void res1) {
}
@Override
public void onError(Exception e) {
Toast.makeText(activity, R.string.toast_unable_kick, Toast.LENGTH_SHORT).show();
}
});
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
});
}
if (groupVM.getIsCanEditAdmins().get() && !userVM.isBot()) {
alertListBuilder.addItem(!isAdministrator ? activity.getResources().getString(R.string.group_make_admin) : activity.getResources().getString(R.string.group_revoke_admin), () -> {
if (!isAdministrator) {
messenger().makeAdmin(groupVM.getId(), userVM.getId()).start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
} else {
messenger().revokeAdmin(groupVM.getId(), userVM.getId()).start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
}
});
}
alertListBuilder.build(activity).show().setCanceledOnTouchOutside(true);
}
use of im.actor.core.viewmodel.UserPhone in project actor-platform by actorapp.
the class BaseActorSettingsFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
messenger().onUserVisible(myUid());
View view = inflater.inflate(R.layout.fragment_settings, container, false);
shp = getActivity().getSharedPreferences("wallpaper", Context.MODE_PRIVATE);
baseColor = getResources().getColor(R.color.primary);
final ActorStyle style = ActorSDK.sharedActor().style;
final UserVM userModel = users().get(myUid());
final TextView nameView = (TextView) view.findViewById(R.id.name);
nameView.setShadowLayer(1, 1, 1, style.getDividerColor());
nameView.setTextColor(style.getProfileTitleColor());
bind(nameView, userModel.getName());
view.findViewById(R.id.notifications).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), NotificationsActivity.class));
}
});
view.findViewById(R.id.helpSettings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), HelpActivity.class));
}
});
final LinearLayout nickContainer = (LinearLayout) view.findViewById(R.id.nickContainer);
final LinearLayout contactsContainer = (LinearLayout) view.findViewById(R.id.phoneContainer);
final LinearLayout about = (LinearLayout) view.findViewById(R.id.about);
// TODO: Move bindings to onResume
bind(userModel.getNick(), new ValueChangedListener<String>() {
@Override
public void onChanged(final String val, Value<String> Value) {
final View recordView = inflater.inflate(R.layout.contact_record, nickContainer, false);
ImageView nickIcon = (ImageView) recordView.findViewById(R.id.recordIcon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_mention_24_dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
nickIcon.setImageDrawable(drawable);
String value = (val != null && !val.isEmpty()) ? val : getString(R.string.nickname_empty);
String title = getString(R.string.nickname);
TextView nickValue = (TextView) recordView.findViewById(R.id.value);
nickValue.setText(value);
nickValue.setTextColor(style.getTextPrimaryColor());
TextView nickTitle = (TextView) recordView.findViewById(R.id.title);
nickTitle.setText(title);
nickTitle.setTextColor(style.getTextSecondaryColor());
nickContainer.removeAllViews();
nickContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
recordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().startActivity(Intents.editUserNick(getActivity()));
}
});
}
});
final TextView aboutTitle = (TextView) about.findViewById(R.id.value);
ImageView nickIcon = (ImageView) about.findViewById(R.id.recordIcon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_info_black_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
nickIcon.setImageDrawable(drawable);
aboutTitle.setTextColor(style.getTextPrimaryColor());
about.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().startActivity(Intents.editUserAbout(getActivity()));
}
});
bind(userModel.getAbout(), new ValueChangedListener<String>() {
@Override
public void onChanged(String val, Value<String> valueModel) {
if (val != null && !val.isEmpty()) {
aboutTitle.setTextColor(style.getTextPrimaryColor());
aboutTitle.setText(val);
} else {
aboutTitle.setTextColor(style.getTextSecondaryColor());
aboutTitle.setText(getString(R.string.edit_about_edittext_hint));
}
}
});
bind(userModel.getPhones(), new ValueChangedListener<ArrayListUserPhone>() {
@Override
public void onChanged(ArrayListUserPhone val, Value<ArrayListUserPhone> Value) {
if (val.size() == 0) {
noPhones = true;
} else {
contactsContainer.setVisibility(View.VISIBLE);
for (int i = 0; i < val.size(); i++) {
final UserPhone record = val.get(i);
View recordView = inflater.inflate(R.layout.contact_record, contactsContainer, false);
ImageView tintImageView = (ImageView) recordView.findViewById(R.id.recordIcon);
if (i == 0) {
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_phone_white_24dp));
drawable = drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
tintImageView.setImageDrawable(drawable);
} else {
tintImageView.setVisibility(View.INVISIBLE);
}
View divider = recordView.findViewById(R.id.divider);
if (i == val.size() - 1 && (userModel.getEmails().get() == null || userModel.getEmails().get().isEmpty())) {
divider.setVisibility(View.GONE);
} else {
divider.setVisibility(View.VISIBLE);
}
divider.setBackgroundColor(style.getDividerColor());
String _phoneNumber;
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + record.getPhone(), "us");
_phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
_phoneNumber = "+" + record.getPhone();
}
final String phoneNumber = _phoneNumber;
TextView value = (TextView) recordView.findViewById(R.id.value);
value.setTextColor(style.getTextPrimaryColor());
value.setText(phoneNumber);
TextView title = (TextView) recordView.findViewById(R.id.title);
title.setTextColor(style.getTextSecondaryColor());
title.setText(record.getTitle().replace("Mobile phone", getString(R.string.settings_mobile_phone)));
contactsContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
recordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.phone_menu_call).replace("{0}", phoneNumber), getString(R.string.phone_menu_sms).replace("{0}", phoneNumber), getString(R.string.phone_menu_share).replace("{0}", phoneNumber), getString(R.string.phone_menu_copy) }, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + record.getPhone())));
} else if (which == 1) {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + record.getPhone())));
} else if (which == 2) {
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text).replace("{0}", phoneNumber).replace("{1}", userModel.getName().get())));
} else if (which == 3) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT).show();
}
}
}).show().setCanceledOnTouchOutside(true);
}
});
recordView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", "+" + record.getPhone());
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
}
});
bind(userModel.getEmails(), new ValueChangedListener<ArrayListUserEmail>() {
@Override
public void onChanged(ArrayListUserEmail val, Value<ArrayListUserEmail> Value) {
if (val.size() == 0) {
noEmails = true;
} else {
contactsContainer.setVisibility(View.VISIBLE);
for (int i = 0; i < val.size(); i++) {
final UserEmail record = val.get(i);
View recordView = inflater.inflate(R.layout.contact_record, contactsContainer, false);
ImageView tintImageView = (ImageView) recordView.findViewById(R.id.recordIcon);
if (i == 0) {
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_email_white_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
tintImageView.setImageDrawable(drawable);
} else {
tintImageView.setVisibility(View.INVISIBLE);
}
View divider = recordView.findViewById(R.id.divider);
if (i != val.size() - 1) {
divider.setVisibility(View.VISIBLE);
} else {
divider.setVisibility(View.GONE);
}
divider.setBackgroundColor(style.getDividerColor());
final String email = record.getEmail();
TextView value = (TextView) recordView.findViewById(R.id.value);
value.setTextColor(style.getTextPrimaryColor());
value.setText(email);
TextView title = (TextView) recordView.findViewById(R.id.title);
title.setTextColor(style.getTextSecondaryColor());
title.setText(record.getTitle());
contactsContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
recordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", email), getString(R.string.phone_menu_copy) }, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", record.getEmail(), null)));
} else if (which == 1) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", email);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT).show();
}
}
}).show().setCanceledOnTouchOutside(true);
}
});
recordView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", "+" + record.getEmail());
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
}
});
view.findViewById(R.id.chatSettings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), ChatSettingsActivity.class));
}
});
view.findViewById(R.id.encryption).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActorSDK.sharedActor().startSecuritySettingsActivity(getActivity());
}
});
// view.findViewById(R.id.encryption).setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// if (AndroidLogProvider.isSendLogsEnabled()) {
// AndroidLogProvider.setSendLogs(null);
// Toast.makeText(getActivity(), "send logs off", Toast.LENGTH_LONG).show();
// } else {
//
// android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity());
// builder.setTitle("Send logs integration url");
//
// LinearLayout ll = new LinearLayout(getActivity());
// ll.setPadding(Screen.dp(20), 0, Screen.dp(20), 0);
//
// final EditText input = new EditText(getActivity());
// ll.addView(input, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
// builder.setView(ll);
//
// builder.setPositiveButton(getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// AndroidLogProvider.setSendLogs(input.getText().toString());
// Toast.makeText(getActivity(), "send logs on", Toast.LENGTH_LONG).show();
//
// }
// });
// builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// dialog.cancel();
// }
// });
//
// builder.create().show();
//
//
// }
// return true;
// }
// });
view.findViewById(R.id.blockedList).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), BlockedListActivity.class));
}
});
// view.findViewById(R.id.chatSettings).setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// Toast.makeText(getActivity(), AndroidLogProvider.toggleWriteLogs() ? "write logs on" : "write logs off", Toast.LENGTH_LONG).show();
// return true;
// }
// });
View askQuestion = view.findViewById(R.id.askQuestion);
if (ActorSDK.sharedActor().getHelpPhone() == null || ActorSDK.sharedActor().getHelpPhone().isEmpty()) {
askQuestion.setVisibility(View.GONE);
view.findViewById(R.id.divider3).setVisibility(View.GONE);
}
askQuestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
execute(messenger().findUsers(ActorSDK.sharedActor().getHelpPhone()), R.string.progress_common, new CommandCallback<UserVM[]>() {
@Override
public void onResult(UserVM[] res) {
if (res.length >= 1) {
startActivity(Intents.openPrivateDialog(res[0].getId(), true, getActivity()));
}
}
@Override
public void onError(Exception e) {
}
});
}
});
//Twitter
View twitterView = view.findViewById(R.id.twitter);
if (ActorSDK.sharedActor().getTwitterAcc() == null || ActorSDK.sharedActor().getTwitterAcc().isEmpty()) {
twitterView.setVisibility(View.GONE);
}
twitterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + ActorSDK.sharedActor().getTwitterAcc()));
startActivity(viewIntent);
}
});
TextView twitterTitle = (TextView) view.findViewById(R.id.settings_twitter);
twitterTitle.setTextColor(style.getSettingsTitleColor());
TintImageView twitterIcon = (TintImageView) view.findViewById(R.id.settings_twitter_icon);
twitterIcon.setTint(style.getSettingsIconColor());
//Home page
View homePageView = view.findViewById(R.id.home_page);
if (ActorSDK.sharedActor().getHomePage() == null || ActorSDK.sharedActor().getHomePage().isEmpty()) {
homePageView.setVisibility(View.GONE);
}
homePageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(ActorSDK.sharedActor().getHomePage()));
startActivity(viewIntent);
}
});
TextView homePageTitle = (TextView) view.findViewById(R.id.settings_home_page);
homePageTitle.setTextColor(style.getSettingsTitleColor());
TintImageView homePageIcon = (TintImageView) view.findViewById(R.id.settings_home_page_icon);
homePageIcon.setTint(style.getSettingsIconColor());
TextView profileHeaderText = (TextView) view.findViewById(R.id.profile_info_header_text);
profileHeaderText.setTextColor(style.getSettingsCategoryTextColor());
TextView settingsHeaderText = (TextView) view.findViewById(R.id.settings_header_text);
settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
TextView aboutHeaderText = (TextView) view.findViewById(R.id.about_header_text);
aboutHeaderText.setTextColor(style.getSettingsCategoryTextColor());
TextView settingsNotificationsTitle = (TextView) view.findViewById(R.id.settings_notifications_title);
settingsNotificationsTitle.setTextColor(style.getSettingsTitleColor());
TextView settingsChatTitle = (TextView) view.findViewById(R.id.settings_chat_title);
settingsChatTitle.setTextColor(style.getSettingsTitleColor());
TextView securityTitle = (TextView) view.findViewById(R.id.settings_security_title);
securityTitle.setTextColor(style.getSettingsTitleColor());
TintImageView securityIcon = (TintImageView) view.findViewById(R.id.settings_security_icon);
securityIcon.setTint(style.getSettingsIconColor());
TextView blockedListTitle = (TextView) view.findViewById(R.id.settings_blocked_title);
blockedListTitle.setTextColor(style.getSettingsTitleColor());
TintImageView blockedListIcon = (TintImageView) view.findViewById(R.id.settings_blocked_icon);
blockedListIcon.setTint(style.getSettingsIconColor());
TextView helpTitle = (TextView) view.findViewById(R.id.settings_help_title);
helpTitle.setTextColor(style.getSettingsTitleColor());
TintImageView helpIcon = (TintImageView) view.findViewById(R.id.settings_help_icon);
helpIcon.setTint(style.getSettingsIconColor());
TextView askTitle = (TextView) view.findViewById(R.id.settings_ask_title);
askTitle.setTextColor(style.getSettingsTitleColor());
TintImageView askIcon = (TintImageView) view.findViewById(R.id.settings_ask_icon);
askIcon.setTint(style.getSettingsIconColor());
TintImageView notificationsSettingsIcon = (TintImageView) view.findViewById(R.id.settings_notification_icon);
notificationsSettingsIcon.setTint(style.getSettingsIconColor());
TintImageView chatSettingsIcon = (TintImageView) view.findViewById(R.id.settings_chat_icon);
chatSettingsIcon.setTint(style.getSettingsIconColor());
if (getBeforeNickSettingsView() != null) {
FrameLayout beforeNick = (FrameLayout) view.findViewById(R.id.before_nick_container);
beforeNick.addView(getBeforeNickSettingsView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getBeforeNickSettingsView() != null) {
FrameLayout afterPhone = (FrameLayout) view.findViewById(R.id.after_phone_container);
afterPhone.addView(getAfterPhoneSettingsView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getSettingsTopView() != null) {
FrameLayout settingsTop = (FrameLayout) view.findViewById(R.id.settings_top_container);
settingsTop.addView(getSettingsTopView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getSettingsBottomView() != null) {
FrameLayout settingsBot = (FrameLayout) view.findViewById(R.id.settings_bottom_container);
settingsBot.addView(getSettingsBottomView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
}
if (getBeforeSettingsCategories() != null) {
LinearLayout beforeSettings = (LinearLayout) view.findViewById(R.id.before_settings_container);
addCategories(beforeSettings, getBeforeSettingsCategories(), inflater);
}
if (getAfterSettingsCategories() != null) {
LinearLayout afterSettings = (LinearLayout) view.findViewById(R.id.after_settings_container);
addCategories(afterSettings, getAfterSettingsCategories(), inflater);
}
view.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
avatarView = (AvatarView) view.findViewById(R.id.avatar);
avatarView.init(Screen.dp(96), 44);
avatarView.bind(users().get(myUid()));
//Wallpaper
if (showWallpaperCategory()) {
((TextView) view.findViewById(R.id.settings_wallpaper_title)).setTextColor(style.getSettingsCategoryTextColor());
RecyclerView wallpapers = (RecyclerView) view.findViewById(R.id.wallpapers_list);
wallpaperAdapter = new HeaderViewRecyclerAdapter(new WallpapersAdapter());
FrameLayout fl = new FrameLayout(getActivity());
ImageView icon = new ImageView(getActivity());
icon.setImageResource(R.drawable.ic_image_black_24dp);
icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
icon.setColorFilter(ActorSDK.sharedActor().style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
fl.addView(icon, new FrameLayout.LayoutParams(Screen.dp(72), Screen.dp(85), Gravity.CENTER));
fl.setLayoutParams(new ViewGroup.LayoutParams(Screen.dp(72), Screen.dp(85)));
wallpaperAdapter.addHeaderView(fl);
wallpapers.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
wallpapers.setAdapter(wallpaperAdapter);
} else {
view.findViewById(R.id.wallpapers_list).setVisibility(View.GONE);
view.findViewById(R.id.settings_wallpaper_title).setVisibility(View.GONE);
}
view.findViewById(R.id.avatar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(ViewAvatarActivity.viewAvatar(myUid(), getActivity()));
}
});
final ScrollView scrollView = ((ScrollView) view.findViewById(R.id.scrollContainer));
scrollView.setBackgroundColor(style.getMainBackgroundColor());
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
updateActionBar(scrollView.getScrollY());
}
});
updateActionBar(scrollView.getScrollY());
return view;
}
use of im.actor.core.viewmodel.UserPhone in project actor-platform by actorapp.
the class JsUser method fromUserVM.
public static JsUser fromUserVM(UserVM userVM, JsMessenger messenger) {
UserPresence presence = userVM.getPresence().get();
String presenceString = messenger.getFormatter().formatPresence(presence, userVM.getSex());
boolean isOnline = presence != null && presence.getState() == UserPresence.State.ONLINE;
if (userVM.isBot()) {
isOnline = true;
presenceString = "bot";
}
String fileUrl = null;
String bigFileUrl = null;
Avatar avatar = userVM.getAvatar().get();
if (avatar != null) {
if (avatar.getSmallImage() != null) {
fileUrl = messenger.getFileUrl(avatar.getSmallImage().getFileReference());
}
if (avatar.getLargeImage() != null) {
bigFileUrl = messenger.getFileUrl(avatar.getLargeImage().getFileReference());
}
}
JsArray<JsPhone> convertedPhones = JsArray.createArray().cast();
ArrayListUserPhone phones = userVM.getPhones().get();
for (UserPhone p : phones) {
convertedPhones.push(JsPhone.create(p.getPhone() + "", p.getTitle()));
}
JsArray<JsEmail> convertedEmails = JsArray.createArray().cast();
ArrayListUserEmail emails = userVM.getEmails().get();
for (UserEmail p : emails) {
convertedEmails.push(JsEmail.create(p.getEmail(), p.getTitle()));
}
return create(userVM.getId(), userVM.getName().get(), userVM.getNick().get(), userVM.getAbout().get(), fileUrl, bigFileUrl, Placeholders.getPlaceholder(userVM.getId()), userVM.isContact().get(), userVM.isBot(), presenceString, isOnline, userVM.getIsBlocked().get(), convertedPhones, convertedEmails, userVM.getTimeZone().get(), userVM.getIsVerified().get());
}
Aggregations