use of im.actor.sdk.view.avatar.AvatarView in project actor-platform by actorapp.
the class CallFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.callId = getArguments().getLong("call_id");
this.call = messenger().getCall(callId);
if (call == null) {
this.peer = Peer.user(myUid());
} else {
this.peer = call.getPeer();
}
manager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
FrameLayout cont = (FrameLayout) inflater.inflate(R.layout.fragment_call, container, false);
v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
CallBackgroundAvatarView backgroundAvatarView = (CallBackgroundAvatarView) cont.findViewById(R.id.background);
// animator = new CallAvatarLayerAnimator(cont.findViewById(R.id.layer),
// cont.findViewById(R.id.layer1),
// cont.findViewById(R.id.layer2),
// cont.findViewById(R.id.layer3),
// cont.findViewById(R.id.layer4)
// );
layer1 = cont.findViewById(R.id.layer1);
layer2 = cont.findViewById(R.id.layer2);
layer3 = cont.findViewById(R.id.layer3);
avatarLayers = new View[] { // cont.findViewById(R.id.layer),
layer1, layer2, layer3 };
for (int i = 0; i < avatarLayers.length; i++) {
View layer = avatarLayers[i];
((GradientDrawable) layer.getBackground()).setColor(Color.WHITE);
((GradientDrawable) layer.getBackground()).setAlpha(50);
}
endCallContainer = cont.findViewById(R.id.end_call_container);
answerContainer = cont.findViewById(R.id.answer_container);
ImageButton answer = (ImageButton) cont.findViewById(R.id.answer);
answer.setOnClickListener(v1 -> onAnswer());
ImageButton notAnswer = (ImageButton) cont.findViewById(R.id.notAnswer);
endCall = (ImageButton) cont.findViewById(R.id.end_call);
notAnswer.setOnClickListener(v1 -> doEndCall());
endCall.setOnClickListener(v1 -> doEndCall());
//
//Avatar/Name bind
//
avatarView = (AvatarView) cont.findViewById(R.id.avatar);
avatarView.init(Screen.dp(130), 50);
nameTV = (TextView) cont.findViewById(R.id.name);
nameTV.setTextColor(ActorSDK.sharedActor().style.getProfileTitleColor());
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM user = users().get(peer.getPeerId());
avatarView.bind(user);
backgroundAvatarView.bind(user);
bind(nameTV, user.getName());
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM g = groups().get(peer.getPeerId());
avatarView.bind(g);
backgroundAvatarView.bind(g);
bind(nameTV, g.getName());
}
nameTV.setSelected(true);
//
// Members list
//
membersList = (RecyclerListView) cont.findViewById(R.id.members_list);
if (call != null) {
CallMembersAdapter membersAdapter = new CallMembersAdapter(getActivity(), call.getMembers());
membersList.setAdapter(membersAdapter);
}
//
// Members list/ avatar switch
//
View.OnClickListener listener = v1 -> switchAvatarMembers();
avatarView.setOnClickListener(listener);
// cont.findViewById(R.id.background).setOnClickListener(listener);
membersList.setOnItemClickListener((parent, view, position, id) -> switchAvatarMembers());
statusTV = (TextView) cont.findViewById(R.id.status);
//
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WAKE_LOCK) != PackageManager.PERMISSION_GRANTED) {
Log.d("Permissions", "call - no permission :c");
CallFragment.this.requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA, Manifest.permission.VIBRATE, Manifest.permission.MODIFY_AUDIO_SETTINGS, Manifest.permission.WAKE_LOCK }, PERMISSIONS_REQUEST_FOR_CALL);
}
audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
speaker = (TintImageView) cont.findViewById(R.id.speaker);
speaker.setResource(R.drawable.ic_volume_up_white_24dp);
speakerTV = (TextView) cont.findViewById(R.id.speaker_tv);
cont.findViewById(R.id.speaker_btn).setOnClickListener(v1 -> toggleSpeaker(speaker, speakerTV));
checkSpeaker(speaker, speakerTV);
muteCall = (TintImageView) cont.findViewById(R.id.mute);
muteCallTv = (TextView) cont.findViewById(R.id.mute_tv);
muteCall.setResource(R.drawable.ic_mic_off_white_24dp);
cont.findViewById(R.id.mute_btn).setOnClickListener(v1 -> messenger().toggleCallMute(callId));
videoIcon = (TintImageView) cont.findViewById(R.id.video);
videoIcon.setResource(R.drawable.ic_videocam_white_24dp);
videoTv = (TextView) cont.findViewById(R.id.video_tv);
videoTv.setTextColor(getResources().getColor(R.color.picker_grey));
videoIcon.setTint(getResources().getColor(R.color.picker_grey));
cont.findViewById(R.id.video_btn).setOnClickListener(v1 -> messenger().toggleVideoEnabled(callId));
final TintImageView back = (TintImageView) cont.findViewById(R.id.back);
back.setResource(R.drawable.ic_message_white_24dp);
cont.findViewById(R.id.back_btn).setOnClickListener(v1 -> getActivity().startActivity(Intents.openDialog(peer, false, getActivity())));
final TintImageView add = (TintImageView) cont.findViewById(R.id.add);
add.setResource(R.drawable.ic_person_add_white_24dp);
TextView addTv = (TextView) cont.findViewById(R.id.add_user_tv);
addTv.setTextColor(getResources().getColor(R.color.picker_grey));
add.setTint(getResources().getColor(R.color.picker_grey));
if (peer.getPeerType() == PeerType.PRIVATE) {
eglContext = EglBase.create();
remoteVideoView = (SurfaceViewRenderer) cont.findViewById(R.id.remote_renderer);
localVideoView = new SurfaceViewRenderer(getActivity()) {
private boolean aspectFixed = false;
@Override
public void renderFrame(VideoRenderer.I420Frame frame) {
if (!aspectFixed) {
aspectFixed = true;
int maxWH = Screen.getWidth() / 3 - Screen.dp(20);
float scale = Math.min(maxWH / (float) frame.width, maxWH / (float) frame.height);
int destW = (int) (scale * frame.width);
int destH = (int) (scale * frame.height);
boolean turned = frame.rotationDegree % 90 % 2 == 0;
localVideoView.post(new Runnable() {
@Override
public void run() {
localVideoView.getLayoutParams().height = turned ? destW : destH;
localVideoView.getLayoutParams().width = turned ? destH : destW;
}
});
}
super.renderFrame(frame);
}
};
localVideoView.setVisibility(View.INVISIBLE);
localVideoView.setZOrderMediaOverlay(true);
localVideoView.setOnTouchListener((v1, event) -> {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
dX = localVideoView.getX() - event.getRawX();
dY = localVideoView.getY() - event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
localVideoView.animate().x(event.getRawX() + dX).y(event.getRawY() + dY).setDuration(0).start();
default:
return false;
}
return true;
});
int margin = Screen.dp(20);
int localVideoWidth = Screen.getWidth() / 3 - margin;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(localVideoWidth, Math.round(localVideoWidth / 1.5f), Gravity.TOP | Gravity.LEFT);
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
params.setMargins(margin, margin + statusBarHeight, 0, 0);
cont.addView(localVideoView, params);
} else {
if (call != null) {
if (call.getIsVideoEnabled().get()) {
messenger().toggleVideoEnabled(callId);
}
}
}
return cont;
}
use of im.actor.sdk.view.avatar.AvatarView 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.sdk.view.avatar.AvatarView in project actor-platform by actorapp.
the class GroupNameFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
helper = new KeyboardHelper(getActivity());
View res = inflater.inflate(R.layout.fragment_create_group_name, container, false);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
TextView hintTextView = (TextView) res.findViewById(R.id.create_group_hint);
hintTextView.setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
if (isChannel) {
hintTextView.setText(R.string.create_channel_hint);
} else {
hintTextView.setText(R.string.create_group_hint);
}
groupName = (EditText) res.findViewById(R.id.groupTitle);
groupName.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
next();
return true;
}
return false;
});
if (isChannel) {
groupName.setHint(R.string.create_channel_name_hint);
} else {
groupName.setHint(R.string.create_group_name_hint);
}
groupName.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
groupName.setHintTextColor(ActorSDK.sharedActor().style.getTextHintColor());
avatarView = (AvatarView) res.findViewById(R.id.avatar);
avatarView.init(Screen.dp(96), 24);
avatarView.getHierarchy().setPlaceholderImage(R.drawable.circle_placeholder);
// avatarView.getHierarchy().setControllerOverlay(getResources().getDrawable(R.drawable.circle_selector));
avatarView.setImageURI(null);
res.findViewById(R.id.pickAvatar).setOnClickListener(view -> {
startActivityForResult(Intents.pickAvatar(avatarPath != null, getActivity()), REQUEST_AVATAR);
});
return res;
}
use of im.actor.sdk.view.avatar.AvatarView in project actor-platform by actorapp.
the class GroupInfoFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
chatId = getArguments().getInt(EXTRA_CHAT_ID);
groupVM = groups().get(chatId);
View res = inflater.inflate(R.layout.fragment_group, container, false);
listView = (RecyclerListView) res.findViewById(R.id.groupList);
notMemberView = res.findViewById(R.id.notMember);
res.setBackgroundColor(style.getMainBackgroundColor());
// listView.setBackgroundColor(style.getMainBackgroundColor());
notMemberView.setBackgroundColor(style.getMainBackgroundColor());
((TextView) notMemberView.findViewById(R.id.not_member_text)).setTextColor(style.getTextPrimaryColor());
//
// Header
//
// Views
View header = inflater.inflate(R.layout.fragment_group_header, listView, false);
TextView title = (TextView) header.findViewById(R.id.title);
TextView subtitle = (TextView) header.findViewById(R.id.subtitle);
avatarView = (AvatarView) header.findViewById(R.id.avatar);
avatarView.init(Screen.dp(48), 22);
TextView aboutTV = (TextView) header.findViewById(R.id.about);
View shortNameCont = header.findViewById(R.id.shortNameContainer);
TextView shortNameView = (TextView) header.findViewById(R.id.shortName);
TextView shortLinkView = (TextView) header.findViewById(R.id.shortNameLink);
TextView addMember = (TextView) header.findViewById(R.id.addMemberAction);
addMember.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
TextView members = (TextView) header.findViewById(R.id.viewMembersAction);
TextView leaveAction = (TextView) header.findViewById(R.id.leaveAction);
TextView administrationAction = (TextView) header.findViewById(R.id.administrationAction);
View descriptionContainer = header.findViewById(R.id.descriptionContainer);
SwitchCompat isNotificationsEnabled = (SwitchCompat) header.findViewById(R.id.enableNotifications);
// Styling
// ((TextView) header.findViewById(R.id.about_hint)).setTextColor(style.getTextSecondaryColor());
header.setBackgroundColor(style.getMainBackgroundColor());
header.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
title.setTextColor(style.getProfileTitleColor());
subtitle.setTextColor(style.getProfileSubtitleColor());
aboutTV.setTextColor(style.getTextPrimaryColor());
shortNameView.setTextColor(style.getTextPrimaryColor());
shortLinkView.setTextColor(style.getTextSecondaryColor());
// settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
((TintImageView) header.findViewById(R.id.settings_notification_icon)).setTint(style.getSettingsIconColor());
((TintImageView) header.findViewById(R.id.settings_about_icon)).setTint(style.getSettingsIconColor());
((TextView) header.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
((TextView) header.findViewById(R.id.addMemberAction)).setTextColor(style.getTextPrimaryColor());
members.setTextColor(style.getTextPrimaryColor());
administrationAction.setTextColor(style.getTextPrimaryColor());
leaveAction.setTextColor(style.getTextDangerColor());
if (groupVM.getGroupType() == GroupType.CHANNEL) {
leaveAction.setText(R.string.group_leave_channel);
} else {
leaveAction.setText(R.string.group_leave);
}
header.findViewById(R.id.after_settings_divider).setBackgroundColor(style.getBackyardBackgroundColor());
//
// Header
//
avatarView.bind(groupVM.getAvatar().get(), groupVM.getName().get(), groupVM.getId());
avatarView.setOnClickListener(view -> {
if (groupVM.getAvatar().get() != null) {
startActivity(ViewAvatarActivity.viewGroupAvatar(chatId, getActivity()));
}
});
bind(groupVM.getName(), name -> {
title.setText(name);
});
bind(groupVM.getMembersCount(), val -> {
subtitle.setText(messenger().getFormatter().formatGroupMembers(val));
});
// About
bind(groupVM.getAbout(), (about) -> {
aboutTV.setText(about);
aboutTV.setVisibility(about != null ? View.VISIBLE : View.GONE);
});
bind(groupVM.getShortName(), shortName -> {
if (shortName != null) {
shortNameView.setText("@" + shortName);
String prefix = ActorSDK.sharedActor().getGroupInvitePrefix();
if (prefix != null) {
shortLinkView.setText(prefix + shortName);
shortLinkView.setVisibility(View.VISIBLE);
} else {
shortLinkView.setVisibility(View.GONE);
}
}
shortNameCont.setVisibility(shortName != null ? View.VISIBLE : View.GONE);
});
final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
shortNameCont.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String link = shortLinkView.getText().toString();
clipboard.setPrimaryClip(ClipData.newPlainText(null, (link.contains("://") ? "" : "https://") + link));
Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
}
});
bind(groupVM.getAbout(), groupVM.getShortName(), (about, shortName) -> {
descriptionContainer.setVisibility(about != null || shortName != null ? View.VISIBLE : View.GONE);
});
// Notifications
isNotificationsEnabled.setChecked(messenger().isNotificationsEnabled(Peer.group(chatId)));
isNotificationsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> {
messenger().changeNotificationsEnabled(Peer.group(chatId), isChecked);
});
header.findViewById(R.id.notificationsCont).setOnClickListener(v -> {
isNotificationsEnabled.setChecked(!isNotificationsEnabled.isChecked());
});
// Add Member
bind(groupVM.getIsCanInviteMembers(), (canInvite) -> {
if (canInvite) {
addMember.setVisibility(View.VISIBLE);
} else {
addMember.setVisibility(View.GONE);
}
});
addMember.setOnClickListener(view -> {
startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
});
// Administration
if (groupVM.getIsCanEditAdministration().get() || groupVM.getIsCanDelete().get()) {
administrationAction.setOnClickListener(view -> {
startActivity(new Intent(getActivity(), GroupAdminActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
});
} else {
administrationAction.setVisibility(View.GONE);
}
// Async Members
// Showing member only when members available and async members is enabled
bind(groupVM.getIsCanViewMembers(), groupVM.getIsAsyncMembers(), (canViewMembers, vm1, isAsync, vm2) -> {
if (canViewMembers) {
if (isAsync) {
members.setVisibility(View.VISIBLE);
header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
} else {
members.setVisibility(View.GONE);
header.findViewById(R.id.after_settings_divider).setVisibility(View.VISIBLE);
}
} else {
members.setVisibility(View.GONE);
header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
}
});
members.setOnClickListener(view -> {
startActivity(new Intent(getContext(), MembersActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupVM.getId()));
});
// Leave
bind(groupVM.getIsCanLeave(), canLeave -> {
if (canLeave) {
leaveAction.setVisibility(View.VISIBLE);
leaveAction.setOnClickListener(view1 -> {
new AlertDialog.Builder(getActivity()).setMessage(getString(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.alert_leave_channel_message : R.string.alert_leave_group_message).replace("%1$s", groupVM.getName().get())).setPositiveButton(R.string.alert_leave_group_yes, (dialog2, which) -> {
execute(messenger().leaveAndDeleteGroup(chatId).then(aVoid -> ActorSDK.returnToRoot(getActivity())));
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
});
} else {
leaveAction.setVisibility(View.GONE);
}
});
listView.addHeaderView(header, null, false);
//
// Members
//
groupUserAdapter = new MembersAdapter(getActivity(), getArguments().getInt("groupId"));
listView.setAdapter(groupUserAdapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
Object item = parent.getItemAtPosition(position);
if (item != null && item instanceof GroupMember) {
GroupMember groupMember = (GroupMember) item;
if (groupMember.getUid() != myUid()) {
UserVM userVM = users().get(groupMember.getUid());
if (userVM != null) {
startActivity(Intents.openPrivateDialog(userVM.getId(), true, getActivity()));
}
}
}
});
listView.setOnItemLongClickListener((adapterView, view, i, l) -> {
Object item = adapterView.getItemAtPosition(i);
if (item != null && item instanceof GroupMember) {
GroupMember groupMember = (GroupMember) item;
if (groupMember.getUid() != myUid()) {
UserVM userVM = users().get(groupMember.getUid());
if (userVM != null) {
groupUserAdapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
return true;
}
}
}
return false;
});
//
// Scroll handling
//
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (firstVisibleItem >= 1) {
updateBar(Integer.MAX_VALUE);
} else {
View top = listView.getChildAt(0);
if (top != null) {
updateBar(-top.getTop());
} else {
updateBar(Integer.MAX_VALUE);
}
}
}
});
//
// Placeholder
//
bind(groupVM.isMember(), (isMember) -> {
notMemberView.setVisibility(isMember ? View.GONE : View.VISIBLE);
getActivity().invalidateOptionsMenu();
});
// Menu
bind(groupVM.getIsCanEditInfo(), canEditInfo -> {
getActivity().invalidateOptionsMenu();
});
return res;
}
use of im.actor.sdk.view.avatar.AvatarView in project actor-platform by actorapp.
the class BubbleContainer method onMeasure.
// Small hack for avoiding listview selection
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int topOffset = 0;
View messageView = findMessageView();
int padding = Screen.dp(8);
if (showAvatar) {
padding += Screen.dp(48);
}
measureChildWithMargins(messageView, widthMeasureSpec, padding, heightMeasureSpec, 0);
if (showDateDiv) {
measureChild(dateDiv, widthMeasureSpec, heightMeasureSpec);
topOffset += Screen.dp(16) + dateDiv.getMeasuredHeight();
}
if (showUnreadDiv) {
measureChild(unreadDiv, widthMeasureSpec, heightMeasureSpec);
topOffset += Screen.dp(16) + unreadDiv.getMeasuredHeight();
}
if (showAvatar) {
measureChild(avatarView, widthMeasureSpec, heightMeasureSpec);
}
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), messageView.getMeasuredHeight() + topOffset);
}
Aggregations