Search in sources :

Example 1 with Contacts

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

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

the class FragmentSyncRegisteredContacts method onContactsGetList.

@Override
public void onContactsGetList() {
    if (getActivity() == null || getActivity().isFinishing()) {
        return;
    }
    if (results == null || results.size() == 0) {
        results = DbManager.getInstance().doRealmTask(realm -> {
            return realm.where(RealmContacts.class).limit(ContactManager.CONTACT_LIMIT).findAll().sort("display_name");
        });
        contactListAdapter2 = new ContactListAdapter2(results);
        realmRecyclerView.setAdapter(contactListAdapter2);
        if (results.size() == 0) {
            // No Contacts Exist Go to Main
            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();
        }
    }
    hideProgress();
}
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) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)2 AsyncTask (android.os.AsyncTask)2 Bundle (android.os.Bundle)2 Gravity (android.view.Gravity)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Button (android.widget.Button)2 LinearLayout (android.widget.LinearLayout)2 ProgressBar (android.widget.ProgressBar)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 ConstraintLayout (androidx.constraintlayout.widget.ConstraintLayout)2 DataBindingUtil (androidx.databinding.DataBindingUtil)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 Case (io.realm.Case)2 RealmChangeListener (io.realm.RealmChangeListener)2 RealmResults (io.realm.RealmResults)2