Browse Source

Check currentFeedStoryIndex every time before accessing models list. Fixes: https://github.com/austinhuang0131/barinsta/issues/819

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
1cd75356c7
  1. 8
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

8
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -684,12 +684,11 @@ public class StoryViewerFragment extends Fragment {
String currentStoryMediaId = null;
final Type type = options.getType();
StoryViewerOptions fetchOptions = null;
if (currentFeedStoryIndex >= 0) {
switch (type) {
case HIGHLIGHT: {
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
final List<HighlightModel> models = highlightsViewModel.getList().getValue();
if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size()) {
if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size() || currentFeedStoryIndex < 0) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
@ -702,7 +701,7 @@ public class StoryViewerFragment extends Fragment {
case FEED_STORY_POSITION: {
final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel;
final List<FeedStoryModel> models = feedStoriesViewModel.getList().getValue();
if (models == null) return;
if (models == null || currentFeedStoryIndex >= models.size() || currentFeedStoryIndex < 0) return;
final FeedStoryModel model = models.get(currentFeedStoryIndex);
currentStoryMediaId = model.getStoryMediaId();
currentStoryUsername = model.getProfileModel().getUsername();
@ -715,7 +714,7 @@ public class StoryViewerFragment extends Fragment {
case STORY_ARCHIVE: {
final ArchivesViewModel archivesViewModel = (ArchivesViewModel) viewModel;
final List<HighlightModel> models = archivesViewModel.getList().getValue();
if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size()) {
if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size() || currentFeedStoryIndex < 0) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
@ -726,7 +725,6 @@ public class StoryViewerFragment extends Fragment {
break;
}
}
}
if (type == Type.USER) {
currentStoryMediaId = String.valueOf(options.getId());
currentStoryUsername = options.getName();

Loading…
Cancel
Save