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();
}
}
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();
}
Aggregations