mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-26 08:37:29 +00:00
Merge pull request #836 from MeLlamoPablo/fix/archive-story-viewer-crash
Fix crashes on the story archive viewer
This commit is contained in:
commit
74be5a5caf
@ -79,7 +79,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
|||||||
public void onHighlightClick(final HighlightModel model, final int position) {
|
public void onHighlightClick(final HighlightModel model, final int position) {
|
||||||
if (model == null) return;
|
if (model == null) return;
|
||||||
final NavDirections action = StoryListViewerFragmentDirections
|
final NavDirections action = StoryListViewerFragmentDirections
|
||||||
.actionStoryListFragmentToStoryViewerFragment(StoryViewerOptions.forStoryArchive(position));
|
.actionStoryListFragmentToStoryViewerFragment(StoryViewerOptions.forStoryArchive(model.getId()));
|
||||||
NavHostFragment.findNavController(StoryListViewerFragment.this).navigate(action);
|
NavHostFragment.findNavController(StoryListViewerFragment.this).navigate(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import awais.instagrabber.BuildConfig;
|
import awais.instagrabber.BuildConfig;
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
@ -304,11 +306,18 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
// isNotification = fragmentArgs.getIsNotification();
|
// isNotification = fragmentArgs.getIsNotification();
|
||||||
final Type type = options.getType();
|
final Type type = options.getType();
|
||||||
if (currentFeedStoryIndex >= 0) {
|
if (currentFeedStoryIndex >= 0) {
|
||||||
viewModel = type == Type.HIGHLIGHT
|
switch (type) {
|
||||||
? type == Type.STORY_ARCHIVE
|
case HIGHLIGHT:
|
||||||
? new ViewModelProvider(fragmentActivity).get(ArchivesViewModel.class)
|
viewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class);
|
||||||
: new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class)
|
break;
|
||||||
: new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
case STORY_ARCHIVE:
|
||||||
|
viewModel = new ViewModelProvider(fragmentActivity).get(ArchivesViewModel.class);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case FEED_STORY_POSITION:
|
||||||
|
viewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setupStories();
|
setupStories();
|
||||||
}
|
}
|
||||||
@ -728,9 +737,9 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HighlightModel model = models.get(currentFeedStoryIndex);
|
final HighlightModel model = models.get(currentFeedStoryIndex);
|
||||||
currentStoryMediaId = model.getId();
|
currentStoryMediaId = parseStoryMediaId(model.getId());
|
||||||
currentStoryUsername = model.getTitle();
|
currentStoryUsername = model.getTitle();
|
||||||
fetchOptions = StoryViewerOptions.forUser(Long.parseLong(currentStoryMediaId), currentStoryUsername);
|
fetchOptions = StoryViewerOptions.forStoryArchive(model.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1139,4 +1148,20 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
resetView();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ public class StoryViewerOptions implements Serializable {
|
|||||||
return new StoryViewerOptions(position, Type.FEED_STORY_POSITION);
|
return new StoryViewerOptions(position, Type.FEED_STORY_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StoryViewerOptions forStoryArchive(final int position) {
|
public static StoryViewerOptions forStoryArchive(final String id) {
|
||||||
return new StoryViewerOptions(position, Type.STORY_ARCHIVE);
|
return new StoryViewerOptions(id, Type.STORY_ARCHIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
|
@ -943,8 +943,7 @@ public final class ResponseBodyUtils {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
public static StoryModel parseStoryItem(final JSONObject data,
|
public static StoryModel parseStoryItem(final JSONObject data,
|
||||||
final boolean isLoc,
|
final boolean isLocOrHashtag,
|
||||||
final boolean isHashtag,
|
|
||||||
final String username) throws JSONException {
|
final String username) throws JSONException {
|
||||||
final boolean isVideo = data.has("video_duration");
|
final boolean isVideo = data.has("video_duration");
|
||||||
final StoryModel model = new StoryModel(data.getString("id"),
|
final StoryModel model = new StoryModel(data.getString("id"),
|
||||||
@ -952,9 +951,7 @@ public final class ResponseBodyUtils {
|
|||||||
.getString("url"), null,
|
.getString("url"), null,
|
||||||
isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE,
|
isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE,
|
||||||
data.optLong("taken_at", 0),
|
data.optLong("taken_at", 0),
|
||||||
(isLoc || isHashtag)
|
isLocOrHashtag ? data.getJSONObject("user").getString("username") : username,
|
||||||
? data.getJSONObject("user").getString("username")
|
|
||||||
: username,
|
|
||||||
data.getJSONObject("user").getLong("pk"),
|
data.getJSONObject("user").getLong("pk"),
|
||||||
data.optBoolean("can_reply"));
|
data.optBoolean("can_reply"));
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class StoriesService extends BaseService {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final JSONObject itemJson = new JSONObject(body).getJSONArray("items").getJSONObject(0);
|
final JSONObject itemJson = new JSONObject(body).getJSONArray("items").getJSONObject(0);
|
||||||
callback.onSuccess(ResponseBodyUtils.parseStoryItem(itemJson, false, false, null));
|
callback.onSuccess(ResponseBodyUtils.parseStoryItem(itemJson, false, null));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
callback.onFailure(e);
|
callback.onFailure(e);
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ public class StoriesService extends BaseService {
|
|||||||
final boolean isBestie = node.optBoolean("has_besties_media", false);
|
final boolean isBestie = node.optBoolean("has_besties_media", false);
|
||||||
StoryModel firstStoryModel = null;
|
StoryModel firstStoryModel = null;
|
||||||
if (itemJson != null) {
|
if (itemJson != null) {
|
||||||
firstStoryModel = ResponseBodyUtils.parseStoryItem(itemJson, false, false, null);
|
firstStoryModel = ResponseBodyUtils.parseStoryItem(itemJson, false, null);
|
||||||
}
|
}
|
||||||
feedStoryModels.add(new FeedStoryModel(id, user, fullyRead, timestamp, firstStoryModel, mediaCount, false, isBestie));
|
feedStoryModels.add(new FeedStoryModel(id, user, fullyRead, timestamp, firstStoryModel, mediaCount, false, isBestie));
|
||||||
}
|
}
|
||||||
@ -364,9 +364,8 @@ public class StoriesService extends BaseService {
|
|||||||
final ServiceCallback<List<StoryModel>> callback) {
|
final ServiceCallback<List<StoryModel>> callback) {
|
||||||
final String url = buildUrl(options);
|
final String url = buildUrl(options);
|
||||||
final Call<String> userStoryCall = repository.getUserStory(url);
|
final Call<String> userStoryCall = repository.getUserStory(url);
|
||||||
final boolean isLoc = options.getType() == StoryViewerOptions.Type.LOCATION;
|
final boolean isLocOrHashtag = options.getType() == StoryViewerOptions.Type.LOCATION || options.getType() == StoryViewerOptions.Type.HASHTAG;
|
||||||
final boolean isHashtag = options.getType() == StoryViewerOptions.Type.HASHTAG;
|
final boolean isHighlight = options.getType() == StoryViewerOptions.Type.HIGHLIGHT || options.getType() == StoryViewerOptions.Type.STORY_ARCHIVE;
|
||||||
final boolean isHighlight = options.getType() == StoryViewerOptions.Type.HIGHLIGHT;
|
|
||||||
userStoryCall.enqueue(new Callback<String>() {
|
userStoryCall.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull final Call<String> call, @NonNull final Response<String> response) {
|
public void onResponse(@NonNull final Call<String> call, @NonNull final Response<String> response) {
|
||||||
@ -380,7 +379,7 @@ public class StoriesService extends BaseService {
|
|||||||
data = new JSONObject(body);
|
data = new JSONObject(body);
|
||||||
|
|
||||||
if (!isHighlight) {
|
if (!isHighlight) {
|
||||||
data = data.optJSONObject((isLoc || isHashtag) ? "story" : "reel");
|
data = data.optJSONObject((isLocOrHashtag) ? "story" : "reel");
|
||||||
} else {
|
} else {
|
||||||
data = data.getJSONObject("reels").optJSONObject(options.getName());
|
data = data.getJSONObject("reels").optJSONObject(options.getName());
|
||||||
}
|
}
|
||||||
@ -388,8 +387,7 @@ public class StoriesService extends BaseService {
|
|||||||
String username = null;
|
String username = null;
|
||||||
if (data != null
|
if (data != null
|
||||||
// && localUsername == null
|
// && localUsername == null
|
||||||
&& !isLoc
|
&& !isLocOrHashtag) {
|
||||||
&& !isHashtag) {
|
|
||||||
username = data.getJSONObject("user").getString("username");
|
username = data.getJSONObject("user").getString("username");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,12 +395,11 @@ public class StoriesService extends BaseService {
|
|||||||
if (data != null
|
if (data != null
|
||||||
&& (media = data.optJSONArray("items")) != null
|
&& (media = data.optJSONArray("items")) != null
|
||||||
&& media.length() > 0 && media.optJSONObject(0) != null) {
|
&& media.length() > 0 && media.optJSONObject(0) != null) {
|
||||||
|
|
||||||
final int mediaLen = media.length();
|
final int mediaLen = media.length();
|
||||||
final List<StoryModel> models = new ArrayList<>();
|
final List<StoryModel> models = new ArrayList<>();
|
||||||
for (int i = 0; i < mediaLen; ++i) {
|
for (int i = 0; i < mediaLen; ++i) {
|
||||||
data = media.getJSONObject(i);
|
data = media.getJSONObject(i);
|
||||||
models.add(ResponseBodyUtils.parseStoryItem(data, isLoc, isHashtag, username));
|
models.add(ResponseBodyUtils.parseStoryItem(data, isLocOrHashtag, username));
|
||||||
}
|
}
|
||||||
callback.onSuccess(models);
|
callback.onSuccess(models);
|
||||||
} else {
|
} else {
|
||||||
@ -543,6 +540,7 @@ public class StoriesService extends BaseService {
|
|||||||
id = String.valueOf(options.getId());
|
id = String.valueOf(options.getId());
|
||||||
break;
|
break;
|
||||||
case HIGHLIGHT:
|
case HIGHLIGHT:
|
||||||
|
case STORY_ARCHIVE:
|
||||||
builder.append("feed/reels_media/?user_ids=");
|
builder.append("feed/reels_media/?user_ids=");
|
||||||
id = options.getName();
|
id = options.getName();
|
||||||
break;
|
break;
|
||||||
@ -550,15 +548,12 @@ public class StoriesService extends BaseService {
|
|||||||
break;
|
break;
|
||||||
// case FEED_STORY_POSITION:
|
// case FEED_STORY_POSITION:
|
||||||
// break;
|
// break;
|
||||||
// case STORY_ARCHIVE:
|
|
||||||
// break;
|
|
||||||
}
|
}
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final String userId = id.replace(":", "%3A");
|
builder.append(id);
|
||||||
builder.append(userId);
|
if (type != StoryViewerOptions.Type.HIGHLIGHT && type != StoryViewerOptions.Type.STORY_ARCHIVE) {
|
||||||
if (type != StoryViewerOptions.Type.HIGHLIGHT) {
|
|
||||||
builder.append("/story/");
|
builder.append("/story/");
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
Loading…
Reference in New Issue
Block a user