use of net.iGap.module.structs.StructBottomSheetForward in project iGap-Android by KianIranian-STDG.
the class FragmentChat method initAttachForward.
/**
* initialize bottomSheet for use in attachment for forward
*/
private void initAttachForward(boolean isMessage) {
canClearForwardList = true;
multiForwardList = new ArrayList<>();
viewBottomSheetForward = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet_forward, null);
fastItemAdapterForward = new FastItemAdapter();
EditText edtSearch = viewBottomSheetForward.findViewById(R.id.edtSearch);
edtSearch.setImeOptions(EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
edtSearch.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH)
hideKeyboard();
return true;
});
edtSearch.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
final AppCompatTextView textSend = viewBottomSheetForward.findViewById(R.id.txtSend);
textSend.setVisibility(View.GONE);
final RecyclerView rcvItem = viewBottomSheetForward.findViewById(R.id.rcvBottomSheetForward);
rcvItem.setLayoutManager(new GridLayoutManager(rcvItem.getContext(), 4, GridLayoutManager.VERTICAL, false));
rcvItem.setItemViewCacheSize(100);
rcvItem.setAdapter(fastItemAdapterForward);
edtSearch.setBackground(new Theme().tintDrawable(edtSearch.getBackground(), getContext(), R.attr.iGapDividerLine));
bottomSheetDialogForward = new BottomSheetDialog(getActivity(), R.style.BaseBottomSheetDialog);
bottomSheetDialogForward.setContentView(viewBottomSheetForward);
final BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) viewBottomSheetForward.getParent());
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
fastItemAdapterForward.getItemFilter().withFilterPredicate((IItemAdapter.Predicate<ItemBottomSheetForward>) (item, constraint) -> item.structBottomSheetForward.getDisplayName().toLowerCase().contains(String.valueOf(constraint)));
edtSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
fastItemAdapterForward.filter(s.toString().toLowerCase());
}
@Override
public void afterTextChanged(Editable s) {
}
});
viewBottomSheetForward.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mBehavior.setPeekHeight(viewBottomSheetForward.getHeight());
viewBottomSheetForward.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
// height is ready
textSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
canClearForwardList = false;
forwardToChatRoom(mListForwardNotExict, isMessage);
prgWaiting.setVisibility(View.VISIBLE);
viewBottomSheetForward.setEnabled(false);
}
});
onForwardBottomSheet = structBottomSheetForward -> {
if (structBottomSheetForward.isNotExistRoom()) {
if (structBottomSheetForward.isChecked()) {
mListForwardNotExict.add(structBottomSheetForward);
} else {
mListForwardNotExict.remove(structBottomSheetForward);
}
} else {
if (structBottomSheetForward.isChecked()) {
multiForwardList.add(structBottomSheetForward.getId());
} else {
multiForwardList.remove(structBottomSheetForward.getId());
}
}
if (mListForwardNotExict.size() + multiForwardList.size() > 0) {
textSend.setVisibility(View.VISIBLE);
} else {
textSend.setVisibility(View.GONE);
}
};
bottomSheetDialogForward.show();
bottomSheetDialogForward.setOnDismissListener(dialog -> {
if (canClearForwardList) {
removeForwardModeFromRoomList();
mForwardMessages = null;
}
});
}
use of net.iGap.module.structs.StructBottomSheetForward in project iGap-Android by KianIranian-STDG.
the class FragmentChat method itemAdapterBottomSheetForward.
private void itemAdapterBottomSheetForward() {
String[] fieldNames = { "isPinned", "pinId", "updatedTime" };
Sort[] sort = { Sort.DESCENDING, Sort.DESCENDING, Sort.DESCENDING };
results = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("keepRoom", false).equalTo("isDeleted", false).equalTo("readOnly", false).findAll().sort(fieldNames, sort);
});
resultsContact = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).findAll().sort("display_name");
});
List<Long> te = new ArrayList<>();
te.add(chatPeerId);
long identifier = 100L;
for (RealmRoom r : results) {
StructBottomSheetForward item = new StructBottomSheetForward();
item.setId(r.getId());
if (r.getType() == ProtoGlobal.Room.Type.CHAT) {
te.add(r.getChatRoom().getPeerId());
}
item.setDisplayName(r.getTitle());
if (r.getChatRoom() != null)
item.setPeer_id(r.getChatRoom().getPeerId());
item.setType(r.getType());
item.setContactList(false);
item.setNotExistRoom(false);
identifier = identifier + 1;
if (r.getChatRoom() != null && r.getChatRoom().getPeerId() > 0 && r.getChatRoom().getPeerId() == userId) {
fastItemAdapterForward.add(0, new ItemBottomSheetForward(item, avatarHandler).withIdentifier(identifier));
} else {
fastItemAdapterForward.add(new ItemBottomSheetForward(item, avatarHandler).withIdentifier(identifier));
}
}
for (RealmContacts r : resultsContact) {
if (!te.contains(r.getId())) {
StructBottomSheetForward item = new StructBottomSheetForward();
item.setId(r.getId());
item.setDisplayName(r.getDisplay_name());
item.setContactList(true);
item.setNotExistRoom(true);
identifier = identifier + 1;
fastItemAdapterForward.add(new ItemBottomSheetForward(item, avatarHandler).withIdentifier(identifier));
}
}
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
if (isAdded()) {
bottomSheetDialogForward.show();
}
}
}, 100);
}
Aggregations