use of net.iGap.module.scrollbar.FastScroller 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.scrollbar.FastScroller 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);
}
use of net.iGap.module.scrollbar.FastScroller 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);
}
Aggregations