Search in sources :

Example 1 with ScrollingLinearLayoutManager

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

the class FragmentSyncRegisteredContacts method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    G.onPhoneContact = this;
    G.onContactsGetList = this;
    Contacts.localPhoneContactId = 0;
    Contacts.getContact = true;
    userID = this.getArguments().getLong(ARG_USER_ID);
    // Toolbar Initial
    LinearLayout toolbarLayout = view.findViewById(R.id.frg_contact_ll_toolbar_layout);
    mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setSearchBoxShown(true).setLogoShown(true).setDefaultTitle(getString(R.string.str_frag_sync_contactWelcome));
    toolbarLayout.addView(mHelperToolbar.getView());
    mHelperToolbar.setListener(this);
    prgWaiting = view.findViewById(R.id.prgWaiting_addContact);
    AppUtils.setProgresColler(prgWaiting);
    Bundle bundle = this.getArguments();
    String title = null;
    if (bundle != null) {
        title = bundle.getString("TITLE");
        isCallAction = bundle.getBoolean("ACTION");
    }
    // My Code H.Amini
    // ContactUtils.syncContacts();
    realmRecyclerView = view.findViewById(R.id.recycler_view);
    realmRecyclerView.setItemViewCacheSize(1000);
    realmRecyclerView.setItemAnimator(null);
    layoutManager = new LinearLayoutManager(realmRecyclerView.getContext());
    realmRecyclerView.setLayoutManager(layoutManager);
    // get all the contacts from realm
    results = DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmContacts.class).findAll().sort("display_name");
    });
    results.addChangeListener(new RealmChangeListener<RealmResults<RealmContacts>>() {

        @Override
        public void onChange(@NotNull RealmResults<RealmContacts> realmContacts) {
            if (realmContacts.size() > 0) {
                fastScroller.setVisibility(View.VISIBLE);
            }
            contactListAdapter2.notifyDataSetChanged();
        }
    });
    // Load all of the data
    // contactListAdapter = new FragmentSyncRegisteredContacts.ContactListAdapter(results);
    contactListAdapter2 = new ContactListAdapter2(results);
    // realmRecyclerView.setAdapter(contactListAdapter);
    realmRecyclerView.setAdapter(contactListAdapter2);
    realmRecyclerView.setVisibility(View.VISIBLE);
    realmRecyclerView.setLayoutManager(new ScrollingLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false, 1000));
    realmRecyclerView.setNestedScrollingEnabled(false);
    fastScroller = view.findViewById(R.id.fast_scroller);
    fastScroller.setRecyclerView(realmRecyclerView);
    fastScroller.setVisibility(View.GONE);
    // going to app directly
    skipBtn = view.findViewById(R.id.frag_sync_skipbtn);
    skipBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getActivity() != null) {
                Intent intent = new Intent(getActivity(), ActivityMain.class);
                intent.putExtra(ARG_USER_ID, userID);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getActivity().startActivity(intent);
                getActivity().finish();
            }
        }
    });
    /*FragmentSyncRegisteredContacts.StickyHeader stickyHeader = new FragmentSyncRegisteredContacts.StickyHeader(results);
        decoration = new StickyRecyclerHeadersDecoration(stickyHeader);
        realmRecyclerView.addItemDecoration(decoration);*/
    onCliclRecyclerView = new FragmentSyncRegisteredContacts.onClickRecyclerView() {

        @Override
        public void onClick(View view, int position) {
            if (isMultiSelect) {
            }
        }
    };
    // get permission for contacts
    try {
        if (getPermission) {
            getPermission = false;
            HelperPermission.getContactPermision(G.fragmentActivity, new OnGetPermission() {

                @Override
                public void Allow() throws IOException {
                    /**
                     * if contacts size is zero send request for get contacts list
                     * for insuring that contacts not exist really or not
                     */
                    if (results.size() == 0) {
                        LoginActions.importContact();
                    }
                }

                @Override
                public void deny() {
                    /*if (results.size() == 0) {
                            new RequestUserContactsGetList().userContactGetList();
                        }*/
                    if (getActivity() == null || getActivity().isFinishing()) {
                        return;
                    }
                    Intent intent = new Intent(getContext(), ActivityMain.class);
                    intent.putExtra(ARG_USER_ID, userID);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    G.context.startActivity(intent);
                    G.fragmentActivity.finish();
                }
            });
        } else {
            if (results.size() == 0) {
                new RequestUserContactsGetList().userContactGetList();
            } else {
                hideProgress();
            }
        /*if (HelperPermission.grantedContactPermission()) {
                    new Contacts.FetchContactForClient().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                } else {
                    hideProgress();
                }*/
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) AppUtils(net.iGap.module.AppUtils) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) ProgressBar(android.widget.ProgressBar) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) G(net.iGap.G) FragmentSyncRegisteredContactsBinding(net.iGap.databinding.FragmentSyncRegisteredContactsBinding) HelperPublicMethod(net.iGap.helper.HelperPublicMethod) LoginActions(net.iGap.module.LoginActions) FastScrollerBarBaseAdapter(net.iGap.module.scrollbar.FastScrollerBarBaseAdapter) HelperPermission(net.iGap.helper.HelperPermission) View(android.view.View) Button(android.widget.Button) HelperError(net.iGap.helper.HelperError) RecyclerView(androidx.recyclerview.widget.RecyclerView) DataBindingUtil(androidx.databinding.DataBindingUtil) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) OnPhoneContact(net.iGap.observers.interfaces.OnPhoneContact) AsyncTask(android.os.AsyncTask) ContactManager(net.iGap.helper.ContactManager) ProtoSignalingOffer(net.iGap.proto.ProtoSignalingOffer) RequestUserContactsGetList(net.iGap.request.RequestUserContactsGetList) ViewGroup(android.view.ViewGroup) DefaultRoundDialog(net.iGap.module.dialog.DefaultRoundDialog) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) ScrollingLinearLayoutManager(net.iGap.module.ScrollingLinearLayoutManager) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Case(io.realm.Case) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) HelperToolbar(net.iGap.helper.HelperToolbar) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) RealmChangeListener(io.realm.RealmChangeListener) StructListOfContact(net.iGap.module.structs.StructListOfContact) ActivityMain(net.iGap.activities.ActivityMain) AccountManager(net.iGap.module.accountManager.AccountManager) Intent(android.content.Intent) RealmContacts(net.iGap.realm.RealmContacts) ArrayList(java.util.ArrayList) Contacts(net.iGap.module.Contacts) OnContactsGetList(net.iGap.observers.interfaces.OnContactsGetList) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) LayoutInflater(android.view.LayoutInflater) RealmResults(io.realm.RealmResults) CheckBox(net.iGap.module.customView.CheckBox) IOException(java.io.IOException) CircleImageView(net.iGap.module.CircleImageView) Gravity(android.view.Gravity) FastScroller(net.iGap.module.scrollbar.FastScroller) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) Bundle(android.os.Bundle) ScrollingLinearLayoutManager(net.iGap.module.ScrollingLinearLayoutManager) Intent(android.content.Intent) IOException(java.io.IOException) ScrollingLinearLayoutManager(net.iGap.module.ScrollingLinearLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) CircleImageView(net.iGap.module.CircleImageView) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) ActivityMain(net.iGap.activities.ActivityMain) RequestUserContactsGetList(net.iGap.request.RequestUserContactsGetList) LinearLayout(android.widget.LinearLayout) RealmContacts(net.iGap.realm.RealmContacts) RealmResults(io.realm.RealmResults)

