use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class InviteHandler method handleIntent.
public static void handleIntent(BaseActivity activity, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW) && intent.getData() != null) {
String joinGroupUrl = intent.getData().toString();
if (joinGroupUrl != null && (joinGroupUrl.contains("join") || joinGroupUrl.contains("token"))) {
String[] urlSplit = null;
if (joinGroupUrl.contains("join")) {
urlSplit = joinGroupUrl.split("/join/");
} else if (joinGroupUrl.contains("token")) {
urlSplit = joinGroupUrl.split("token=");
}
if (urlSplit != null) {
joinGroupUrl = urlSplit[urlSplit.length - 1];
final String token = joinGroupUrl;
HTTP.getMethod(ActorSDK.sharedActor().getInviteDataUrl() + joinGroupUrl, 0, 0, 0).then(new Consumer<HTTPResponse>() {
@Override
public void apply(HTTPResponse httpResponse) {
try {
JSONObject data = new JSONObject(new String(httpResponse.getContent(), "UTF-8"));
JSONObject group = data.getJSONObject("group");
String title = group.getString("title");
if (group.has("id") && group.has("isPublic")) {
int gid = group.getInt("id");
boolean isPublic = group.getBoolean("isPublic");
//Check if we have this group
try {
GroupVM groupVM = groups().get(gid);
if (groupVM.isMember().get() || isPublic) {
//Have this group, is member or group is public, just open it
activity.startActivity(Intents.openDialog(Peer.group(gid), false, activity));
} else {
//Have this group, but not member, join it
joinViaToken(token, title, activity);
}
} catch (Exception e) {
//Do not have this group, join it
if (isPublic) {
messenger().findPublicGroupById(gid).then(peer -> activity.startActivity(Intents.openDialog(peer, false, activity)));
} else {
joinViaToken(token, title, activity);
}
}
} else {
joinViaToken(token, title, activity);
}
} catch (JSONException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
});
}
}
}
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class EditNameFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
type = getArguments().getInt("EXTRA_TYPE");
id = getArguments().getInt("EXTRA_ID");
helper = new KeyboardHelper(getActivity());
View res = inflater.inflate(R.layout.fragment_edit_name, container, false);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
nameEdit = (EditText) res.findViewById(R.id.nameEdit);
nameEdit.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
hintTv = (TextView) res.findViewById(R.id.hint);
hintTv.setTextColor(ActorSDK.sharedActor().style.getTextHintColor());
if (type == EditNameActivity.TYPE_ME) {
UserVM userModel = users().get(myUid());
nameEdit.setText(userModel.getName().get());
} else if (type == EditNameActivity.TYPE_NICK) {
UserVM userModel = users().get(myUid());
nameEdit.setText(userModel.getNick().get());
nameEdit.setHint(getString(R.string.nickname_edittext_hint));
hintTv.setText(getString(R.string.nickname_hint).replace("{appName}", ActorSDK.sharedActor().getAppName()));
} else if (type == EditNameActivity.TYPE_USER) {
UserVM userModel = users().get(id);
nameEdit.setText(userModel.getName().get());
} else if (type == EditNameActivity.TYPE_GROUP) {
GroupVM group = groups().get(id);
nameEdit.setText(group.getName().get());
} else if (type == EditNameActivity.TYPE_GROUP_THEME) {
GroupVM group = groups().get(id);
nameEdit.setText(group.getTheme().get());
}
res.findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
((TextView) res.findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
res.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = nameEdit.getText().toString().trim();
if (name.length() == 0) {
Toast.makeText(getActivity(), R.string.toast_empty_name, Toast.LENGTH_SHORT).show();
return;
}
if (type == EditNameActivity.TYPE_ME) {
execute(messenger().editMyName(name), R.string.edit_name_process, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
} else if (type == EditNameActivity.TYPE_NICK) {
execute(messenger().editMyNick(name), R.string.edit_nick_process, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change_nick, Toast.LENGTH_SHORT).show();
}
});
} else if (type == EditNameActivity.TYPE_USER) {
execute(messenger().editName(id, name), R.string.edit_name_process, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
} else if (type == EditNameActivity.TYPE_GROUP_THEME) {
execute(messenger().editGroupTheme(id, name), R.string.edit_theme_process, new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
}
}
});
((TextView) res.findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
return res;
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class JsNotificationsProvider method onNotification.
@Override
public void onNotification(Messenger messenger, List<Notification> topNotifications, int messagesCount, int conversationsCount) {
String peerTitle;
String peerKey = null;
String peerAvatarUrl = null;
String contentMessage = "";
Notification notification = topNotifications.get(0);
// Peer info
Peer peer = notification.getPeer();
if (conversationsCount == 1) {
Avatar peerAvatar;
JsPeer jsPeer = JsPeer.create(peer);
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM userVM = messenger.getUser(peer.getPeerId());
peerTitle = userVM.getName().get();
peerAvatar = userVM.getAvatar().get();
} else {
GroupVM groupVM = messenger.getGroup(peer.getPeerId());
peerTitle = groupVM.getName().get();
peerAvatar = groupVM.getAvatar().get();
}
if (peerAvatar != null && peerAvatar.getSmallImage() != null) {
peerAvatarUrl = ((JsMessenger) messenger).getFileUrl(peerAvatar.getSmallImage().getFileReference());
}
peerKey = jsPeer.getPeerKey();
} else {
peerTitle = "New messages";
peerAvatarUrl = "assets/img/notification_icon_512.png";
}
// Notification body
int nCount = Math.min(topNotifications.size(), 5);
boolean showCounters = false;
if (topNotifications.size() > 5) {
nCount--;
showCounters = true;
}
boolean isChannel = peer.getPeerType() == PeerType.GROUP && messenger.getGroups().get(peer.getPeerId()).getGroupType() == GroupType.CHANNEL;
if (conversationsCount == 1) {
for (int i = 0; i < nCount; i++) {
Notification n = topNotifications.get(i);
if (contentMessage.length() > 0) {
contentMessage += "\n";
}
if (peer.getPeerType() == PeerType.GROUP) {
contentMessage += messenger.getUser(notification.getSender()).getName().get() + ": ";
}
contentMessage += messenger.getFormatter().formatContentText(n.getSender(), n.getContentDescription().getContentType(), n.getContentDescription().getText(), n.getContentDescription().getRelatedUser(), isChannel);
}
if (showCounters) {
contentMessage += "\n+" + (messagesCount - 4) + " new messages";
}
} else {
for (int i = 0; i < nCount; i++) {
Notification n = topNotifications.get(i);
if (contentMessage.length() > 0) {
contentMessage += "\n";
}
String senderName = messenger.getUser(n.getSender()).getName().get();
if (n.getPeer().getPeerType() == PeerType.GROUP) {
String groupName = messenger.getGroup(n.getPeer().getPeerId()).getName().get();
contentMessage += "[" + groupName + "] " + senderName + ": ";
} else {
contentMessage += senderName + ": ";
}
contentMessage += messenger.getFormatter().formatContentText(n.getSender(), n.getContentDescription().getContentType(), n.getContentDescription().getText(), n.getContentDescription().getRelatedUser(), isChannel);
}
if (showCounters) {
contentMessage += "\n+" + (messagesCount - 4) + " new messages in " + conversationsCount + " conversations";
}
}
if (!JsElectronApp.isElectron()) {
playSound();
}
if (!JsNotification.isSupported()) {
return;
}
if (!JsNotification.isGranted()) {
return;
}
JsManagedNotification.show(peerKey, peerTitle, contentMessage, peerAvatarUrl);
}
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 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;
}
Aggregations