use of net.iGap.realm.RealmMember in project iGap-Android by KianIranian-STDG.
the class FragmentShowMember method getMemberList.
private void getMemberList() {
mMemberCount = listMembers.size();
infoUpdateListenerCount = (result, messageOne, MessageTow) -> {
if (MessageTow.contains("OK")) {
new Handler(Looper.getMainLooper()).post(() -> DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransactionAsync(realm12 -> {
final RealmList<RealmMember> newMemberList = new RealmList<>();
RealmRoom realmRoom = realm12.where(RealmRoom.class).equalTo("id", mRoomID).findFirst();
if (realmRoom != null) {
if (realmRoom.getType() == GROUP) {
for (ProtoGroupGetMemberList.GroupGetMemberListResponse.Member member : listMembers) {
if (Long.parseLong(messageOne) == member.getUserId()) {
mCurrentUpdateCount++;
newMemberList.add(RealmMember.put(realm12, member));
newMemberList.addAll(0, realmRoom.getGroupRoom().getMembers());
realmRoom.getGroupRoom().setMembers(newMemberList);
newMemberList.clear();
break;
}
}
} else {
for (ProtoChannelGetMemberList.ChannelGetMemberListResponse.Member member : listMembersChannal) {
if (Long.parseLong(messageOne) == member.getUserId()) {
mCurrentUpdateCount++;
newMemberList.add(RealmMember.put(realm12, member));
newMemberList.addAll(0, realmRoom.getChannelRoom().getMembers());
realmRoom.getChannelRoom().setMembers(newMemberList);
newMemberList.clear();
break;
}
}
}
}
}, () -> fillItem());
}));
} else {
mCurrentUpdateCount++;
}
};
G.onGroupGetMemberList = new OnGroupGetMemberList() {
@Override
public void onGroupGetMemberList(final List<ProtoGroupGetMemberList.GroupGetMemberListResponse.Member> members) {
mMemberCount = members.size();
if (mMemberCount > 0) {
listMembers.clear();
for (final ProtoGroupGetMemberList.GroupGetMemberListResponse.Member member : members) {
listMembers.add(member);
new RequestUserInfo().userInfoWithCallBack(infoUpdateListenerCount, member.getUserId(), "" + member.getUserId());
}
} else {
G.handler.post(() -> {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
});
isOne = true;
if (isFirstFill) {
fillAdapter();
isFirstFill = false;
}
}
}
@Override
public void onError(int majorCode, int minorCode) {
G.handler.post(() -> {
if (progressBar != null)
progressBar.setVisibility(View.GONE);
HelperError.showSnackMessage(G.currentActivity.getString(R.string.AccessBan), false);
});
}
@Override
public void onTimeOut() {
G.handler.post(() -> {
if (progressBar != null)
progressBar.setVisibility(View.GONE);
HelperError.showSnackMessage(G.currentActivity.getString(R.string.time_out), false);
});
}
};
G.onChannelGetMemberList = new OnChannelGetMemberList() {
@Override
public void onChannelGetMemberList(List<ProtoChannelGetMemberList.ChannelGetMemberListResponse.Member> members) {
mMemberCount = members.size();
if (mMemberCount > 0) {
listMembersChannal.clear();
for (final ProtoChannelGetMemberList.ChannelGetMemberListResponse.Member member : members) {
listMembersChannal.add(member);
new RequestUserInfo().userInfoWithCallBack(infoUpdateListenerCount, member.getUserId(), "" + member.getUserId());
}
} else {
G.handler.post(() -> {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
});
isOne = true;
if (isFirstFill) {
fillAdapter();
isFirstFill = false;
}
}
}
@Override
public void onError(int majorCode, int minorCode) {
G.handler.post(() -> {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
HelperError.showSnackMessage(requireActivity().getString(R.string.AccessBan), false);
}
});
}
@Override
public void onTimeOut() {
G.handler.post(() -> {
if (progressBar != null)
progressBar.setVisibility(View.GONE);
HelperError.showSnackMessage(requireActivity().getString(R.string.time_out), false);
});
}
};
G.handler.post(() -> {
mCurrentUpdateCount = 0;
DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransactionAsync(realm1 -> RealmMember.deleteAllMembers(realm1, mRoomID, selectedRole), () -> {
if (roomType == GROUP) {
new RequestGroupGetMemberList().getMemberList(mRoomID, offset, limit, ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.valueOf(selectedRole));
} else {
new RequestChannelGetMemberList().channelGetMemberList(mRoomID, offset, limit, ProtoChannelGetMemberList.ChannelGetMemberList.FilterRole.valueOf(selectedRole));
}
});
});
});
}
use of net.iGap.realm.RealmMember 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.realm.RealmMember 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