From 0afe482b864b0b2b49c4a3ec48bed814a17d3963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Rodr=C3=ADguez=20Caballero?= Date: Sun, 21 Mar 2021 21:30:20 +0100 Subject: [PATCH] fix(StoryViewerFragment): crash when parsing unexpected Instagram id --- .../fragments/StoryViewerFragment.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index bfdeaaf3..c10e4384 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -65,6 +65,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import awais.instagrabber.BuildConfig; import awais.instagrabber.R; @@ -735,7 +737,7 @@ public class StoryViewerFragment extends Fragment { return; } final HighlightModel model = models.get(currentFeedStoryIndex); - currentStoryMediaId = model.getId(); + currentStoryMediaId = parseStoryMediaId(model.getId()); currentStoryUsername = model.getTitle(); fetchOptions = StoryViewerOptions.forUser(Long.parseLong(currentStoryMediaId), currentStoryUsername); break; @@ -1146,4 +1148,20 @@ public class StoryViewerFragment extends Fragment { resetView(); } } + + /** + * Parses the Story's media ID. For user stories this is a number, but for archive stories + * this is "archiveDay:" plus a number. + */ + private static String parseStoryMediaId(String rawId) { + final String regex = "(?:archiveDay:)?(.+)"; + final Pattern pattern = Pattern.compile(regex); + final Matcher matcher = pattern.matcher(rawId); + + if (matcher.matches() && matcher.groupCount() >= 1) { + return matcher.group(1); + } + + return rawId; + } }