use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.
the class FragmentGroupProfile method onViewCreated.
@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
isNeedResume = true;
// because actionbar not in this view do that and not correct in viewModel
imvGroupAvatar = binding.toolbarAvatar;
imvGroupAvatar.setOnClickListener(v -> viewModel.onClickRippleGroupAvatar());
if (currentRoomAccess != null) {
checkRoomAccess(currentRoomAccess);
roomAccessChangeListener = (realmRoomAccess, changeSet) -> checkRoomAccess(realmRoomAccess);
currentRoomAccess.addChangeListener(roomAccessChangeListener);
}
binding.toolbarMore.setOnClickListener(v -> viewModel.onClickRippleMenu());
binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
binding.toolbarEdit.setOnClickListener(v -> {
if (getActivity() != null && currentRoomAccess != null && currentRoomAccess.isCanModifyRoom()) {
new HelperFragment(getActivity().getSupportFragmentManager(), EditGroupFragment.newInstance(viewModel.roomId)).setReplace(false).load();
}
});
viewModel.groupName.observe(getViewLifecycleOwner(), s -> {
binding.toolbarTxtNameCollapsed.setText(EmojiManager.getInstance().replaceEmoji(s, binding.toolbarTxtNameCollapsed.getPaint().getFontMetricsInt()));
binding.toolbarTxtNameExpanded.setText(EmojiManager.getInstance().replaceEmoji(s, binding.toolbarTxtNameExpanded.getPaint().getFontMetricsInt()));
});
viewModel.groupNumber.observe(getViewLifecycleOwner(), s -> binding.toolbarTxtStatusExpanded.setText(String.format("%s %s", s, getString(R.string.member))));
viewModel.showMoreMenu.observe(getViewLifecycleOwner(), isShow -> {
if (isShow != null) {
binding.toolbarMore.setVisibility(isShow ? View.VISIBLE : View.GONE);
}
});
viewModel.goToShearedMediaPage.observe(getViewLifecycleOwner(), model -> {
if (getActivity() != null && model != null) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(model)).setReplace(false).load();
}
});
viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), roomId -> {
if (getActivity() != null && roomId != null) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowAvatars.newInstance(roomId, FragmentShowAvatars.From.group)).setReplace(false).load();
}
});
viewModel.showMenu.observe(getViewLifecycleOwner(), menuList -> {
if (getActivity() != null && menuList != null) {
new TopSheetDialog(getActivity()).setListDataWithResourceId(menuList, -1, position -> {
if (menuList.get(position) == R.string.clear_history) {
new MaterialDialog.Builder(getActivity()).title(R.string.clear_history).content(R.string.clear_history_content).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
getMessageController().clearHistoryMessage(viewModel.roomId);
}
}).negativeText(R.string.no).show();
} else if (menuList.get(position) == R.string.group_title_convert_to_public || menuList.get(position) == R.string.group_title_convert_to_private) {
viewModel.convertMenuClick();
}
}).show();
}
});
viewModel.goToShowMemberPage.observe(getViewLifecycleOwner(), type -> {
if (getActivity() != null && type != null) {
FragmentShowMember fragment = FragmentShowMember.newInstance2(this, viewModel.roomId, viewModel.role.toString(), AccountManager.getInstance().getCurrentUser().getId(), type, viewModel.isNeedgetContactlist, true);
new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
}
});
viewModel.showDialogConvertToPublic.observe(getViewLifecycleOwner(), isShow -> {
if (getActivity() != null && isShow != null && isShow) {
new MaterialDialog.Builder(getActivity()).title(getString(R.string.group_title_convert_to_public)).content(getString(R.string.group_text_convert_to_public)).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
setUsername();
}
}).negativeText(R.string.no).show();
}
});
viewModel.showDialogConvertToPrivate.observe(getViewLifecycleOwner(), isShow -> {
if (getActivity() != null && isShow != null && isShow) {
new MaterialDialog.Builder(getActivity()).title(R.string.group_title_convert_to_private).content(R.string.group_text_convert_to_private).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
viewModel.sendRequestRemoveGroupUsername();
}
}).negativeText(R.string.no).show();
}
});
viewModel.showRequestError.observe(getViewLifecycleOwner(), errorMessage -> {
if (errorMessage != null) {
HelperError.showSnackMessage(getString(errorMessage), false);
}
});
viewModel.goToShowCustomListPage.observe(getViewLifecycleOwner(), listItem -> {
if (getActivity() != null && listItem != null) {
ShowCustomList showCustomListFragment = new ShowCustomList();
showCustomListFragment.setFields(ProtoGlobal.Room.Type.GROUP, listItem, (result, message, countForShowLastMessage, list) -> {
for (int i = 0; i < list.size(); i++) {
new RequestGroupAddMember().groupAddMember(viewModel.roomId, list.get(i).peerId, RealmRoomMessage.findCustomMessageId(viewModel.roomId, countForShowLastMessage));
}
});
Bundle bundle = new Bundle();
bundle.putBoolean("DIALOG_SHOWING", true);
bundle.putLong("COUNT_MESSAGE", 0);
showCustomListFragment.setArguments(bundle);
new HelperFragment(getActivity().getSupportFragmentManager(), showCustomListFragment).setReplace(false).load();
}
});
viewModel.goBack.observe(getViewLifecycleOwner(), isGoBack -> {
if (isGoBack != null && isGoBack) {
popBackStackFragment();
}
});
BetterLinkMovementMethod.linkify(Linkify.ALL, binding.description).setOnLinkClickListener((tv, url) -> {
return false;
}).setOnLinkLongClickListener((tv, url) -> {
if (HelperUrl.isTextLink(url)) {
G.isLinkClicked = true;
HelperUrl.openLinkDialog(getActivity(), url);
}
return true;
});
viewModel.groupDescription.observe(getViewLifecycleOwner(), groupDescription -> {
if (getActivity() != null && groupDescription != null) {
binding.description.setText(EmojiManager.getInstance().replaceEmoji(HelperUrl.setUrlLink(getActivity(), groupDescription, true, false, null, true), binding.description.getPaint().getFontMetricsInt()));
}
});
viewModel.goToRoomListPage.observe(getViewLifecycleOwner(), isGo -> {
if (getActivity() instanceof ActivityMain && isGo != null) {
Log.wtf(this.getClass().getName(), "goToRoomListPage observe");
((ActivityMain) getActivity()).removeAllFragmentFromMain();
/*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(2);*/
}
});
viewModel.showDialogEditLink.observe(getViewLifecycleOwner(), link -> {
if (getActivity() != null && link != null) {
MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.group_link).positiveText(R.string.array_Copy).customView(createDialogLayout(link), true).widgetColor(new Theme().getPrimaryColor(getContext())).negativeText(R.string.edit).onPositive((dialog1, which) -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("LINK_GROUP", link);
clipboard.setPrimaryClip(clip);
}).onNegative((dialog12, which) -> {
if (viewModel.isPrivate) {
viewModel.sendRequestRevokeGroupUsername();
} else {
setUsername();
}
}).build();
dialog.show();
}
});
viewModel.showDialogCopyLink.observe(getViewLifecycleOwner(), link -> {
if (getActivity() != null && link != null) {
MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.group_link).positiveText(R.string.array_Copy).customView(createDialogLayout(link), true).widgetColor(new Theme().getPrimaryColor(getContext())).onPositive((dialog1, which) -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("LINK_GROUP", link);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.copied, Toast.LENGTH_SHORT).show();
}).build();
dialog.show();
}
});
viewModel.goToCustomNotificationPage.observe(getViewLifecycleOwner(), roomId -> {
if (getActivity() != null && roomId != null) {
FragmentNotification fragmentNotification = new FragmentNotification();
Bundle bundle = new Bundle();
bundle.putLong("ID", roomId);
fragmentNotification.setArguments(bundle);
new HelperFragment(getActivity().getSupportFragmentManager(), fragmentNotification).setReplace(false).load();
}
});
viewModel.showDialogLeaveGroup.observe(getViewLifecycleOwner(), isShow -> {
if (isShow != null && isShow) {
groupLeft();
}
});
if (viewModel.role.equals(GroupChatRole.OWNER)) {
binding.editGroupPermission.setVisibility(View.VISIBLE);
binding.editGroupPermission.setOnClickListener(v -> {
openChatEditRightsFragment(viewModel.getRealmRoom());
});
}
initComponent();
attachFile = new AttachFile(getActivity());
G.onGroupAvatarDelete = this;
initialToolbar();
}
use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.
the class FragmentShowMember method goToAddMember.
private void goToAddMember() {
List<StructContactInfo> userList = Contacts.retrieve(null);
RealmList<RealmMember> memberList = DbManager.getInstance().doRealmTask(realm -> {
return RealmMember.getMembers(realm, mRoomID);
});
for (int i = 0; i < memberList.size(); i++) {
for (int j = 0; j < userList.size(); j++) {
if (userList.get(j).peerId == memberList.get(i).getPeerId()) {
userList.remove(j);
break;
}
}
}
if (getActivity() != null) {
ShowCustomList showCustomListFragment = new ShowCustomList();
showCustomListFragment.setFields(roomType, userList, new OnSelectedList() {
@Override
public void getSelectedList(boolean result, String message, int countForShowLastMessage, final ArrayList<StructContactInfo> list) {
if (isGroup) {
for (int i = 0; i < list.size(); i++) {
new RequestGroupAddMember().groupAddMember(mRoomID, list.get(i).peerId, RealmRoomMessage.findCustomMessageId(mRoomID, countForShowLastMessage));
}
} else {
for (int i = 0; i < list.size(); i++) {
new RequestChannelAddMember().channelAddMember(mRoomID, list.get(i).peerId);
}
}
}
});
Bundle bundle = new Bundle();
bundle.putBoolean("DIALOG_SHOWING", true);
bundle.putLong("COUNT_MESSAGE", 0);
showCustomListFragment.setArguments(bundle);
new HelperFragment(getActivity().getSupportFragmentManager(), showCustomListFragment).setReplace(false).load();
}
}
use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.
the class FragmentNewGroup method addMembersToGroup.
private void addMembersToGroup() {
G.onGroupAddMember = new OnGroupAddMember() {
@Override
public void onGroupAddMember(Long roomId, Long UserId) {
countAddMemberResponse++;
countMember++;
if (countAddMemberResponse == countAddMemberRequest) {
addMember(roomId, ProtoGlobal.Room.Type.GROUP);
}
}
@Override
public void onError(int majorCode, int minorCode) {
countAddMemberResponse++;
if (countAddMemberResponse == countAddMemberRequest) {
addMember(createdRoomId, ProtoGlobal.Room.Type.GROUP);
}
}
};
/**
* request add member for group
*/
// countAddMemberRequest = ContactGroupFragment.selectedContacts.size() ;
ArrayList<Long> list = getSelectedList();
if (list.size() > 0) {
for (long peerId : list) {
new RequestGroupAddMember().groupAddMember(createdRoomId, peerId, 0);
}
} else {
if (getActivity() instanceof ActivityMain && isAdded()) {
Log.wtf(this.getClass().getName(), "addMembersToGroup is done");
/* if (FragmentNewGroup.onRemoveFragmentNewGroup != null)
FragmentNewGroup.onRemoveFragmentNewGroup.onRemove();*/
G.refreshRealmUi();
/*popBackStackFragment();
popBackStackFragment();
removeFromBaseFragment(FragmentNewGroup.this);*/
((ActivityMain) getActivity()).removeAllFragmentFromMain();
new GoToChatActivity(createdRoomId).startActivity(getActivity());
}
}
}
use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.
the class ContactGroupFragment method onRightIconClickListener.
@Override
public void onRightIconClickListener(View view) {
fixChipsLayoutShowingState();
if (typeCreate.equals("CHANNEL")) {
G.onChannelAddMember = new OnChannelAddMember() {
@Override
public void onChannelAddMember(Long RoomId, Long UserId, ProtoGlobal.ChannelRoom.Role role) {
G.runOnUiThread(() -> {
progressDialog.dismiss();
countAddMemberResponse++;
addMember(RoomId, ProtoGlobal.Room.Type.CHANNEL);
countMember++;
if (countAddMemberResponse == countAddMemberRequest) {
addMember(RoomId, ProtoGlobal.Room.Type.CHANNEL);
}
});
}
@Override
public void onError(int majorCode, int minorCode) {
G.runOnUiThread(() -> {
progressDialog.dismiss();
countAddMemberResponse++;
if (countAddMemberResponse == countAddMemberRequest) {
addMember(roomId, ProtoGlobal.Room.Type.CHANNEL);
}
HelperError.showSnackMessage(requireContext().getResources().getString(R.string.error), false);
});
}
@Override
public void onTimeOut() {
G.runOnUiThread(() -> {
progressDialog.dismiss();
HelperError.showSnackMessage(requireContext().getResources().getString(R.string.time_out), false);
});
}
};
ArrayList<Long> list = getSelectedList();
if (list.size() > 0) {
for (long peerId : list) {
new RequestChannelAddMember().channelAddMember(roomId, peerId);
progressDialog.show();
progressDialog.setCancelable(false);
}
} else {
if (isAdded()) {
if (getActivity() instanceof ActivityMain) {
((ActivityMain) getActivity()).removeAllFragmentFromMain();
new GoToChatActivity(ContactGroupFragment.this.roomId).startActivity(getActivity());
}
}
}
} else if (typeCreate.equals("GROUP")) {
if (roomId == -127) {
if (getActivity() != null) {
FragmentNewGroup fragment = FragmentNewGroup.newInstance();
Bundle bundle_ = new Bundle();
bundle_.putString("TYPE", "NewGroup");
fragment.setArguments(bundle_);
new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load(true);
return;
}
}
G.onGroupAddMember = new OnGroupAddMember() {
@Override
public void onGroupAddMember(Long roomId, Long UserId) {
countAddMemberResponse++;
countMember++;
if (countAddMemberResponse == countAddMemberRequest) {
addMember(roomId, ProtoGlobal.Room.Type.GROUP);
}
}
@Override
public void onError(int majorCode, int minorCode) {
countAddMemberResponse++;
if (countAddMemberResponse == countAddMemberRequest) {
addMember(roomId, ProtoGlobal.Room.Type.GROUP);
}
}
};
/**
* request add member for group
*/
ArrayList<Long> list = getSelectedList();
if (list.size() > 0) {
for (long peerId : list) {
new RequestGroupAddMember().groupAddMember(roomId, peerId, 0);
}
} else {
if (getActivity() != null && isAdded()) {
removeFromBaseFragment(ContactGroupFragment.this);
new GoToChatActivity(ContactGroupFragment.this.roomId).startActivity(getActivity());
}
}
}
}
Aggregations