use of net.iGap.realm.RealmRoomAccess 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.realm.RealmRoomAccess in project iGap-Android by KianIranian-STDG.
the class FragmentChannelProfile method onViewCreated.
@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (currentRoomAccess != null) {
checkRoomAccess(currentRoomAccess);
roomAccessChangeListener = (realmRoomAccess, changeSet) -> checkRoomAccess(realmRoomAccess);
currentRoomAccess.addChangeListener(roomAccessChangeListener);
}
imvChannelAvatar = binding.toolbarAvatar;
imvChannelAvatar.setOnClickListener(v -> viewModel.onClickCircleImage());
binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
binding.toolbarMore.setOnClickListener(v -> showPopUp());
binding.toolbarEdit.setOnClickListener(v -> {
if (getActivity() != null && viewModel.checkIsEditableAndReturnState()) {
new HelperFragment(getActivity().getSupportFragmentManager(), EditChannelFragment.newInstance(viewModel.roomId)).setReplace(false).load();
}
});
viewModel.channelName.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.channelSecondsTitle.observe(getViewLifecycleOwner(), s -> binding.toolbarTxtStatusExpanded.setText(s));
viewModel.menuPopupVisibility.observe(getViewLifecycleOwner(), integer -> {
if (integer != null) {
binding.toolbarMore.setVisibility(integer);
}
});
viewModel.channelDescription.observe(getViewLifecycleOwner(), description -> {
if (getActivity() != null && description != null) {
binding.description.setText(HelperUrl.setUrlLink(getActivity(), description, true, false, null, true));
}
});
viewModel.goBack.observe(getViewLifecycleOwner(), goBack -> {
if (goBack != null && goBack) {
popBackStackFragment();
}
});
viewModel.muteNotifListener.observe(getViewLifecycleOwner(), isMute -> {
getRoomController().clientMuteRoom(viewModel.roomId, isMute);
binding.enableNotification.setChecked(isMute);
});
viewModel.goToRoomListPage.observe(getViewLifecycleOwner(), isGo -> {
if (getActivity() instanceof ActivityMain && isGo != null && isGo) {
((ActivityMain) getActivity()).removeAllFragmentFromMain();
/*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(2);*/
}
});
viewModel.goToShowMemberList.observe(getViewLifecycleOwner(), data -> {
if (getActivity() != null && data != null) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowMember.newInstance2(this, data.getRoomId(), data.getRole(), data.getUserId(), data.getSelectedRole(), data.isNeedGetMemberList(), false)).setReplace(false).load();
}
});
viewModel.showDialogCopyLink.observe(getViewLifecycleOwner(), link -> {
if (getActivity() != null && link != null) {
LinearLayout layoutChannelLink = new LinearLayout(getActivity());
layoutChannelLink.setOrientation(LinearLayout.VERTICAL);
View viewRevoke = new View(getActivity());
LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
TextInputLayout inputChannelLink = new TextInputLayout(getActivity());
MEditText edtLink = new MEditText(getActivity());
edtLink.setHint(R.string.channel_public_hint_revoke);
edtLink.setTypeface(ResourcesCompat.getFont(edtLink.getContext(), R.font.main_font));
edtLink.setText(link);
edtLink.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.dp14));
edtLink.setTextColor(new Theme().getTitleTextColor(getActivity()));
edtLink.setHintTextColor(getResources().getColor(R.color.hint_edit_text));
edtLink.setPadding(0, 8, 0, 8);
edtLink.setEnabled(false);
edtLink.setSingleLine(true);
inputChannelLink.addView(edtLink);
inputChannelLink.addView(viewRevoke, viewParams);
TextView txtLink = new AppCompatTextView(getActivity());
txtLink.setText(link);
txtLink.setTextColor(new Theme().getTitleTextColor(getActivity()));
viewRevoke.setBackgroundColor(getResources().getColor(R.color.line_edit_text));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
edtLink.setBackground(getResources().getDrawable(android.R.color.transparent));
}
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutChannelLink.addView(inputChannelLink, layoutParams);
layoutChannelLink.addView(txtLink, layoutParams);
if (getActivity() != null) {
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();
}
}
});
viewModel.goToSharedMediaPage.observe(getViewLifecycleOwner(), typeModel -> {
if (getActivity() != null && typeModel != null) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(typeModel)).setReplace(false).load();
}
});
viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), roomId -> {
if (getActivity() != null && roomId != null) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowAvatars.newInstance(roomId, FragmentShowAvatars.From.channel)).setReplace(false).load();
}
});
viewModel.showDialogLeaveChannel.observe(getViewLifecycleOwner(), isShow -> showDialogLeaveChannel());
viewModel.goToChatRoom.observe(getViewLifecycleOwner(), isGo -> {
if (getActivity() != null && isGo != null && isGo) {
((ActivityMain) getActivity()).removeAllFragmentFromMain();
}
});
viewModel.showErrorMessage.observe(getViewLifecycleOwner(), errorMessageResId -> {
if (errorMessageResId != null) {
HelperError.showSnackMessage(getString(errorMessageResId), false);
}
});
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;
});
// binding.description.setMovementMethod(LinkMovementMethod.getInstance());
AppUtils.setProgresColler(binding.loading);
FragmentShowAvatars.onComplete = (result, messageOne, MessageTow) -> {
long mAvatarId = 0;
if (messageOne != null && !messageOne.equals("")) {
mAvatarId = Long.parseLong(messageOne);
}
avatarHandler.avatarDelete(new ParamWithAvatarType(imvChannelAvatar, viewModel.roomId).avatarType(AvatarHandler.AvatarType.ROOM), mAvatarId);
};
setAvatar();
initialToolbar();
}
use of net.iGap.realm.RealmRoomAccess in project iGap-Android by KianIranian-STDG.
the class FragmentShowMember method initComponent.
private void initComponent(View view) {
mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setLogoShown(true).setSearchBoxShown(true).setListener(this);
LinearLayout layoutToolbar = view.findViewById(R.id.fcm_layout_toolbar);
layoutToolbar.addView(mHelperToolbar.getView());
mBtnAdd = view.findViewById(R.id.fcm_lbl_add);
realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("id", mRoomID).findFirst();
});
if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
if (isGroup) {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.member));
mBtnAdd.setText(context.getResources().getString(R.string.add_new_member));
} else {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.subscriber));
mBtnAdd.setText(context.getResources().getString(R.string.add_new_subscriber));
}
if (!isShowAddButton) {
mBtnAdd.setVisibility(View.GONE);
view.findViewById(R.id.fcm_splitter_add).setVisibility(View.GONE);
}
mBtnAdd.setVisibility(realmRoomAccess != null && realmRoomAccess.isCanAddNewMember() ? View.VISIBLE : View.GONE);
} else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.list_admin));
mBtnAdd.setText(context.getResources().getString(R.string.add_admin));
mBtnAdd.setVisibility(realmRoomAccess != null && realmRoomAccess.isCanAddNewAdmin() ? View.VISIBLE : View.GONE);
if (realmRoom != null) {
if (realmRoom.getGroupRoom() != null && realmRoom.getGroupRoom().getRole() == GroupChatRole.OWNER) {
mBtnAdd.setVisibility(View.VISIBLE);
}
if (realmRoom.getChannelRoom() != null && realmRoom.getChannelRoom().getRole() == ChannelChatRole.OWNER) {
mBtnAdd.setVisibility(View.VISIBLE);
}
}
} else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString())) {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.list_modereator));
mBtnAdd.setText(context.getResources().getString(R.string.add_modereator));
mBtnAdd.setVisibility(View.GONE);
if (realmRoom != null) {
if (realmRoom.getGroupRoom() != null && (realmRoom.getGroupRoom().getRole() == GroupChatRole.OWNER || realmRoom.getGroupRoom().getRole() == GroupChatRole.ADMIN)) {
mBtnAdd.setVisibility(View.VISIBLE);
}
if (realmRoom.getChannelRoom() != null && (realmRoom.getChannelRoom().getRole() == ChannelChatRole.OWNER || realmRoom.getChannelRoom().getRole() == ChannelChatRole.ADMIN)) {
mBtnAdd.setVisibility(View.VISIBLE);
}
}
}
mBtnAdd.setOnClickListener(v -> {
if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString()) || selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
openFragmentForAdd(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString(), selectedRole);
} else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
goToAddMember();
}
});
final EditText edtSearch = mHelperToolbar.getEditTextSearch();
edtSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(final Editable s) {
RealmResults<RealmMember> searchMember = DbManager.getInstance().doRealmTask(realm -> {
return RealmMember.filterMember(realm, mRoomID, s.toString(), getUnselectRow(), selectedRole);
});
mAdapter = new MemberAdapter(searchMember, roomType, mMainRole, userID);
mRecyclerView.setAdapter(mAdapter);
}
});
mRecyclerView = view.findViewById(R.id.fcm_recycler_view_show_member);
mRecyclerView.setItemViewCacheSize(100);
mRecyclerView.setItemAnimator(null);
mRecyclerView.setLayoutManager(new LinearLayoutManager(G.fragmentActivity));
final PreCachingLayoutManager preCachingLayoutManager = new PreCachingLayoutManager(G.fragmentActivity, DeviceUtils.getScreenHeight(G.fragmentActivity));
mRecyclerView.setLayoutManager(preCachingLayoutManager);
progressBar = view.findViewById(R.id.fcg_prgWaiting);
AppUtils.setProgresColler(progressBar);
// TextView txtNumberOfMember = (TextView) view.findViewById(R.id.fcg_txt_member);
// if (selectedRole.toString().equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString())) {
// txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(R.string.list_modereator));
// } else if (selectedRole.toString().equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
// txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(R.string.list_admin));
// } else {
// txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(member));
// }
scrollListener = new EndlessRecyclerViewScrollListener(preCachingLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
// Triggered only when new data needs to be appended to the list
// Add whatever code is needed to append new items to the bottom of the list
loadMoreMember();
}
};
mRecyclerView.addOnScrollListener(scrollListener);
}
Aggregations