use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class PresenceActor method onGroupOnline.
@Verified
private void onGroupOnline(int gid, int count, long updateDate) {
// Log.d(TAG, "onGroupOnline #" + gid + " " + count + " at " + updateDate);
if (lastGidState.containsKey(gid) && lastGidState.get(gid) >= updateDate) {
// Log.d(TAG, "onGroupOnline:ignored - too old");
return;
}
lastGidState.put(gid, updateDate);
// Log.d(TAG, "onGroupOnline:updated");
GroupVM vm = getGroupVM(gid);
if (vm != null) {
vm.getPresence().change(count);
}
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class ChatFragment method onResume.
@Override
public void onResume() {
super.onResume();
findInputBar().setText(messenger().loadDraft(peer), true);
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM userVM = users().get(peer.getPeerId());
if (userVM.isBot()) {
ConversationVM conversationVM = messenger().getConversationVM(peer);
bind(conversationVM.getIsEmpty(), conversationVM.getIsLoaded(), (isEmpty, valueModel, isLoaded, valueModel2) -> {
if (isEmpty) {
inputOverlayText.setText(R.string.chat_empty_bot);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else {
goneView(inputOverlayContainer, false);
showView(inputContainer, false);
}
if (isEmpty && isLoaded) {
showView(emptyContainer, false);
} else {
hideView(emptyContainer, false);
}
});
bind(userVM.getAbout(), (val, valueModel) -> {
if (val == null) {
findEmptyPlaceholder().setText(getString(R.string.chat_empty_bot_about));
} else {
findEmptyPlaceholder().setText(val);
}
});
} else {
bind(userVM.getIsBlocked(), (val, valueModel) -> {
if (val) {
inputOverlayText.setText(R.string.blocked_unblock);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else {
goneView(inputOverlayContainer, false);
showView(inputContainer, false);
}
});
}
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM groupVM = groups().get(peer.getPeerId());
bind(groupVM.isMember(), groupVM.getIsCanWriteMessage(), (isMember, valueModel, canWriteMessage, valueModel2) -> {
if (canWriteMessage) {
goneView(inputOverlayContainer, false);
showView(inputContainer, false);
} else if (isMember) {
if (messenger().isNotificationsEnabled(peer)) {
inputOverlayText.setText(getString(R.string.chat_mute));
} else {
inputOverlayText.setText(getString(R.string.chat_unmute));
}
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
inputOverlayText.setEnabled(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else if (groupVM.getIsCanJoin().get()) {
inputOverlayText.setText(getString(R.string.join));
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
inputOverlayText.setEnabled(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else if (groupVM.getIsDeleted().get()) {
inputOverlayText.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_deleted : R.string.group_deleted);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(false);
inputOverlayText.setEnabled(false);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else {
inputOverlayText.setText(R.string.chat_not_member);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(false);
inputOverlayText.setEnabled(false);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
}
});
}
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class ChatToolbarFragment method onResume.
@Override
public void onResume() {
super.onResume();
if (peer.getPeerType() == PeerType.PRIVATE) {
// Loading user
UserVM user = users().get(peer.getPeerId());
// Binding User Avatar to Toolbar
bind(barAvatar, user.getId(), user.getAvatar(), user.getName());
// Binding User name to Toolbar
bind(barTitle, user.getName());
bind(user.getIsVerified(), (val, valueModel) -> {
barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, val ? new TintDrawable(getResources().getDrawable(R.drawable.ic_verified_user_black_18dp), ActorSDK.sharedActor().style.getVerifiedColor()) : null, null);
});
// Binding User presence to Toolbar
bind(barSubtitle, user);
// Binding User typing to Toolbar
bindPrivateTyping(barTyping, barTypingContainer, barSubtitle, messenger().getTyping(user.getId()));
// Refresh menu on contact state change
bind(user.isContact(), (val, valueModel) -> {
getActivity().invalidateOptionsMenu();
});
} else if (peer.getPeerType() == PeerType.GROUP) {
// Loading group
GroupVM group = groups().get(peer.getPeerId());
// Binding Group avatar to Toolbar
bind(barAvatar, group.getId(), group.getAvatar(), group.getName());
// Binding Group title to Toolbar
bind(barTitle, group.getName());
if (group.getGroupType() == GroupType.CHANNEL) {
barTitle.setCompoundDrawablesWithIntrinsicBounds(new TintDrawable(getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), Color.WHITE), null, null, null);
} else {
barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
// Subtitle is always visible for Groups
barSubtitleContainer.setVisibility(View.VISIBLE);
// Binding group members
bind(barSubtitle, barSubtitleContainer, group);
// Binding group typing
if (group.getGroupType() == GroupType.GROUP) {
bindGroupTyping(barTyping, barTypingContainer, barSubtitle, messenger().getGroupTyping(group.getId()));
}
}
// Global Counter
bind(messenger().getGlobalState().getGlobalCounter(), (val, valueModel) -> {
if (val != null && val > 0) {
counter.setText(Integer.toString(val));
showView(counter);
} else {
hideView(counter);
}
});
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class MembersFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View res = inflater.inflate(R.layout.fragment_members, container, false);
int groupId = getArguments().getInt("groupId");
adapter = new MembersAdapter(getContext(), groupId);
GroupVM groupVM = groups().get(groupId);
RecyclerListView list = (RecyclerListView) res.findViewById(R.id.items);
Boolean canInvite = groupVM.getIsCanInviteMembers().get();
Boolean canInviteViaLink = groupVM.getIsCanInviteViaLink().get();
if (canInvite || canInviteViaLink) {
LinearLayout header = new LinearLayout(getActivity());
list.addHeaderView(header);
if (canInvite) {
TextView addMmemberTV = new TextView(getContext());
addMmemberTV.setBackgroundResource(R.drawable.selector);
addMmemberTV.setTextSize(16);
addMmemberTV.setPadding(Screen.dp(72), 0, 0, 0);
addMmemberTV.setGravity(Gravity.CENTER_VERTICAL);
addMmemberTV.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
addMmemberTV.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
addMmemberTV.setOnClickListener(view -> {
startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupId));
});
header.addView(addMmemberTV, ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(58));
}
if (canInvite && canInviteViaLink) {
header.addView(new DividerView(getActivity()), ViewGroup.LayoutParams.MATCH_PARENT, 1);
}
if (canInviteViaLink) {
TextView shareLinkTV = new TextView(getContext());
shareLinkTV.setBackgroundResource(R.drawable.selector);
shareLinkTV.setTextSize(16);
shareLinkTV.setPadding(Screen.dp(72), 0, 0, 0);
shareLinkTV.setGravity(Gravity.CENTER_VERTICAL);
shareLinkTV.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
shareLinkTV.setText(R.string.invite_link_action_share);
shareLinkTV.setOnClickListener(view -> Intents.inviteLink(groupId, getActivity()));
header.addView(shareLinkTV, ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(58));
}
}
footer = new LinearLayout(getActivity());
footer.setVisibility(View.INVISIBLE);
list.addFooterView(footer);
CircularProgressBar botProgressView = new CircularProgressBar(getActivity());
int padding = Screen.dp(16);
botProgressView.setPadding(padding, padding, padding, padding);
botProgressView.setIndeterminate(true);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Screen.dp(72), Screen.dp(72));
params.gravity = Gravity.CENTER;
FrameLayout cont = new FrameLayout(getActivity());
cont.addView(botProgressView, params);
footer.addView(cont, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
list.setAdapter(adapter);
list.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()));
}
}
}
});
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long 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) {
adapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
return true;
}
}
}
return false;
}
});
progressView = (CircularProgressBar) res.findViewById(R.id.loadingProgress);
progressView.setIndeterminate(true);
return res;
}
use of im.actor.core.viewmodel.GroupVM 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);
}
Aggregations