Search in sources :

Example 1 with StructContactInfo

use of net.iGap.module.structs.StructContactInfo in project iGap-Android by KianIranian-STDG.

the class ContactGroupFragment method addItems.

private void addItems() {
    List<IItem> items = new ArrayList<>();
    contacts = Contacts.retrieve(null);
    if (contacts.size() == 0) {
        LoginActions.importContact();
    } else {
        for (StructContactInfo contact : contacts) {
            if (contact != null) {
                items.add(new ContactItemGroup(avatarHandler).setContact(contact).withIdentifier(contact.peerId));
                Uri uri = null;
                if (contact.avatar != null && contact.avatar.getFile() != null && contact.avatar.getFile().getLocalThumbnailPath() != null) {
                    uri = Uri.fromFile(new File(contact.avatar.getFile().getLocalThumbnailPath()));
                }
                ContactChip contactChip;
                if (uri == null) {
                    Drawable d = new BitmapDrawable(getResources(), net.iGap.helper.HelperImageBackColor.drawAlphabetOnPicture((int) G.context.getResources().getDimension(R.dimen.dp60), contact.initials, contact.color));
                    contactChip = new ContactChip(contact.peerId, d, contact.displayName);
                } else {
                    contactChip = new ContactChip(contact.peerId, uri, contact.displayName);
                }
                mContactList.add(contactChip);
            }
        }
        chipsInput.setFilterableList(mContactList);
        itemAdapter.add(items);
    }
}
Also used : StructContactInfo(net.iGap.module.structs.StructContactInfo) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IItem(com.mikepenz.fastadapter.IItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Uri(android.net.Uri) File(java.io.File) ContactChip(net.iGap.module.ContactChip) ContactItemGroup(net.iGap.adapter.items.ContactItemGroup)

Example 2 with StructContactInfo

use of net.iGap.module.structs.StructContactInfo 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 3 with StructContactInfo

use of net.iGap.module.structs.StructContactInfo in project iGap-Android by KianIranian-STDG.

the class ShowCustomList method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Bundle bundle = this.getArguments();
    if (bundle != null) {
        dialogShowing = bundle.getBoolean("DIALOG_SHOWING");
        if (bundle.getLong("COUNT_MESSAGE") != 0) {
            lastId = bundle.getLong("COUNT_MESSAGE");
        }
        singleSelect = bundle.getBoolean("SINGLE_SELECT");
    }
    mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setRightIcons(R.string.icon_sent).setDefaultTitle(getString(R.string.add_new_member)).setListener(this).setLogoShown(true);
    LinearLayout toolbarLayout = view.findViewById(R.id.fcg_layout_toolbar);
    toolbarLayout.addView(mHelperToolbar.getView());
    /**
     * for some problem in theme we created 2 layout and check theme then add at run time
     * library does not support change text color or background color at run time until 1.0.8
     */
    ViewGroup layoutChips = view.findViewById(R.id.fcg_layout_search);
    // todo:// use material chips
    if (G.themeColor == Theme.DARK) {
        layoutChips.addView(getLayoutInflater().inflate(R.layout.item_chips_layout_dark, null));
    } else {
        layoutChips.addView(getLayoutInflater().inflate(R.layout.item_chips_layout, null));
    }
    chipsInput = view.findViewById(R.id.chips_input);
    final ItemAdapter itemAdapter = new ItemAdapter();
    fastAdapter = FastAdapter.with(itemAdapter);
    fastAdapter.withSelectable(true);
    fastAdapter.setHasStableIds(true);
    // get our recyclerView and do basic setup
    RecyclerView rv = view.findViewById(R.id.fcg_recycler_view_add_item_to_group);
    rv.setLayoutManager(new ScrollingLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false, 1000));
    rv.setItemAnimator(new DefaultItemAnimator());
    rv.setAdapter(fastAdapter);
    FastScroller fastScroller = view.findViewById(R.id.fast_scroller);
    fastScroller.setRecyclerView(rv);
    itemAdapter.getItemFilter().withFilterPredicate(new IItemAdapter.Predicate<ContactItemGroup>() {

        @Override
        public boolean filter(ContactItemGroup item, CharSequence constraint) {
            return !item.mContact.displayName.toLowerCase().startsWith(String.valueOf(constraint).toLowerCase());
        }
    });
    fastAdapter.withOnClickListener(new OnClickListener<ContactItemGroup>() {

        @Override
        public boolean onClick(View v, IAdapter adapter, ContactItemGroup item, int position) {
            if (item.mContact.isSelected) {
                chipsInput.removeChipByLabel(item.mContact.displayName);
            } else {
                Uri uri = null;
                if (item.mContact.avatar != null && item.mContact.avatar.getFile() != null && item.mContact.avatar.getFile().getLocalThumbnailPath() != null) {
                    uri = Uri.fromFile(new File(item.mContact.avatar.getFile().getLocalThumbnailPath()));
                }
                if (uri == null) {
                    Drawable d = new BitmapDrawable(getResources(), net.iGap.helper.HelperImageBackColor.drawAlphabetOnPicture((int) G.context.getResources().getDimension(R.dimen.dp60), item.mContact.initials, item.mContact.color));
                    chipsInput.addChip(item.mContact.peerId, d, item.mContact.displayName, "");
                } else {
                    chipsInput.addChip(item.mContact.peerId, uri, item.mContact.displayName, "");
                }
            }
            if (isRemove) {
                notifyAdapter(item, position);
            }
            return false;
        }
    });
    List<IItem> items = new ArrayList<>();
    for (StructContactInfo contact : contacts) {
        if (contact != null) {
            items.add(new ContactItemGroup(avatarHandler).setContact(contact).withIdentifier(contact.peerId));
            Uri uri = null;
            if (contact.avatar != null && contact.avatar.getFile() != null && contact.avatar.getFile().getLocalThumbnailPath() != null) {
                uri = Uri.fromFile(new File(contact.avatar.getFile().getLocalThumbnailPath()));
            }
            ContactChip contactChip;
            if (uri == null) {
                Drawable d = new BitmapDrawable(getResources(), net.iGap.helper.HelperImageBackColor.drawAlphabetOnPicture((int) G.context.getResources().getDimension(R.dimen.dp60), contact.initials, contact.color));
                contactChip = new ContactChip(contact.peerId, d, contact.displayName);
            } else {
                contactChip = new ContactChip(contact.peerId, uri, contact.displayName);
            }
            mContactList.add(contactChip);
        }
    }
    chipsInput.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    chipsInput.setFilterableList(mContactList);
    itemAdapter.add(items);
    chipsInput.addChipsListener(new ChipsInput.ChipsListener() {

        @Override
        public void onChipAdded(ChipInterface chip, int newSize) {
            try {
                if (chip != null) {
                    notifyAdapter(((ContactItemGroup) fastAdapter.getItem(fastAdapter.getPosition((Long) chip.getId()))), fastAdapter.getPosition((Long) chip.getId()));
                    isRemove = false;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onChipRemoved(ChipInterface chip, int newSize) {
            notifyAdapter(((ContactItemGroup) fastAdapter.getItem(fastAdapter.getPosition((Long) chip.getId()))), fastAdapter.getPosition((Long) chip.getId()));
            isRemove = false;
        }

        @Override
        public void onTextChanged(CharSequence text) {
        // text changed
        }
    });
    // restore selections (this has to be done after the items were added
    fastAdapter.withSavedInstanceState(savedInstanceState);
}
Also used : StructContactInfo(net.iGap.module.structs.StructContactInfo) ScrollingLinearLayoutManager(net.iGap.module.ScrollingLinearLayoutManager) ArrayList(java.util.ArrayList) FastScroller(net.iGap.module.scrollbar.FastScroller) Uri(android.net.Uri) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ContactItemGroup(net.iGap.adapter.items.ContactItemGroup) ChipsInput(com.pchmn.materialchips.ChipsInput) IItemAdapter(com.mikepenz.fastadapter.IItemAdapter) IItem(com.mikepenz.fastadapter.IItem) IAdapter(com.mikepenz.fastadapter.IAdapter) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter) IItemAdapter(com.mikepenz.fastadapter.IItemAdapter) ChipInterface(com.pchmn.materialchips.model.ChipInterface) Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) File(java.io.File) ContactChip(net.iGap.module.ContactChip) LinearLayout(android.widget.LinearLayout)

Aggregations

StructContactInfo (net.iGap.module.structs.StructContactInfo)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 IItem (com.mikepenz.fastadapter.IItem)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ContactItemGroup (net.iGap.adapter.items.ContactItemGroup)2 ContactChip (net.iGap.module.ContactChip)2 SuppressLint (android.annotation.SuppressLint)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 IAdapter (com.mikepenz.fastadapter.IAdapter)1 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)1 ItemAdapter (com.mikepenz.fastadapter.adapters.ItemAdapter)1 ChipsInput (com.pchmn.materialchips.ChipsInput)1