Example 2 with ScrollingLinearLayoutManager

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

the class ContactGroupFragment method onViewCreated.

@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    progressDialog = new ProgressDialog(getContext());
    // to disable swipe in channel creation mode
    if (typeCreate != null) {
        if (typeCreate.equals("CHANNEL"))
            getSwipeBackLayout().setEnableGesture(false);
    }
    selectedContacts.clear();
    G.onContactsGetList = this;
    // some times touch screen remind lock so this method do unlock
    hideProgressBar();
    Bundle bundle = this.getArguments();
    if (bundle != null) {
        roomId = bundle.getLong("RoomId");
        typeCreate = bundle.getString("TYPE");
    }
    HelperToolbar mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setRightIcons(R.string.icon_sent).setDefaultTitle(G.context.getResources().getString(R.string.new_group)).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));
    }
    if (typeCreate.equals("CHANNEL")) {
        mHelperToolbar.setDefaultTitle(G.context.getResources().getString(R.string.new_channel));
    }
    chipsInput = view.findViewById(R.id.chips_input);
    // 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());
    itemAdapter = new ItemAdapter();
    fastAdapter = FastAdapter.with(itemAdapter);
    fastAdapter.withSelectable(true);
    fastAdapter.setHasStableIds(true);
    rv.setAdapter(fastAdapter);
    addItems();
    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);
                selectedContacts.remove(item.mContact);
            } 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;
        }
    });
    chipsInput.addChipsListener(new ChipsInput.ChipsListener() {

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

        @Override
        public void onChipRemoved(ChipInterface chip, int newSize) {
            if (chip.getId() != null) {
                ContactItemGroup contactInfo = ((ContactItemGroup) fastAdapter.getItem(fastAdapter.getPosition((Long) chip.getId())));
                notifyAdapter(contactInfo, fastAdapter.getPosition((Long) chip.getId()));
                isRemove = false;
                selectedContacts.remove(contactInfo.mContact);
            }
        }

        @Override
        public void onTextChanged(CharSequence text) {
        // text changed
        }
    });
    initContactRemoveListener();
    // restore selections (this has to be done after the items were added
    fastAdapter.withSavedInstanceState(savedInstanceState);
}
Also used : ScrollingLinearLayoutManager(net.iGap.module.ScrollingLinearLayoutManager) FastScroller(net.iGap.module.scrollbar.FastScroller) ProgressDialog(net.iGap.messenger.ui.components.ProgressDialog) 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) HelperToolbar(net.iGap.helper.HelperToolbar) 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) RecyclerView(androidx.recyclerview.widget.RecyclerView) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 3 with ScrollingLinearLayoutManager

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

