diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 95434ca0..02c2e4d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1353,11 +1353,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - if (canStartActivity) { + int position = getAdapterPosition(); + if (position > 0 && canStartActivity) { canStartActivity = false; Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, getItem(getAdapterPosition())); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, getItem(position)); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, getAdapterPosition()); mActivity.startActivity(intent); } @@ -1365,7 +1366,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (canStartActivity) { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { canStartActivity = false; Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); @@ -1377,7 +1382,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (canStartActivity) { canStartActivity = false; @@ -1399,7 +1408,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter subredditTextView.performClick()); } else { subredditTextView.setOnClickListener(view -> { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (canStartActivity) { canStartActivity = false; @@ -1422,7 +1435,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { Intent intent = new Intent(mActivity, FilteredThingActivity.class); intent.putExtra(FilteredThingActivity.EXTRA_NAME, post.getSubredditNamePrefixed().substring(2)); @@ -1432,7 +1449,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { mCallback.typeChipClicked(post.getPostType()); } @@ -1440,7 +1461,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (mAccessToken == null) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); @@ -1514,7 +1539,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (mAccessToken == null) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); @@ -1588,7 +1617,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (mAccessToken == null) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); @@ -1640,7 +1673,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { shareLink(post); } @@ -1752,7 +1789,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { Intent intent = new Intent(mActivity, ViewVideoActivity.class); intent.setData(Uri.parse(post.getVideoUrl())); @@ -1955,7 +1996,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (post.getPostType() == Post.VIDEO_TYPE) { Intent intent = new Intent(mActivity, ViewVideoActivity.class); @@ -2063,7 +2108,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { if (post.getPostType() == Post.IMAGE_TYPE) { Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class); @@ -2172,7 +2221,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { Intent intent = new Intent(mActivity, LinkResolverActivity.class); Uri uri = Uri.parse(post.getUrl()); @@ -2268,7 +2321,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { Intent intent = new Intent(mActivity, LinkResolverActivity.class); Uri uri = Uri.parse(post.getUrl()); @@ -2373,7 +2430,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class); intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery()); @@ -2607,7 +2668,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null && canStartActivity) { canStartActivity = false; @@ -2619,7 +2684,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null && canStartActivity) { canStartActivity = false; if (mDisplaySubredditName) { @@ -2645,7 +2714,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter nameTextView.performClick()); nsfwTextView.setOnClickListener(view -> { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null && !(mActivity instanceof FilteredThingActivity)) { Intent intent = new Intent(mActivity, FilteredThingActivity.class); intent.putExtra(FilteredThingActivity.EXTRA_NAME, post.getSubredditNamePrefixed().substring(2)); @@ -2656,14 +2729,22 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null && !(mActivity instanceof FilteredThingActivity)) { mCallback.typeChipClicked(post.getPostType()); } }); imageView.setOnClickListener(view -> { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { switch (post.getPostType()) { case Post.IMAGE_TYPE: { @@ -2709,7 +2790,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { Intent intent = new Intent(mActivity, LinkResolverActivity.class); Uri uri = Uri.parse(post.getUrl()); @@ -2729,7 +2814,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - Post post = getItem(getAdapterPosition()); + int position = getAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); if (post != null) { shareLink(post); }