Update dependencies
Settings activity refactor
This commit is contained in:
248 files changed
+8700
-8980
No files matched your search
@@ -28,9 +28,11 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
@@ -45,6 +47,7 @@ import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.collect.IntList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -167,10 +170,18 @@ public class ContentLayout extends FrameLayout {
|
||||
|
||||
public abstract static class ContentHelper<E extends Parcelable> implements ViewTransition.OnShowViewListener {
|
||||
|
||||
public static final int TYPE_REFRESH = 0;
|
||||
public static final int TYPE_PRE_PAGE = 1;
|
||||
public static final int TYPE_PRE_PAGE_KEEP_POS = 2;
|
||||
public static final int TYPE_NEXT_PAGE = 3;
|
||||
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";
|
||||
private static final String KEY_SHOWN_VIEW = "shown_view";
|
||||
private static final String KEY_TIP = "tip";
|
||||
@@ -180,83 +191,53 @@ public class ContentLayout extends FrameLayout {
|
||||
private static final String KEY_START_PAGE = "start_page";
|
||||
private static final String KEY_END_PAGE = "end_page";
|
||||
private static final String KEY_PAGES = "pages";
|
||||
|
||||
public static final int TYPE_REFRESH = 0;
|
||||
public static final int TYPE_PRE_PAGE = 1;
|
||||
public static final int TYPE_PRE_PAGE_KEEP_POS = 2;
|
||||
public static final int TYPE_NEXT_PAGE = 3;
|
||||
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 ProgressView mProgressView;
|
||||
private TextView mTipView;
|
||||
private ViewGroup mContentView;
|
||||
|
||||
private RefreshLayout mRefreshLayout;
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*/
|
||||
private ArrayList<E> mData = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Generate task id
|
||||
*/
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
|
||||
private final LayoutManagerUtils.OnScrollToPositionListener mOnScrollToPositionListener =
|
||||
new LayoutManagerUtils.OnScrollToPositionListener() {
|
||||
@Override
|
||||
public void onScrollToPosition(int position) {
|
||||
ContentHelper.this.onScrollToPosition(position);
|
||||
}
|
||||
};
|
||||
private ProgressView mProgressView;
|
||||
private TextView mTipView;
|
||||
private ViewGroup mContentView;
|
||||
private RefreshLayout mRefreshLayout;
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
private ViewTransition mViewTransition;
|
||||
/**
|
||||
* Store data
|
||||
*/
|
||||
private ArrayList<E> mData = new ArrayList<>();
|
||||
/**
|
||||
* Store the page divider index
|
||||
*
|
||||
* <p>
|
||||
* For example, the data contain page 3, page 4, page 5,
|
||||
* page 3 size is 7, page 4 size is 8, page 5 size is 9,
|
||||
* so <code>mPageDivider</code> contain 7, 15, 24.
|
||||
*/
|
||||
private IntList mPageDivider = new IntList();
|
||||
|
||||
/**
|
||||
* The first page in <code>mData</code>
|
||||
*/
|
||||
private int mStartPage;
|
||||
|
||||
/**
|
||||
* The last page + 1 in <code>mData</code>
|
||||
*/
|
||||
private int mEndPage;
|
||||
|
||||
/**
|
||||
* The available page count.
|
||||
*/
|
||||
private int mPages;
|
||||
|
||||
private int mNextPage;
|
||||
|
||||
private int mCurrentTaskId;
|
||||
private int mCurrentTaskType;
|
||||
private int mCurrentTaskPage;
|
||||
|
||||
private int mNextPageScrollSize;
|
||||
|
||||
private String mEmptyString = "No hint";
|
||||
|
||||
private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
if (!mRefreshLayout.isRefreshing() && mRefreshLayout.isAlmostBottom() && mEndPage < mPages) {
|
||||
// Get next page
|
||||
mRefreshLayout.setFooterRefreshing(true);
|
||||
mOnRefreshListener.onFooterRefresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final RefreshLayout.OnRefreshListener mOnRefreshListener = new RefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onHeaderRefresh() {
|
||||
@@ -297,14 +278,17 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final LayoutManagerUtils.OnScrollToPositionListener mOnScrollToPositionListener =
|
||||
new LayoutManagerUtils.OnScrollToPositionListener() {
|
||||
@Override
|
||||
public void onScrollToPosition(int position) {
|
||||
ContentHelper.this.onScrollToPosition(position);
|
||||
}
|
||||
};
|
||||
private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
if (!mRefreshLayout.isRefreshing() && mRefreshLayout.isAlmostBottom() && mEndPage < mPages) {
|
||||
// Get next page
|
||||
mRefreshLayout.setFooterRefreshing(true);
|
||||
mOnRefreshListener.onFooterRefresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
private int mSavedDataId = IntIdGenerator.INVALID_ID;
|
||||
|
||||
private void init(ContentLayout contentLayout) {
|
||||
mNextPageScrollSize = LayoutUtils.dp2pix(contentLayout.getContext(), 48);
|
||||
@@ -338,7 +322,7 @@ public class ContentLayout extends FrameLayout {
|
||||
* Call {@link #onGetPageData(int, int, int, List)} when get data
|
||||
*
|
||||
* @param taskId task id
|
||||
* @param page the page to get
|
||||
* @param page the page to get
|
||||
*/
|
||||
protected abstract void getPageData(int taskId, int type, int page);
|
||||
|
||||
@@ -350,10 +334,12 @@ public class ContentLayout extends FrameLayout {
|
||||
|
||||
protected abstract void notifyItemRangeInserted(int positionStart, int itemCount);
|
||||
|
||||
protected void onScrollToPosition(int postion) {}
|
||||
protected void onScrollToPosition(int postion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowView(View hiddenView, View shownView) {}
|
||||
public void onShowView(View hiddenView, View shownView) {
|
||||
}
|
||||
|
||||
public int getShownViewIndex() {
|
||||
return mViewTransition.getShownViewIndex();
|
||||
@@ -376,8 +362,7 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code location < 0 || location >= size()}
|
||||
* @throws IndexOutOfBoundsException if {@code location < 0 || location >= size()}
|
||||
*/
|
||||
public E getDataAt(int location) {
|
||||
return mData.get(location);
|
||||
@@ -437,7 +422,7 @@ public class ContentLayout extends FrameLayout {
|
||||
private void removeDuplicateData(List<E> data, int start, int end) {
|
||||
start = Math.max(0, start);
|
||||
end = Math.min(mData.size(), end);
|
||||
for (Iterator<E> iterator = data.iterator(); iterator.hasNext();) {
|
||||
for (Iterator<E> iterator = data.iterator(); iterator.hasNext(); ) {
|
||||
E d = iterator.next();
|
||||
for (int i = start; i < end; i++) {
|
||||
if (isDuplicate(d, mData.get(i))) {
|
||||
@@ -448,15 +433,20 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
protected void onAddData(E data) { }
|
||||
protected void onAddData(E data) {
|
||||
}
|
||||
|
||||
protected void onAddData(List<E> data) { }
|
||||
protected void onAddData(List<E> data) {
|
||||
}
|
||||
|
||||
protected void onRemoveData(E data) { }
|
||||
protected void onRemoveData(E data) {
|
||||
}
|
||||
|
||||
protected void onRemoveData(List<E> data) { }
|
||||
protected void onRemoveData(List<E> data) {
|
||||
}
|
||||
|
||||
protected void onClearData() { }
|
||||
protected void onClearData() {
|
||||
}
|
||||
|
||||
public void onGetPageData(int taskId, int pages, int nextPage, List<E> data) {
|
||||
if (mCurrentTaskId == taskId) {
|
||||
@@ -927,8 +917,6 @@ public class ContentLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private int mSavedDataId = IntIdGenerator.INVALID_ID;
|
||||
|
||||
protected Parcelable saveInstanceState(Parcelable superState) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(KEY_SUPER, superState);
|
||||
|
||||
Reference in new issue
Block a user