diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java index 244e8beeb..cc726acac 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java @@ -605,7 +605,10 @@ public class FavoritesScene extends BaseScene implements if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) { mRecyclerView.toggleItemChecked(position); } else if (mHelper != null) { - GalleryInfo gi = mHelper.getDataAt(position); + GalleryInfo gi = mHelper.getDataAtEx(position); + if (gi == null) { + return true; + } Bundle args = new Bundle(); args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO); args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi); @@ -751,7 +754,10 @@ public class FavoritesScene extends BaseScene implements SparseBooleanArray stateArray = mRecyclerView.getCheckedItemPositions(); for (int i = 0, n = stateArray.size(); i < n; i++) { if (stateArray.valueAt(i)) { - mModifyGiList.add(mHelper.getDataAt(stateArray.keyAt(i))); + GalleryInfo gi = mHelper.getDataAtEx(stateArray.keyAt(i)); + if (gi != null) { + mModifyGiList.add(gi); + } } } @@ -1002,7 +1008,7 @@ public class FavoritesScene extends BaseScene implements @Nullable @Override public GalleryInfo getDataAt(int position) { - return null != mHelper ? mHelper.getDataAt(position) : null; + return null != mHelper ? mHelper.getDataAtEx(position) : null; } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 90726d4b5..d510b24bb 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -832,7 +832,11 @@ public final class GalleryListScene extends BaseScene return false; } - GalleryInfo gi = mHelper.getDataAt(position); + GalleryInfo gi = mHelper.getDataAtEx(position); + if (gi == null) { + return true; + } + Bundle args = new Bundle(); args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO); args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi); @@ -946,7 +950,11 @@ public final class GalleryListScene extends BaseScene return false; } - final GalleryInfo gi = mHelper.getDataAt(position); + final GalleryInfo gi = mHelper.getDataAtEx(position); + if (gi == null) { + return true; + } + new AlertDialog.Builder(context) .setTitle(EhUtils.getSuitableTitle(gi)) .setItems(R.array.gallery_list_menu_entries, new DialogInterface.OnClickListener() { @@ -1340,7 +1348,7 @@ public final class GalleryListScene extends BaseScene @Nullable @Override public GalleryInfo getDataAt(int position) { - return null != mHelper ? mHelper.getDataAt(position) : null; + return null != mHelper ? mHelper.getDataAtEx(position) : null; } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java index 973319beb..7f6521668 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java @@ -231,12 +231,14 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) { Context context = getContext2(); if (null != context && null != mHelper && null != mGalleryInfo) { - GalleryPreview p = mHelper.getDataAt(position); - Intent intent = new Intent(context, GalleryActivity.class); - intent.setAction(GalleryActivity.ACTION_EH); - intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryInfo); - intent.putExtra(GalleryActivity.KEY_PAGE, p.getPosition()); - startActivity(intent); + GalleryPreview p = mHelper.getDataAtEx(position); + if (p != null) { + Intent intent = new Intent(context, GalleryActivity.class); + intent.setAction(GalleryActivity.ACTION_EH); + intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryInfo); + intent.putExtra(GalleryActivity.KEY_PAGE, p.getPosition()); + startActivity(intent); + } } return true; } @@ -272,9 +274,11 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi @SuppressLint("SetTextI18n") public void onBindViewHolder(GalleryPreviewHolder holder, int position) { if (null != mHelper) { - GalleryPreview preview = mHelper.getDataAt(position); - preview.load(holder.image); - holder.text.setText(Integer.toString(preview.getPosition() + 1)); + GalleryPreview preview = mHelper.getDataAtEx(position); + if (preview != null) { + preview.load(holder.image); + holder.text.setText(Integer.toString(preview.getPosition() + 1)); + } } } diff --git a/app/src/main/java/com/hippo/widget/ContentLayout.java b/app/src/main/java/com/hippo/widget/ContentLayout.java index a5924eca1..7520d350c 100644 --- a/app/src/main/java/com/hippo/widget/ContentLayout.java +++ b/app/src/main/java/com/hippo/widget/ContentLayout.java @@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.util.Log; @@ -368,6 +369,15 @@ public class ContentLayout extends FrameLayout { return mData.get(location); } + @Nullable + public E getDataAtEx(int location) { + if (location >= 0 && location < mData.size()) { + return mData.get(location); + } else { + return null; + } + } + public int size() { return mData.size(); }