Notify next items changed after items inserted (#520)
* Notify next items changed after items inserted, Resolve #201 * Code cleanup
This commit is contained in:
1 parent
683c8dc5c5
commit
1a963a3239
4 files changed
+50
-196
No files matched your search
@@ -1188,9 +1188,9 @@ public class FavoritesScene extends SearchBarScene implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
protected void notifyItemRangeChanged(int positionStart, int itemCount) {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyItemRangeRemoved(positionStart, itemCount);
|
||||
mAdapter.notifyItemRangeChanged(positionStart, itemCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.text.Spannable;
|
||||
@@ -140,8 +139,6 @@ public final class GalleryListScene extends SearchBarScene
|
||||
private final static int STATE_SEARCH = 2;
|
||||
private final static int STATE_SEARCH_SHOW_LIST = 3;
|
||||
private static final long ANIMATE_TIME = 300L;
|
||||
// Double click back exit
|
||||
private final long mPressBackTime = 0;
|
||||
/*---------------
|
||||
Whole life cycle
|
||||
---------------*/
|
||||
@@ -149,11 +146,6 @@ public final class GalleryListScene extends SearchBarScene
|
||||
private EhClient mClient;
|
||||
@Nullable
|
||||
private ListUrlBuilder mUrlBuilder;
|
||||
/*---------------
|
||||
View life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
private ContentLayout mContentLayout;
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
@@ -247,17 +239,13 @@ public final class GalleryListScene extends SearchBarScene
|
||||
} else if (ListUrlBuilder.MODE_WHATS_HOT == urlBuilder.getMode()) {
|
||||
return resources.getString(R.string.whats_hot);
|
||||
} else if (ListUrlBuilder.MODE_TOPLIST == urlBuilder.getMode()) {
|
||||
switch (urlBuilder.getKeyword()) {
|
||||
case "11":
|
||||
return resources.getString(R.string.toplist_alltime);
|
||||
case "12":
|
||||
return resources.getString(R.string.toplist_pastyear);
|
||||
case "13":
|
||||
return resources.getString(R.string.toplist_pastmonth);
|
||||
case "15":
|
||||
return resources.getString(R.string.toplist_yesterday);
|
||||
}
|
||||
return null;
|
||||
return switch (urlBuilder.getKeyword()) {
|
||||
case "11" -> resources.getString(R.string.toplist_alltime);
|
||||
case "12" -> resources.getString(R.string.toplist_pastyear);
|
||||
case "13" -> resources.getString(R.string.toplist_pastmonth);
|
||||
case "15" -> resources.getString(R.string.toplist_yesterday);
|
||||
default -> null;
|
||||
};
|
||||
} else if (!TextUtils.isEmpty(keyword)) {
|
||||
return keyword;
|
||||
} else if (MathUtils.hammingWeight(category) == 1) {
|
||||
@@ -325,6 +313,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
showSearchBar();
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -547,7 +536,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
mShowActionFab = true;
|
||||
|
||||
View mainLayout = ViewUtils.$$(view, R.id.main_layout);
|
||||
mContentLayout = (ContentLayout) ViewUtils.$$(mainLayout, R.id.content_layout);
|
||||
ContentLayout mContentLayout = (ContentLayout) ViewUtils.$$(mainLayout, R.id.content_layout);
|
||||
mRecyclerView = mContentLayout.getRecyclerView();
|
||||
FastScroller fastScroller = mContentLayout.getFastScroller();
|
||||
mSearchLayout = (SearchLayout) ViewUtils.$$(mainLayout, R.id.search_layout);
|
||||
@@ -651,8 +640,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
mActionFabDrawable = null;
|
||||
}
|
||||
|
||||
private void showQuickSearchTipDialog(final QsDrawerAdapter adapter,
|
||||
final EasyRecyclerView recyclerView, final TextView tip) {
|
||||
private void showQuickSearchTipDialog() {
|
||||
Context context = getContext();
|
||||
if (null == context) {
|
||||
return;
|
||||
@@ -756,7 +744,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
if (id == R.id.action_add) {
|
||||
showAddQuickSearchDialog(qsDrawerAdapter, recyclerView, tip);
|
||||
} else if (id == R.id.action_help) {
|
||||
showQuickSearchTipDialog(qsDrawerAdapter, recyclerView, tip);
|
||||
showQuickSearchTipDialog();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@@ -778,15 +766,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
}
|
||||
if (isSearchViewShown())
|
||||
return false;
|
||||
switch (mState) {
|
||||
case STATE_NORMAL:
|
||||
return getStackIndex() == 0;
|
||||
case STATE_SIMPLE_SEARCH:
|
||||
case STATE_SEARCH:
|
||||
case STATE_SEARCH_SHOW_LIST:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return mState == STATE_NORMAL && getStackIndex() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -817,7 +797,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onItemClick(View view, int position) {
|
||||
public boolean onItemClick(int position) {
|
||||
if (null == mHelper || null == mRecyclerView) {
|
||||
return false;
|
||||
}
|
||||
@@ -884,7 +864,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
long fromDate = local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
|
||||
long toDate = MaterialDatePicker.todayInUtcMilliseconds();
|
||||
|
||||
ArrayList listValidators = new ArrayList<>();
|
||||
ArrayList<CalendarConstraints.DateValidator> listValidators = new ArrayList<>();
|
||||
listValidators.add(DateValidatorPointForward.from(fromDate));
|
||||
listValidators.add(DateValidatorPointBackward.before(toDate));
|
||||
|
||||
@@ -899,9 +879,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
.setSelection(toDate)
|
||||
.build();
|
||||
datePicker.show(requireActivity().getSupportFragmentManager(), "date-picker");
|
||||
datePicker.addOnPositiveButtonClickListener(v -> {
|
||||
mHelper.goTo(v);
|
||||
});
|
||||
datePicker.addOnPositiveButtonClickListener(v -> mHelper.goTo(v));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1186,21 +1164,12 @@ public final class GalleryListScene extends SearchBarScene
|
||||
}
|
||||
break;
|
||||
case STATE_SEARCH:
|
||||
if (state == STATE_NORMAL) {
|
||||
mViewTransition.showView(0, animation);
|
||||
selectActionFab(animation);
|
||||
} else if (state == STATE_SIMPLE_SEARCH) {
|
||||
mViewTransition.showView(0, animation);
|
||||
} else if (state == STATE_SEARCH_SHOW_LIST) {
|
||||
}
|
||||
break;
|
||||
case STATE_SEARCH_SHOW_LIST:
|
||||
if (state == STATE_NORMAL) {
|
||||
mViewTransition.showView(0, animation);
|
||||
selectActionFab(animation);
|
||||
} else if (state == STATE_SIMPLE_SEARCH) {
|
||||
mViewTransition.showView(0, animation);
|
||||
} else if (state == STATE_SEARCH) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1208,12 +1177,6 @@ public final class GalleryListScene extends SearchBarScene
|
||||
((StageActivity) requireActivity()).updateBackPressCallBackStatus();
|
||||
}
|
||||
|
||||
public void onClickTitle() {
|
||||
if (mState == STATE_NORMAL) {
|
||||
setState(STATE_SIMPLE_SEARCH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||
if (mState == STATE_NORMAL) {
|
||||
@@ -1251,15 +1214,6 @@ public final class GalleryListScene extends SearchBarScene
|
||||
setState(STATE_NORMAL);
|
||||
}
|
||||
|
||||
public void onReceiveContent(Uri uri) {
|
||||
if (mSearchLayout == null || uri == null) {
|
||||
return;
|
||||
}
|
||||
mSearchLayout.setSearchMode(SearchLayout.SEARCH_MODE_IMAGE);
|
||||
mSearchLayout.setImageUri(uri);
|
||||
setState(STATE_SEARCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartDragHandler() {
|
||||
// Lock right drawer
|
||||
@@ -1308,7 +1262,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
: R.string.gallery_list_empty_hit);
|
||||
mHelper.setEmptyString(emptyString);
|
||||
|
||||
int pages = 0;
|
||||
int pages;
|
||||
if (mIsTopList)
|
||||
pages = 200;
|
||||
else if (result.nextGid == 0)
|
||||
@@ -1619,7 +1573,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
|
||||
@Override
|
||||
void onItemClick(View view, int position) {
|
||||
GalleryListScene.this.onItemClick(view, position);
|
||||
GalleryListScene.this.onItemClick(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1692,6 +1646,7 @@ public final class GalleryListScene extends SearchBarScene
|
||||
return GalleryListScene.this.getContext();
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Override
|
||||
protected void notifyDataSetChanged() {
|
||||
if (null != mAdapter) {
|
||||
@@ -1700,9 +1655,9 @@ public final class GalleryListScene extends SearchBarScene
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
protected void notifyItemRangeChanged(int positionStart, int itemCount) {
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyItemRangeRemoved(positionStart, itemCount);
|
||||
mAdapter.notifyItemRangeChanged(positionStart, itemCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -76,11 +75,6 @@ public class GalleryPreviewsScene extends ToolbarScene {
|
||||
@Nullable
|
||||
private GalleryInfo mGalleryInfo;
|
||||
|
||||
/*---------------
|
||||
View life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
private ContentLayout mContentLayout;
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
@@ -132,11 +126,11 @@ public class GalleryPreviewsScene extends ToolbarScene {
|
||||
outState.putParcelable(KEY_GALLERY_INFO, mGalleryInfo);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateViewWithToolbar(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
mContentLayout = (ContentLayout) inflater.inflate(
|
||||
ContentLayout mContentLayout = (ContentLayout) inflater.inflate(
|
||||
R.layout.scene_gallery_previews, container, false);
|
||||
mContentLayout.hideFastScroll();
|
||||
mRecyclerView = mContentLayout.getRecyclerView();
|
||||
@@ -144,7 +138,6 @@ public class GalleryPreviewsScene extends ToolbarScene {
|
||||
|
||||
Context context = getContext();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mAdapter = new GalleryPreviewAdapter();
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
@@ -191,12 +184,14 @@ public class GalleryPreviewsScene extends ToolbarScene {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
setTitle(R.string.gallery_previews);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
if (((GalleryDetail) mGalleryInfo).previewPages > 2)
|
||||
showMenu(R.menu.scene_gallery_previews);
|
||||
if (mGalleryInfo != null) {
|
||||
if (((GalleryDetail) mGalleryInfo).previewPages > 2)
|
||||
showMenu(R.menu.scene_gallery_previews);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||
Context context = getContext();
|
||||
if (null == context) {
|
||||
return false;
|
||||
@@ -368,6 +363,7 @@ public class GalleryPreviewsScene extends ToolbarScene {
|
||||
return GalleryPreviewsScene.this.getContext();
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Override
|
||||
protected void notifyDataSetChanged() {
|
||||
if (mAdapter != null) {
|
||||
@@ -376,9 +372,9 @@ public class GalleryPreviewsScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
protected void notifyItemRangeChanged(int positionStart, int itemCount) {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyItemRangeRemoved(positionStart, itemCount);
|
||||
mAdapter.notifyItemRangeChanged(positionStart, itemCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,21 +123,11 @@ public class ContentLayout extends FrameLayout {
|
||||
return mFastScroller;
|
||||
}
|
||||
|
||||
public SwipeRefreshLayout getRefreshLayout() {
|
||||
return mRefreshLayout;
|
||||
}
|
||||
|
||||
public void setHelper(ContentHelper<?> helper) {
|
||||
mContentHelper = helper;
|
||||
helper.init(this);
|
||||
}
|
||||
|
||||
public void showFastScroll() {
|
||||
if (!mFastScroller.isAttached()) {
|
||||
mFastScroller.attachToRecyclerView(mRecyclerView);
|
||||
}
|
||||
}
|
||||
|
||||
public void hideFastScroll() {
|
||||
mFastScroller.detachedFromRecyclerView();
|
||||
}
|
||||
@@ -191,9 +181,6 @@ public class ContentLayout extends FrameLayout {
|
||||
public static final int TYPE_NEXT_PAGE_KEEP_POS = 4;
|
||||
public static final int TYPE_SOMEWHERE = 5;
|
||||
public static final int TYPE_REFRESH_PAGE = 6;
|
||||
public static final int REFRESH_TYPE_HEADER = 0;
|
||||
public static final int REFRESH_TYPE_FOOTER = 1;
|
||||
public static final int REFRESH_TYPE_PROGRESS_VIEW = 2;
|
||||
private static final String TAG = ContentHelper.class.getSimpleName();
|
||||
private static final int CHECK_DUPLICATE_RANGE = 50;
|
||||
private static final String KEY_SUPER = "super";
|
||||
@@ -210,9 +197,7 @@ public class ContentLayout extends FrameLayout {
|
||||
*/
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final LayoutManagerUtils.OnScrollToPositionListener mOnScrollToPositionListener = ContentHelper.this::onScrollToPosition;
|
||||
private CircularProgressIndicator mProgressView;
|
||||
private TextView mTipView;
|
||||
private ViewGroup mContentView;
|
||||
private SwipeRefreshLayout mRefreshLayout;
|
||||
private LinearProgressIndicator mBottomProgress;
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@@ -297,9 +282,9 @@ public class ContentLayout extends FrameLayout {
|
||||
private void init(ContentLayout contentLayout) {
|
||||
mNextPageScrollSize = LayoutUtils.dp2pix(contentLayout.getContext(), 48);
|
||||
|
||||
mProgressView = contentLayout.mProgressView;
|
||||
CircularProgressIndicator mProgressView = contentLayout.mProgressView;
|
||||
mTipView = contentLayout.mTipView;
|
||||
mContentView = contentLayout.mContentView;
|
||||
ViewGroup mContentView = contentLayout.mContentView;
|
||||
|
||||
mRefreshLayout = contentLayout.mRefreshLayout;
|
||||
mBottomProgress = contentLayout.mBottomProgress;
|
||||
@@ -330,11 +315,11 @@ public class ContentLayout extends FrameLayout {
|
||||
|
||||
protected abstract void notifyDataSetChanged();
|
||||
|
||||
protected abstract void notifyItemRangeRemoved(int positionStart, int itemCount);
|
||||
protected abstract void notifyItemRangeChanged(int positionStart, int itemCount);
|
||||
|
||||
protected abstract void notifyItemRangeInserted(int positionStart, int itemCount);
|
||||
|
||||
protected void onScrollToPosition(int postion) {
|
||||
protected void onScrollToPosition(int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -361,13 +346,6 @@ public class ContentLayout extends FrameLayout {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IndexOutOfBoundsException if {@code location < 0 || location >= size()}
|
||||
*/
|
||||
public E getDataAt(int location) {
|
||||
return mData.get(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public E getDataAtEx(int location) {
|
||||
if (location >= 0 && location < mData.size()) {
|
||||
@@ -389,34 +367,6 @@ public class ContentLayout extends FrameLayout {
|
||||
return mPages;
|
||||
}
|
||||
|
||||
public void addAt(int index, E data) {
|
||||
mData.add(index, data);
|
||||
onAddData(data);
|
||||
|
||||
for (int i = 0, n = mPageDivider.size(); i < n; i++) {
|
||||
int divider = mPageDivider.get(i);
|
||||
if (index < divider) {
|
||||
mPageDivider.set(i, divider + 1);
|
||||
}
|
||||
}
|
||||
|
||||
notifyItemRangeInserted(index, 1);
|
||||
}
|
||||
|
||||
public void removeAt(int index) {
|
||||
E data = mData.remove(index);
|
||||
onRemoveData(data);
|
||||
|
||||
for (int i = 0, n = mPageDivider.size(); i < n; i++) {
|
||||
int divider = mPageDivider.get(i);
|
||||
if (index < divider) {
|
||||
mPageDivider.set(i, divider - 1);
|
||||
}
|
||||
}
|
||||
|
||||
notifyItemRangeRemoved(index, 1);
|
||||
}
|
||||
|
||||
protected abstract boolean isDuplicate(E d1, E d2);
|
||||
|
||||
private void removeDuplicateData(List<E> data, int start, int end) {
|
||||
@@ -453,14 +403,13 @@ public class ContentLayout extends FrameLayout {
|
||||
int dataSize;
|
||||
|
||||
switch (mCurrentTaskType) {
|
||||
case TYPE_REFRESH:
|
||||
case TYPE_REFRESH -> {
|
||||
mStartPage = 0;
|
||||
mEndPage = 1;
|
||||
mPages = pages;
|
||||
mNextPage = nextPage;
|
||||
mPageDivider.clear();
|
||||
mPageDivider.add(data.size());
|
||||
|
||||
if (data.isEmpty()) {
|
||||
mData.clear();
|
||||
onClearData();
|
||||
@@ -490,9 +439,8 @@ public class ContentLayout extends FrameLayout {
|
||||
onScrollToPosition(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_PRE_PAGE:
|
||||
case TYPE_PRE_PAGE_KEEP_POS:
|
||||
}
|
||||
case TYPE_PRE_PAGE, TYPE_PRE_PAGE_KEEP_POS -> {
|
||||
removeDuplicateData(data, 0, CHECK_DUPLICATE_RANGE);
|
||||
dataSize = data.size();
|
||||
for (int i = 0, n = mPageDivider.size(); i < n; i++) {
|
||||
@@ -527,6 +475,7 @@ public class ContentLayout extends FrameLayout {
|
||||
mData.addAll(0, data);
|
||||
onAddData(data);
|
||||
notifyItemRangeInserted(0, data.size());
|
||||
notifyItemRangeChanged(data.size(), mData.size() - data.size());
|
||||
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
@@ -546,9 +495,8 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_NEXT_PAGE:
|
||||
case TYPE_NEXT_PAGE_KEEP_POS:
|
||||
}
|
||||
case TYPE_NEXT_PAGE, TYPE_NEXT_PAGE_KEEP_POS -> {
|
||||
removeDuplicateData(data, mData.size() - CHECK_DUPLICATE_RANGE, mData.size());
|
||||
dataSize = data.size();
|
||||
int oldDataSize = mData.size();
|
||||
@@ -556,7 +504,6 @@ public class ContentLayout extends FrameLayout {
|
||||
mEndPage++;
|
||||
mNextPage = nextPage;
|
||||
mPages = Math.max(mEndPage, pages);
|
||||
|
||||
if (data.isEmpty()) {
|
||||
// OK, that's all
|
||||
if (mData.isEmpty()) {
|
||||
@@ -598,15 +545,14 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_SOMEWHERE:
|
||||
}
|
||||
case TYPE_SOMEWHERE -> {
|
||||
mStartPage = mCurrentTaskPage;
|
||||
mEndPage = mCurrentTaskPage + 1;
|
||||
mNextPage = nextPage;
|
||||
mPages = pages;
|
||||
mPageDivider.clear();
|
||||
mPageDivider.add(data.size());
|
||||
|
||||
if (data.isEmpty()) {
|
||||
mData.clear();
|
||||
onClearData();
|
||||
@@ -636,36 +582,30 @@ public class ContentLayout extends FrameLayout {
|
||||
onScrollToPosition(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_REFRESH_PAGE:
|
||||
}
|
||||
case TYPE_REFRESH_PAGE -> {
|
||||
if (mCurrentTaskPage < mStartPage || mCurrentTaskPage >= mEndPage) {
|
||||
Log.e(TAG, "TYPE_REFRESH_PAGE, but mCurrentTaskPage = " + mCurrentTaskPage +
|
||||
", mStartPage = " + mStartPage + ", mEndPage = " + mEndPage);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mCurrentTaskPage == mEndPage - 1) {
|
||||
mNextPage = nextPage;
|
||||
}
|
||||
|
||||
mPages = Math.max(mEndPage, pages);
|
||||
|
||||
int oldIndexStart = mCurrentTaskPage == mStartPage ? 0 : mPageDivider.get(mCurrentTaskPage - mStartPage - 1);
|
||||
int oldIndexEnd = mPageDivider.get(mCurrentTaskPage - mStartPage);
|
||||
List<E> toRemove = mData.subList(oldIndexStart, oldIndexEnd);
|
||||
onRemoveData(toRemove);
|
||||
toRemove.clear();
|
||||
removeDuplicateData(data, oldIndexStart - CHECK_DUPLICATE_RANGE, oldIndexStart + CHECK_DUPLICATE_RANGE);
|
||||
int newIndexStart = oldIndexStart;
|
||||
int newIndexEnd = newIndexStart + data.size();
|
||||
int newIndexEnd = oldIndexStart + data.size();
|
||||
mData.addAll(oldIndexStart, data);
|
||||
onAddData(data);
|
||||
notifyDataSetChanged();
|
||||
|
||||
for (int i = mCurrentTaskPage - mStartPage, n = mPageDivider.size(); i < n; i++) {
|
||||
mPageDivider.set(i, mPageDivider.get(i) - oldIndexEnd + newIndexEnd);
|
||||
}
|
||||
|
||||
if (mData.isEmpty()) {
|
||||
// Ui change, show empty string
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
@@ -684,7 +624,7 @@ public class ContentLayout extends FrameLayout {
|
||||
onScrollToPosition(newIndexEnd - 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -739,35 +679,6 @@ public class ContentLayout extends FrameLayout {
|
||||
showText(mEmptyString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Be carefull
|
||||
*/
|
||||
public void doGetData(int type, int page, int refreshType) {
|
||||
switch (refreshType) {
|
||||
default:
|
||||
case REFRESH_TYPE_HEADER:
|
||||
showContent();
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mBottomProgress.hide();
|
||||
break;
|
||||
case REFRESH_TYPE_FOOTER:
|
||||
showContent();
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mBottomProgress.hide();
|
||||
break;
|
||||
case REFRESH_TYPE_PROGRESS_VIEW:
|
||||
showProgressBar();
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mBottomProgress.hide();
|
||||
break;
|
||||
}
|
||||
|
||||
mCurrentTaskId = mIdGenerator.nextId();
|
||||
mCurrentTaskType = type;
|
||||
mCurrentTaskPage = page;
|
||||
getPageData(mCurrentTaskId, mCurrentTaskType, mCurrentTaskPage);
|
||||
}
|
||||
|
||||
protected void doRefresh() {
|
||||
beforeRefresh();
|
||||
mCurrentTaskId = mIdGenerator.nextId();
|
||||
@@ -777,7 +688,7 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lisk {@link #refresh()}, but no animation when show progress bar
|
||||
* Like {@link #refresh()}, but no animation when show progress bar
|
||||
*/
|
||||
public void firstRefresh() {
|
||||
showProgressBar(false);
|
||||
@@ -806,10 +717,6 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private int getPageEnd(int page) {
|
||||
return mPageDivider.get(page - mStartPage);
|
||||
}
|
||||
|
||||
private int getPageForPosition(int position) {
|
||||
if (position < 0) {
|
||||
return -1;
|
||||
@@ -829,10 +736,6 @@ public class ContentLayout extends FrameLayout {
|
||||
return getPageForPosition(LayoutManagerUtils.getFirstVisibleItemPosition(mRecyclerView.getLayoutManager()));
|
||||
}
|
||||
|
||||
public int getPageForBottom() {
|
||||
return getPageForPosition(LayoutManagerUtils.getLastVisibleItemPosition(mRecyclerView.getLayoutManager()));
|
||||
}
|
||||
|
||||
public boolean canGoTo() {
|
||||
return isContentShowing();
|
||||
}
|
||||
@@ -841,7 +744,7 @@ public class ContentLayout extends FrameLayout {
|
||||
* Check range first!
|
||||
*
|
||||
* @param page the target page
|
||||
* @throws IndexOutOfBoundsException
|
||||
* @throws IndexOutOfBoundsException if page < 0 or page >= mPages
|
||||
*/
|
||||
public void goTo(int page) throws IndexOutOfBoundsException {
|
||||
if (page < 0 || page >= mPages) {
|
||||
|
||||
Reference in new issue
Block a user