Search in sources :

Example 1 with RequestChannelAddMember

use of net.iGap.request.RequestChannelAddMember 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();
    }
}
Also used : StructContactInfo(net.iGap.module.structs.StructContactInfo) Bundle(android.os.Bundle) OnSelectedList(net.iGap.observers.interfaces.OnSelectedList) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) HelperFragment(net.iGap.helper.HelperFragment) RealmMember(net.iGap.realm.RealmMember) RequestChannelAddMember(net.iGap.request.RequestChannelAddMember)

Example 2 with RequestChannelAddMember

use of net.iGap.request.RequestChannelAddMember 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());
            }
        }
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) ActivityMain(net.iGap.activities.ActivityMain) OnChannelAddMember(net.iGap.observers.interfaces.OnChannelAddMember) GoToChatActivity(net.iGap.helper.GoToChatActivity) OnGroupAddMember(net.iGap.observers.interfaces.OnGroupAddMember) HelperFragment(net.iGap.helper.HelperFragment) RequestChannelAddMember(net.iGap.request.RequestChannelAddMember)

Aggregations

Bundle (android.os.Bundle)2 HelperFragment (net.iGap.helper.HelperFragment)2 RequestChannelAddMember (net.iGap.request.RequestChannelAddMember)2 RequestGroupAddMember (net.iGap.request.RequestGroupAddMember)2 ArrayList (java.util.ArrayList)1 ActivityMain (net.iGap.activities.ActivityMain)1 GoToChatActivity (net.iGap.helper.GoToChatActivity)1 StructContactInfo (net.iGap.module.structs.StructContactInfo)1 OnChannelAddMember (net.iGap.observers.interfaces.OnChannelAddMember)1 OnGroupAddMember (net.iGap.observers.interfaces.OnGroupAddMember)1 OnSelectedList (net.iGap.observers.interfaces.OnSelectedList)1 RealmMember (net.iGap.realm.RealmMember)1