the class RegisteredContactsFragment method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (getContext() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        StatusBarUtil.setColor(getActivity(), new Theme().getPrimaryDarkColor(getContext()), 50);
    }
    G.onContactImport = this;
    G.onUserContactdelete = this;
    G.onContactsGetList = this;
    tryRequest = 0;
    realmRecyclerView = view.findViewById(R.id.recycler_view);
    FrameLayout toolbarLayout = view.findViewById(R.id.frg_contact_ll_toolbar_layout);
    contactsToolbar = new Toolbar(getContext());
    mediaContainer = new FragmentMediaContainer(getContext(), this);
    mediaContainer.setListener(i -> {
        switch(i) {
            case FragmentMediaContainer.CALL_TAG:
                getActivity().startActivity(new Intent(getContext(), CallActivity.class));
                break;
            case FragmentMediaContainer.MEDIA_TAG:
                if (!MusicPlayer.isVoice) {
                    Intent intent = new Intent(context, ActivityMain.class);
                    intent.putExtra(ActivityMain.openMediaPlayer, true);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getActivity().startActivity(intent);
                }
                break;
            case FragmentMediaContainer.PLAY_TAG:
                break;
        }
    });
    ToolbarItems toolbarItems = contactsToolbar.createToolbarItems();
    contactsToolbar.setTitle(getString(R.string.contacts));
    contactsToolbar.setBackIcon(new BackDrawable(false));
    if (isContact) {
        ToolbarItem moreItem = toolbarItems.addItemWithWidth(moreItemTag, R.string.icon_other_vertical_dots, 54);
        addItem = moreItem.addSubItem(addUserTag, R.string.icon_add, getResources().getString(R.string.menu_add_contact));
        moreItem.addSubItem(syncContactTag, R.string.icon_beeptunes_sync, getResources().getString(R.string.sync_contact));
        moreItem.addSubItem(inviteContactTag, R.string.icon_add_contact, getResources().getString(R.string.Invite_Friends));
        if (PassCode.getInstance().isPassCode()) {
            passCodeItem = toolbarItems.addItemWithWidth(passCodeTag, R.string.icon_unlock, 54);
        }
    }
    searchItem = toolbarItems.addItemWithWidth(searchTag, R.string.icon_search, 54).setIsSearchBox(true).setActionBarMenuItemSearchListener(new ToolbarItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            isSearchEnabled = true;
            inSearchMode = true;
        }

        @Override
        public void onSearchCollapse() {
            isSearchEnabled = false;
            inSearchMode = false;
            loadContacts();
        }

        @Override
        public void onTextChanged(EditText editText) {
            String text = null;
            try {
                text = java.net.URLDecoder.decode(editText.getText().toString(), "UTF-8");
                if (text.length() > 0) {
                    searchText = text;
                    loadContact(text);
                } else {
                    loadContacts();
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    });
    if (!isContact) {
        contactsToolbar.setBackIcon(new BackDrawable(false));
        toolbarItems.addItemWithWidth(addUserTag, R.string.icon_add_contact, 54);
    } else {
        toolbarItems.addItemWithWidth(codeScannerTag, R.string.icon_QR_code, 54);
    }
    if (mPageMode == CALL) {
        contactsToolbar.setTitle(getString(R.string.make_call));
    } else if (mPageMode == ADD) {
        contactsToolbar.setTitle(getString(R.string.create_chat));
    }
    createActionMode();
    toolbarLayout.addView(mediaContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, 38, Gravity.BOTTOM, 0, 60, 0, 0));
    toolbarLayout.addView(contactsToolbar);
    contactsToolbar.setListener(i -> {
        switch(i) {
            case -1:
                if (!isContact) {
                    if (!contactsToolbar.isSearchFieldVisible()) {
                        popBackStackFragment();
                    }
                } else {
                    if (isMultiSelect) {
                        contactsToolbar.hideActionToolbar();
                        contactsToolbar.setBackIcon(new BackDrawable(false));
                        setMultiSelectState(isMultiSelect);
                    } else {
                        if (!isSearchEnabled) {
                            requireActivity().onBackPressed();
                        }
                    }
                }
                break;
            case editTag:
                if (results != null) {
                    for (RealmContacts realmContacts : results) {
                        if (realmContacts.getPhone() == (Long) selectedList.keySet().toArray()[0]) {
                            FragmentAddContact fragment = FragmentAddContact.newInstance(realmContacts.getId(), "+" + realmContacts.getPhone(), realmContacts.getFirst_name(), realmContacts.getLast_name(), FragmentAddContact.ContactMode.EDIT, (name1, family1) -> loadContacts());
                            if (getActivity() != null)
                                new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
                            contactsToolbar.hideActionToolbar();
                            setMultiSelectState(isMultiSelect);
                            contactsToolbar.setBackIcon(null);
                            return;
                        }
                    }
                }
                break;
            case deleteTag:
                new MaterialDialog.Builder(G.fragmentActivity).title(R.string.to_delete_contact).content(R.string.delete_text).positiveText(R.string.B_ok).onPositive((dialog, which) -> {
                    for (ArrayMap.Entry<Long, Boolean> entry : selectedList.entrySet()) {
                        new RequestUserContactsDelete().contactsDelete("" + entry.getKey());
                    }
                    setMultiSelectState(true);
                    contactsToolbar.hideActionToolbar();
                    contactsToolbar.setBackIcon(null);
                }).negativeText(R.string.B_cancel).show();
                break;
            case addUserTag:
                if (mActionMode != null) {
                    mActionMode.finish();
                }
                if (getActivity() != null) {
                    FragmentAddContact fragment = FragmentAddContact.newInstance(null, FragmentAddContact.ContactMode.ADD);
                    new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
                }
                break;
            case multiSelectTag:
                showDialog();
                break;
            case codeScannerTag:
                onCodeScannerClickListener();
                break;
            case syncContactTag:
                if (isMultiSelect)
                    setMultiSelectState(true);
                ContactUtils.syncContacts();
                break;
            case inviteContactTag:
                try {
                    HelperPermission.getContactPermision(getContext(), new OnGetPermission() {

                        @Override
                        public void Allow() {
                            HelperTracker.sendTracker(HelperTracker.TRACKER_INVITE_FRIEND);
                            new HelperFragment(getActivity().getSupportFragmentManager(), new LocalContactFragment()).setReplace(false).load();
                        }

                        @Override
                        public void deny() {
                            showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case passCodeTag:
                if (passCodeItem == null) {
                    return;
                }
                if (ActivityMain.isLock) {
                    passCodeItem.setIcon(R.string.icon_unlock);
                    ActivityMain.isLock = false;
                    HelperPreferences.getInstance().putBoolean(SHP_SETTING.FILE_NAME, SHP_SETTING.KEY_LOCK_STARTUP_STATE, false);
                } else {
                    passCodeItem.setIcon(R.string.icon_lock);
                    ActivityMain.isLock = true;
                    HelperPreferences.getInstance().putBoolean(SHP_SETTING.FILE_NAME, SHP_SETTING.KEY_LOCK_STARTUP_STATE, true);
                }
                checkPassCodeVisibility();
                break;
        }
    });
    if (isContact) {
        Contacts.localPhoneContactId = 0;
        Contacts.getContact = true;
    }
    prgMainLoader = view.findViewById(R.id.fc_loader_main);
    btnAddNewGroupCall = view.findViewById(R.id.menu_layout_new_group_call);
    btnDialNumber = view.findViewById(R.id.menu_layout_btn_dial_number);
    btnAddNewGroup = view.findViewById(R.id.menu_layout_add_new_group);
    btnAddNewChannel = view.findViewById(R.id.menu_layout_add_new_channel);
    fastScroller = view.findViewById(R.id.fs_contact_fastScroller);
    prgWaitingLoadList = view.findViewById(R.id.prgWaiting_loadList);
    realmRecyclerView.setAdapter(new ContactListAdapter());
    if (!inSearchMode)
        loadContacts();
    switch(mPageMode) {
        case CALL:
            btnDialNumber.setVisibility(View.GONE);
            if (addItem != null) {
            // addItem.setVisibility(View.GONE);
            }
            break;
        case ADD:
            btnAddNewChannel.setVisibility(View.VISIBLE);
            btnAddNewGroup.setVisibility(View.VISIBLE);
            break;
        case CONTACTS:
    }
    realmRecyclerView = view.findViewById(R.id.recycler_view);
    realmRecyclerView.setLayoutManager(new ScrollingLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false, 1000));
    realmRecyclerView.setNestedScrollingEnabled(false);
    fastScroller.setRecyclerView(realmRecyclerView);
    onClickRecyclerView = (v, position) -> {
        if (isMultiSelect) {
            multi_select(position);
        }
    };
    onLongClickRecyclerView = (v, position) -> {
        if (!isMultiSelect) {
            isMultiSelect = true;
            refreshAdapter(0, true);
            if (!contactsToolbar.isInActionMode()) {
                setPageShowingMode(4);
            }
        }
        multi_select(position);
    };
    try {
        if (getPermission && isContact) {
            getPermission = false;
            HelperPermission.getContactPermision(getContext(), new OnGetPermission() {

                @Override
                public void Allow() throws IOException {
                    /**
                     * if contacts size is zero send request for get contacts list
                     * for insure that contacts not exist really or not
                     */
                    LoginActions.importContact();
                    prgMainLoader.setVisibility(View.GONE);
                }

                @Override
                public void deny() {
                    if (results.size() == 0) {
                        new RequestUserContactsGetList().userContactGetList();
                    }
                    prgMainLoader.setVisibility(View.GONE);
                }
            });
        } else {
            if (results.size() == 0) {
                LoginActions.importContact();
            }
            prgMainLoader.setVisibility(View.GONE);
        }
    } catch (IOException e) {
        e.printStackTrace();
        prgMainLoader.setVisibility(View.GONE);
    }
    btnAddNewChannel.setOnClickListener(v -> {
        if (getActivity() != null) {
            FragmentNewGroup fragment = FragmentNewGroup.newInstance();
            Bundle bundle_ = new Bundle();
            bundle_.putString("TYPE", "NewChanel");
            fragment.setArguments(bundle_);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
        }
    });
    btnAddNewGroup.setOnClickListener(v -> {
        if (getActivity() != null) {
            Fragment fragment = ContactGroupFragment.newInstance();
            Bundle bundle1 = new Bundle();
            bundle1.putLong("RoomId", -127);
            bundle1.putString("LIMIT", "5000");
            bundle1.putString("TYPE", ProtoGlobal.Room.Type.GROUP.name());
            bundle1.putBoolean("NewRoom", true);
            fragment.setArguments(bundle1);
            if (FragmentNewGroup.onRemoveFragmentNewGroup != null) {
                Log.wtf(this.getClass().getName(), "onRemoveFragmentNewGroup");
                FragmentNewGroup.onRemoveFragmentNewGroup.onRemove();
            }
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
        }
    });
    btnDialNumber.setOnClickListener(v -> {
        if (getActivity() != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), new DailNumberFragment()).setReplace(false).load();
        }
    });
    // todo: fixed it ,effect in load time
    if (isMultiSelect) {
        refreshAdapter(0, true);
        if (!contactsToolbar.isInActionMode()) {
            Log.wtf(this.getClass().getName(), "setPageShowingMode 4");
            setPageShowingMode(4);
        }
        isLongClick = true;
    }
}
Also used : ScrollingLinearLayoutManager(net.iGap.module.ScrollingLinearLayoutManager) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) CallActivity(net.iGap.activities.CallActivity) Fragment(androidx.fragment.app.Fragment) BottomSheetFragment(net.iGap.module.dialog.bottomsheet.BottomSheetFragment) HelperFragment(net.iGap.helper.HelperFragment) ScanCodeQRCodePaymentFragment(net.iGap.fragments.qrCodePayment.fragments.ScanCodeQRCodePaymentFragment) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) ToolbarItem(net.iGap.messenger.ui.toolBar.ToolbarItem) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) EditText(android.widget.EditText) FragmentMediaContainer(net.iGap.messenger.ui.components.FragmentMediaContainer) Bundle(android.os.Bundle) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayMap(androidx.collection.ArrayMap) Intent(android.content.Intent) IOException(java.io.IOException) RequestUserContactsDelete(net.iGap.request.RequestUserContactsDelete) FrameLayout(android.widget.FrameLayout) ToolbarItems(net.iGap.messenger.ui.toolBar.ToolbarItems) Theme(net.iGap.module.Theme) RequestUserContactsGetList(net.iGap.request.RequestUserContactsGetList) HelperFragment(net.iGap.helper.HelperFragment) RealmContacts(net.iGap.realm.RealmContacts)

Example 4 with ScrollingLinearLayoutManager

use of net.iGap.module.ScrollingLinearLayoutManager 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

Bundle (android.os.Bundle)4 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 LinearLayout (android.widget.LinearLayout)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 ScrollingLinearLayoutManager (net.iGap.module.ScrollingLinearLayoutManager)3 Intent (android.content.Intent)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)2 IAdapter (com.mikepenz.fastadapter.IAdapter)2 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)2 ItemAdapter (com.mikepenz.fastadapter.adapters.ItemAdapter)2 ChipsInput (com.pchmn.materialchips.ChipsInput)2 ChipInterface (com.pchmn.materialchips.model.ChipInterface)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ContactItemGroup (net.iGap.adapter.items.ContactItemGroup)2