use of android.support.v7.widget.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class LayoutManager method getAnchorAtEnd.
/**
* Find an anchor to fill to end from.
*
* @return Non-header view closest to the end edge.
*/
private View getAnchorAtEnd() {
if (getChildCount() == 1) {
return getChildAt(0);
}
View candidate = getChildAt(getChildCount() - 1);
LayoutParams candidateParams = (LayoutParams) candidate.getLayoutParams();
if (candidateParams.isHeader) {
// Try one above.
View check = getChildAt(getChildCount() - 2);
LayoutParams checkParams = (LayoutParams) check.getLayoutParams();
if (checkParams.getTestedFirstPosition() == candidateParams.getTestedFirstPosition()) {
candidate = check;
}
}
return candidate;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class LayoutManager method findAttachedHeaderOrFirstViewForSection.
/**
* Find header or, if it cannot be found, the first view for a section.
*
* @param sfp Section to look for header inside of. Search is expected to start inside
* the section so it must be at the matching end specified by the direction.
* @param startIndex Index to start looking from.
* @param from Edge to start looking from.
* @return Null if no header or first item found, otherwise the found view.
*/
private View findAttachedHeaderOrFirstViewForSection(final int sfp, int startIndex, final Direction from) {
int childIndex = startIndex;
int step = from == Direction.START ? 1 : -1;
for (; 0 <= childIndex && childIndex < getChildCount(); childIndex += step) {
View child = getChildAt(childIndex);
if (getPosition(child) == sfp) {
return child;
}
LayoutParams params = (LayoutParams) child.getLayoutParams();
if (params.getTestedFirstPosition() != sfp) {
break;
}
}
return null;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class LayoutManager method findAttachedHeaderForSectionFromStart.
/**
* The header is most likely at the end of the section but we don't know where that is so use
* binary search.
*
* @param min min
* @param max max
* @param sfp Section identifier.
* @return Header, or null if not found.
*/
private View findAttachedHeaderForSectionFromStart(int min, int max, int sfp) {
if (max < min) {
return null;
}
int mid = min + (max - min) / 2;
View candidate = getChildAt(mid);
LayoutParams params = (LayoutParams) candidate.getLayoutParams();
if (params.getTestedFirstPosition() != sfp) {
return findAttachedHeaderForSectionFromStart(min, mid - 1, sfp);
}
if (params.isHeader) {
return candidate;
}
return findAttachedHeaderForSectionFromStart(mid + 1, max, sfp);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project CoCoin by Nightonke.
the class MonthViewFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
if (!IS_EMPTY) {
RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
int startYear = recordManager.RECORDS.get(0).getCalendar().get(Calendar.YEAR);
int startMonth = recordManager.RECORDS.get(0).getCalendar().get(Calendar.MONTH);
int nowYear = startYear + (startMonth + (monthNumber - position - 1)) / 12;
int nowMonth = (startMonth + (monthNumber - position - 1)) % 12;
Calendar monthStart = Calendar.getInstance();
Calendar monthEnd = Calendar.getInstance();
monthStart.set(nowYear, nowMonth, 1, 0, 0, 0);
monthStart.add(Calendar.MILLISECOND, 0);
monthEnd.set(nowYear, nowMonth, monthStart.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);
monthEnd.add(Calendar.MILLISECOND, 0);
Calendar leftRange = CoCoinUtil.GetThisWeekLeftRange(monthStart);
Calendar rightRange = CoCoinUtil.GetThisWeekRightRange(monthEnd);
int start = -1;
int end = 0;
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
} else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
if (start == -1) {
start = i;
}
}
}
mAdapter = new RecyclerViewMaterialAdapter(new MonthViewRecyclerViewAdapter(start, end, mContext, position, monthNumber));
mRecyclerView.setAdapter(mAdapter);
} else {
mAdapter = new RecyclerViewMaterialAdapter(new MonthViewRecyclerViewAdapter(-1, -1, mContext, 0, -1));
mRecyclerView.setAdapter(mAdapter);
}
MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project WordPress-Android by wordpress-mobile.
the class CommentsListFragment method getAdapter.
private CommentAdapter getAdapter() {
if (mAdapter == null) {
// called after comments have been loaded
CommentAdapter.OnDataLoadedListener dataLoadedListener = new CommentAdapter.OnDataLoadedListener() {
@Override
public void onDataLoaded(boolean isEmpty) {
if (!isAdded())
return;
if (!isEmpty) {
// Hide the empty view if there are already some displayed comments
mFilteredCommentsView.hideEmptyView();
} else if (!mIsUpdatingComments) {
// Change LOADING to NO_CONTENT message
mFilteredCommentsView.updateEmptyView(EmptyViewMessageType.NO_CONTENT);
}
}
};
// adapter calls this to request more comments from server when it reaches the end
CommentAdapter.OnLoadMoreListener loadMoreListener = new CommentAdapter.OnLoadMoreListener() {
@Override
public void onLoadMore() {
if (mCanLoadMoreComments && !mIsUpdatingComments) {
updateComments(true);
}
}
};
// adapter calls this when selected comments have changed (CAB)
CommentAdapter.OnSelectedItemsChangeListener changeListener = new CommentAdapter.OnSelectedItemsChangeListener() {
@Override
public void onSelectedItemsChanged() {
if (mActionMode != null) {
if (getSelectedCommentCount() == 0) {
mActionMode.finish();
} else {
updateActionModeTitle();
// must invalidate to ensure onPrepareActionMode is called
mActionMode.invalidate();
}
}
}
};
CommentAdapter.OnCommentPressedListener pressedListener = new CommentAdapter.OnCommentPressedListener() {
@Override
public void onCommentPressed(int position, View view) {
CommentModel comment = getAdapter().getItem(position);
if (comment == null) {
return;
}
if (mActionMode == null) {
mFilteredCommentsView.invalidate();
if (getActivity() instanceof OnCommentSelectedListener) {
((OnCommentSelectedListener) getActivity()).onCommentSelected(comment.getRemoteCommentId());
}
} else {
getAdapter().toggleItemSelected(position, view);
}
}
@Override
public void onCommentLongPressed(int position, View view) {
// enable CAB if it's not already enabled
if (mActionMode == null) {
if (getActivity() instanceof AppCompatActivity) {
((AppCompatActivity) getActivity()).startSupportActionMode(new ActionModeCallback());
getAdapter().setEnableSelection(true);
getAdapter().setItemSelected(position, true, view);
}
} else {
getAdapter().toggleItemSelected(position, view);
}
}
};
mAdapter = new CommentAdapter(getActivity(), mSite);
mAdapter.setOnCommentPressedListener(pressedListener);
mAdapter.setOnDataLoadedListener(dataLoadedListener);
mAdapter.setOnLoadMoreListener(loadMoreListener);
mAdapter.setOnSelectedItemsChangeListener(changeListener);
}
return mAdapter;
}
Aggregations