use of net.iGap.module.EndlessRecyclerViewScrollListener in project iGap-Android by KianIranian-STDG.
the class MplTransactionFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setUpViews();
viewModel.getMplTransactionLiveData().observe(getViewLifecycleOwner(), mplTransaction -> {
if (mplTransaction != null) {
if (mplTransaction.size() > 0) {
adapter.setTransAction(mplTransaction);
start = adapter.getItemCount();
end = start + MplTransactionViewModel.PAGINATION_LIMIT;
page++;
}
}
});
viewModel.getProgressMutableLiveData().observe(getViewLifecycleOwner(), progress -> {
if (progress != null)
swipeRefreshLayout.setRefreshing(progress);
});
recyclerView.addOnScrollListener(new EndlessRecyclerViewScrollListener(layoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
viewModel.getMorePageOffset(start, end);
}
});
swipeRefreshLayout.setOnRefreshListener(() -> {
viewModel.getFirstPageMplTransactionList(viewModel.getType());
});
adapter.setCallBack(token -> {
if (token != null)
new HelperFragment(getFragmentManager(), MplTransactionInfoFragment.getInstance(token)).setReplace(false).load();
});
typeAllTv.setOnClickListener(v -> {
setEnableButton(typeAllTv, typeBillTv, typeCardToCardTv, typeSalesTv, typeTopUpTv);
viewModel.getFirstPageMplTransactionList(ProtoGlobal.MplTransaction.Type.NONE);
});
typeBillTv.setOnClickListener(v -> {
setEnableButton(typeBillTv, typeAllTv, typeCardToCardTv, typeSalesTv, typeTopUpTv);
viewModel.getFirstPageMplTransactionList(ProtoGlobal.MplTransaction.Type.BILL);
});
typeCardToCardTv.setOnClickListener(v -> {
setEnableButton(typeCardToCardTv, typeAllTv, typeBillTv, typeSalesTv, typeTopUpTv);
viewModel.getFirstPageMplTransactionList(ProtoGlobal.MplTransaction.Type.CARD_TO_CARD);
});
typeSalesTv.setOnClickListener(v -> {
setEnableButton(typeSalesTv, typeAllTv, typeBillTv, typeCardToCardTv, typeTopUpTv);
viewModel.getFirstPageMplTransactionList(ProtoGlobal.MplTransaction.Type.SALES);
});
typeTopUpTv.setOnClickListener(v -> {
setEnableButton(typeTopUpTv, typeAllTv, typeBillTv, typeCardToCardTv, typeSalesTv);
viewModel.getFirstPageMplTransactionList(ProtoGlobal.MplTransaction.Type.TOPUP);
});
}
use of net.iGap.module.EndlessRecyclerViewScrollListener in project iGap-Android by KianIranian-STDG.
the class ViewUserDialogFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.STORY_USER_INFO, this);
EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.STORY_VIEWS_FETCHED, this);
userId = new ArrayList<>();
storyIdList = new ArrayList<>();
createdAtList = new ArrayList<>();
displayNameList = new ArrayList<>();
Collections.sort(userIdList);
for (int i = 0; i < userIdList.size(); i++) {
userId.add(userIdList.get(i).userId);
storyIdList.add(userIdList.get(i).id);
createdAtList.add(userIdList.get(i).createdTime);
displayNameList.add(userIdList.get(i).displayName);
}
mOffset = userId.size();
this.storyId = userIdList.get(0).id;
G.onUserInfoResponse = new OnUserInfoResponse() {
@Override
public void onUserInfo(ProtoGlobal.RegisteredUser user, String identity) {
}
@Override
public void onUserInfoTimeOut() {
}
@Override
public void onUserInfoError(int majorCode, int minorCode) {
}
};
recyclerView.setAdapter(listAdapter);
listAdapter.addRow();
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
EndlessRecyclerViewScrollListener scrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {
@Override
public void onLoadMore(int iPage, int totalItemsCount, RecyclerView view) {
Log.e("fkldsjfklsjjf", "onLoadMore: ");
if (!storyViewListFetched && mOffset > 0 && userIdList.size() < count) {
progressBar.setVisibility(View.VISIBLE);
AbstractObject req = null;
IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
story_get_own_story_views.offset = mOffset;
story_get_own_story_views.limit = 50;
req = story_get_own_story_views;
MessageDataStorage.getInstance(AccountManager.selectedAccount).getRequestManager().sendRequest(req, (response, error) -> {
if (error == null) {
IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
mOffset += 50;
if (res.groupedViews.size() > 0) {
MessageDataStorage.getInstance(AccountManager.selectedAccount).updateOwnViews(res.groupedViews);
} else if (userIdList.size() >= count) {
storyViewListFetched = true;
} else {
progressBar.setVisibility(View.GONE);
}
} else {
progressBar.setVisibility(View.GONE);
}
});
}
}
};
recyclerView.addOnScrollListener(scrollListener);
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// private boolean scrollUpdated;
// private boolean scrollingManually;
// private int prevTop;
// private int prevPosition;
//
// @Override
// public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// super.onScrollStateChanged(recyclerView, newState);
// scrollingManually = newState == RecyclerView.SCROLL_STATE_DRAGGING;
// }
//
// @Override
// public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
//
// LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
// firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
// View view = layoutManager.getChildAt(0);
// if (firstVisibleItemPosition > 0 && view != null) {
// firstVisibleItemPositionOffset = view.getTop();
// }
//
// if (!storyListFetched) {
// if (mOffset > 0) {
// int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
// if (lastVisiblePosition + 10 >= mOffset) {
// AbstractObject req = null;
// IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
// story_get_own_story_views.offset = mOffset;
// story_get_own_story_views.limit = 50;
// req = story_get_own_story_views;
// MessageDataStorage.getInstance(AccountManager.selectedAccount).getRequestManager().sendRequest(req, (response, error) -> {
// if (error == null) {
// IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
// mOffset += res.groupedViews.size();
// MessageDataStorage.getInstance(AccountManager.selectedAccount).updateOwnViews(res.groupedViews);
//
// } else {
// }
// });
// }
// }
// }
//
// int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
// if (firstVisibleItem != RecyclerView.NO_POSITION) {
// RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(firstVisibleItem);
// if (holder != null && holder.getAdapterPosition() != 0) {
// int firstViewTop = holder.itemView.getTop();
// boolean goingDown;
// boolean changed = true;
// if (prevPosition == firstVisibleItem) {
// final int topDelta = prevTop - firstViewTop;
// goingDown = firstViewTop < prevTop;
// changed = Math.abs(topDelta) > 1;
// } else {
// goingDown = firstVisibleItem > prevPosition;
// }
// prevPosition = firstVisibleItem;
// prevTop = firstViewTop;
// scrollUpdated = true;
// }
// }
// }
// });
}
use of net.iGap.module.EndlessRecyclerViewScrollListener in project iGap-Android by KianIranian-STDG.
the class LocalContactFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toolbarLayout = rootView.findViewById(R.id.ll_localContact_toolbar);
loadingPb = rootView.findViewById(R.id.pb_localContact);
txtNoItem = rootView.findViewById(R.id.txt_no_item);
toolbarInit();
// calculate these for recycler pagination
recyclerRowsHeight = getResources().getDimensionPixelSize(R.dimen.dp60);
deviceScreenHeight = getDeviceScreenHeight();
recyclerView = rootView.findViewById(R.id.rv_localContact);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
adapterListContact = new AdapterListContact(phoneContactsList, getContext());
recyclerView.setAdapter(adapterListContact);
recyclerView.addOnScrollListener(new EndlessRecyclerViewScrollListener(linearLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
if (!inSearchMode || mHelperToolbar.getEditTextSearch().getText().toString().trim().equals("")) {
if (Contacts.isEndLocal) {
return;
}
loadingPb.setVisibility(View.VISIBLE);
new Contacts.FetchContactForClient().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
mHelperToolbar.getEditTextSearch().setImeOptions(EditorInfo.IME_ACTION_SEARCH);
mHelperToolbar.getEditTextSearch().setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
cancelSearchTimer();
String text = mHelperToolbar.getEditTextSearch().getText().toString().trim();
if (text.equals(""))
return true;
new SearchAsync(text).execute();
return true;
}
return false;
}
});
}
use of net.iGap.module.EndlessRecyclerViewScrollListener in project iGap-Android by KianIranian-STDG.
the class FragmentShowMember method initComponent.
private void initComponent(View view) {
mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setLogoShown(true).setSearchBoxShown(true).setListener(this);
LinearLayout layoutToolbar = view.findViewById(R.id.fcm_layout_toolbar);
layoutToolbar.addView(mHelperToolbar.getView());
mBtnAdd = view.findViewById(R.id.fcm_lbl_add);
realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("id", mRoomID).findFirst();
});
if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
if (isGroup) {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.member));
mBtnAdd.setText(context.getResources().getString(R.string.add_new_member));
} else {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.subscriber));
mBtnAdd.setText(context.getResources().getString(R.string.add_new_subscriber));
}
if (!isShowAddButton) {
mBtnAdd.setVisibility(View.GONE);
view.findViewById(R.id.fcm_splitter_add).setVisibility(View.GONE);
}
mBtnAdd.setVisibility(realmRoomAccess != null && realmRoomAccess.isCanAddNewMember() ? View.VISIBLE : View.GONE);
} else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.list_admin));
mBtnAdd.setText(context.getResources().getString(R.string.add_admin));
mBtnAdd.setVisibility(realmRoomAccess != null && realmRoomAccess.isCanAddNewAdmin() ? View.VISIBLE : View.GONE);
if (realmRoom != null) {
if (realmRoom.getGroupRoom() != null && realmRoom.getGroupRoom().getRole() == GroupChatRole.OWNER) {
mBtnAdd.setVisibility(View.VISIBLE);
}
if (realmRoom.getChannelRoom() != null && realmRoom.getChannelRoom().getRole() == ChannelChatRole.OWNER) {
mBtnAdd.setVisibility(View.VISIBLE);
}
}
} else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString())) {
mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.list_modereator));
mBtnAdd.setText(context.getResources().getString(R.string.add_modereator));
mBtnAdd.setVisibility(View.GONE);
if (realmRoom != null) {
if (realmRoom.getGroupRoom() != null && (realmRoom.getGroupRoom().getRole() == GroupChatRole.OWNER || realmRoom.getGroupRoom().getRole() == GroupChatRole.ADMIN)) {
mBtnAdd.setVisibility(View.VISIBLE);
}
if (realmRoom.getChannelRoom() != null && (realmRoom.getChannelRoom().getRole() == ChannelChatRole.OWNER || realmRoom.getChannelRoom().getRole() == ChannelChatRole.ADMIN)) {
mBtnAdd.setVisibility(View.VISIBLE);
}
}
}
mBtnAdd.setOnClickListener(v -> {
if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString()) || selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
openFragmentForAdd(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString(), selectedRole);
} else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
goToAddMember();
}
});
final EditText edtSearch = mHelperToolbar.getEditTextSearch();
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) {
}
@Override
public void afterTextChanged(final Editable s) {
RealmResults<RealmMember> searchMember = DbManager.getInstance().doRealmTask(realm -> {
return RealmMember.filterMember(realm, mRoomID, s.toString(), getUnselectRow(), selectedRole);
});
mAdapter = new MemberAdapter(searchMember, roomType, mMainRole, userID);
mRecyclerView.setAdapter(mAdapter);
}
});
mRecyclerView = view.findViewById(R.id.fcm_recycler_view_show_member);
mRecyclerView.setItemViewCacheSize(100);
mRecyclerView.setItemAnimator(null);
mRecyclerView.setLayoutManager(new LinearLayoutManager(G.fragmentActivity));
final PreCachingLayoutManager preCachingLayoutManager = new PreCachingLayoutManager(G.fragmentActivity, DeviceUtils.getScreenHeight(G.fragmentActivity));
mRecyclerView.setLayoutManager(preCachingLayoutManager);
progressBar = view.findViewById(R.id.fcg_prgWaiting);
AppUtils.setProgresColler(progressBar);
// TextView txtNumberOfMember = (TextView) view.findViewById(R.id.fcg_txt_member);
// if (selectedRole.toString().equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString())) {
// txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(R.string.list_modereator));
// } else if (selectedRole.toString().equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
// txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(R.string.list_admin));
// } else {
// txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(member));
// }
scrollListener = new EndlessRecyclerViewScrollListener(preCachingLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
// Triggered only when new data needs to be appended to the list
// Add whatever code is needed to append new items to the bottom of the list
loadMoreMember();
}
};
mRecyclerView.addOnScrollListener(scrollListener);
}
use of net.iGap.module.EndlessRecyclerViewScrollListener in project iGap-Android by KianIranian-STDG.
the class AddStickersFragment method setupViews.
@Override
public void setupViews() {
progressBar = rootView.findViewById(R.id.progress_stricker);
addStickerToolbar = rootView.findViewById(R.id.toolbar2);
customTextViewMedium = rootView.findViewById(R.id.title);
buttonBack = rootView.findViewById(R.id.chl_ripple_back_Button);
if (title == null)
addStickerToolbar.setVisibility(View.GONE);
else
customTextViewMedium.setText(title);
RecyclerView recyclerView = rootView.findViewById(R.id.rcvSettingPage);
recyclerView.setAdapter(adapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
EndlessRecyclerViewScrollListener scrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {
@Override
public void onLoadMore(int iPage, int totalItemsCount, RecyclerView view) {
viewModel.onPageEnded();
}
};
buttonBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popBackStackFragment();
}
});
recyclerView.addOnScrollListener(scrollListener);
adapter.setListener(new AddStickerFragmentAdapter.AddStickerAdapterListener() {
@Override
public void onButtonClick(StructIGStickerGroup stickerGroup, AddStickerFragmentAdapter.ProgressStatus progressStatus) {
viewModel.onItemButtonClicked(stickerGroup, sticker -> {
if (sticker.getGroupId().equals(stickerGroup.getGroupId())) {
progressStatus.setVisibility(sticker.isInUserList());
}
});
}
@Override
public void onCellClick(StructIGStickerGroup stickerGroup) {
viewModel.onItemCellClicked(stickerGroup);
}
@Override
public void onButtonStatusChange(AddStickerFragmentAdapter.ButtonsStatus buttonsStatus) {
viewModel.getButtonStatusChangedLiveData().observe(getViewLifecycleOwner(), buttonsStatus::changed);
}
});
viewModel.getOpenStickerDetailLiveData().observe(getViewLifecycleOwner(), sticker -> openFragmentAddStickerToFavorite(sticker.getGroupId()));
viewModel.getLoadMoreProgressLiveData().observe(getViewLifecycleOwner(), visibility -> progressBar.setVisibility(visibility));
viewModel.getStickerGroupLiveData().observe(getViewLifecycleOwner(), stickerGroup -> adapter.addData(stickerGroup));
}
Aggregations