From 80787c7e5e5a4a98ba2ffe57506b5ed7b116f991 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Wed, 30 Jun 2021 11:32:39 -0400 Subject: [PATCH] various story fixes, closes #1496 --- .../fragments/StoryViewerFragment.java | 15 +++-- .../responses/stories/PollSticker.kt | 6 +- .../responses/stories/QuestionSticker.kt | 4 +- .../responses/stories/QuizSticker.kt | 6 +- .../responses/stories/StoryMedia.kt | 64 ++++++++++--------- .../responses/stories/StorySticker.kt | 2 +- .../awais/instagrabber/utils/DownloadUtils.kt | 2 +- 7 files changed, 52 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 59346a17..d6400c7e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -473,11 +473,11 @@ public class StoryViewerFragment extends Fragment { poll = (PollSticker) tag; final List tallies = poll.getTallies(); final String[] choices = tallies.stream() - .map(t -> (poll.getViewerVote() == tallies.indexOf(t) ? "√ " : "") + .map(t -> (poll.getViewerVote() != null && poll.getViewerVote() == tallies.indexOf(t) ? "√ " : "") + t.getText() + " (" + t.getCount() + ")" ) .toArray(String[]::new); final ArrayAdapter adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, choices); - if (poll.getViewerVote() > -1) { + if (poll.getViewerVote() != null) { new AlertDialog.Builder(context) .setTitle(R.string.voted_story_poll) .setAdapter(adapter, null) @@ -577,16 +577,17 @@ public class StoryViewerFragment extends Fragment { .setPositiveButton(R.string.cancel, null) .show(); } else if (tag instanceof QuizSticker) { + quiz = (QuizSticker) tag; final List tallies = quiz.getTallies(); final String[] choices = tallies.stream().map( - t -> (quiz.getViewerAnswer() == tallies.indexOf(t) ? "√ " : "") + + t -> (quiz.getViewerAnswer() != null && quiz.getViewerAnswer() == tallies.indexOf(t) ? "√ " : "") + (quiz.getCorrectAnswer() == tallies.indexOf(t) ? "*** " : "") + t.getText() + " (" + t.getCount() + ")" ).toArray(String[]::new); new AlertDialog.Builder(context) - .setTitle(quiz.getViewerAnswer() > -1 ? getString(R.string.story_quizzed) : quiz.getQuestion()) + .setTitle(quiz.getViewerAnswer() != null ? getString(R.string.story_quizzed) : quiz.getQuestion()) .setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, choices), (d, w) -> { - if (quiz.getViewerAnswer() == -1) { + if (quiz.getViewerAnswer() == null) { sticking = true; storiesRepository.respondToQuiz( csrfToken, @@ -901,7 +902,7 @@ public class StoryViewerFragment extends Fragment { } lastSlidePos = slidePos; - final MediaItemType itemType = currentStory.getMediaType(); + final MediaItemType itemType = currentStory.getType(); url = itemType == MediaItemType.MEDIA_TYPE_IMAGE ? ResponseBodyUtils.getImageUrl(currentStory) @@ -966,7 +967,7 @@ public class StoryViewerFragment extends Fragment { } if (currentStory.getStoryCta() != null) { - final StoryCta swipeUp = currentStory.getStoryCta().get(0).getLinks(); + final StoryCta swipeUp = currentStory.getStoryCta().get(0).getLinks().get(0); binding.swipeUp.setVisibility(View.VISIBLE); binding.swipeUp.setText(currentStory.getLinkText()); final String swipeUpUrl = swipeUp.getWebUri(); diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/PollSticker.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/PollSticker.kt index d95e1329..537a3d21 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/stories/PollSticker.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/PollSticker.kt @@ -6,8 +6,8 @@ import awais.instagrabber.repositories.responses.Location import awais.instagrabber.repositories.responses.User data class PollSticker( - val pollId: Long?, + val pollId: Long, val question: String?, - val tallies: List?, - var viewerVote: Int = -1 + val tallies: List, + var viewerVote: Int? ) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuestionSticker.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuestionSticker.kt index 7b9f1bf8..7dfec43c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuestionSticker.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuestionSticker.kt @@ -7,6 +7,6 @@ import awais.instagrabber.repositories.responses.User data class QuestionSticker( val questionType: String?, - val questionId: Long?, - val question: String? + val questionId: Long, + val question: String ) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuizSticker.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuizSticker.kt index 5a82a88f..45f237f2 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuizSticker.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/QuizSticker.kt @@ -8,7 +8,7 @@ import awais.instagrabber.repositories.responses.User data class QuizSticker( val quizId: Long?, val question: String?, - val tallies: List?, - var viewerAnswer: Int? = -1, - val correctAnswer: Int? + val tallies: List, + var viewerAnswer: Int?, + val correctAnswer: Int ) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/StoryMedia.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/StoryMedia.kt index 47af8625..f9559fd0 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/stories/StoryMedia.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/StoryMedia.kt @@ -1,6 +1,7 @@ package awais.instagrabber.repositories.responses.stories import awais.instagrabber.models.enums.MediaItemType +import awais.instagrabber.models.enums.MediaItemType.Companion.valueOf import awais.instagrabber.repositories.responses.ImageVersions2 import awais.instagrabber.repositories.responses.MediaCandidate import awais.instagrabber.repositories.responses.User @@ -9,36 +10,36 @@ import java.io.Serializable data class StoryMedia( // inherited from Media - val pk: String? = null, - val id: String? = null, - val takenAt: Long = -1, - val user: User? = null, - val canReshare: Boolean = false, - val imageVersions2: ImageVersions2? = null, - val originalWidth: Int = 0, - val originalHeight: Int = 0, - val mediaType: MediaItemType? = null, - val isReelMedia: Boolean = false, - val videoVersions: List? = null, - val hasAudio: Boolean = false, - val videoDuration: Double = 0.0, - val viewCount: Long = 0, - val title: String? = null, - // story-specific - val canReply: Boolean = false, - val linkText: String? = null, // required for story_cta - // stickers - val reelMentions: List? = null, - val storyHashtags: List? = null, - val storyLocations: List? = null, - val storyFeedMedia: List? = null, - val storyPolls: List? = null, - val storyQuestions: List? = null, - val storyQuizs: List? = null, - val storyCta: List? = null, - val storySliders: List? = null, - // spotify/soundcloud button, not a sticker - val storyAppAttribution: StoryAppAttribution? = null + val pk: String? = null, + val id: String? = null, + val takenAt: Long = -1, + val user: User? = null, + val canReshare: Boolean = false, + val imageVersions2: ImageVersions2? = null, + val originalWidth: Int = 0, + val originalHeight: Int = 0, + val mediaType: Int = 0, + val isReelMedia: Boolean = false, + val videoVersions: List? = null, + val hasAudio: Boolean = false, + val videoDuration: Double = 0.0, + val viewCount: Long = 0, + val title: String? = null, + // story-specific + val canReply: Boolean = false, + val linkText: String? = null, // required for story_cta + // stickers + val reelMentions: List? = null, + val storyHashtags: List? = null, + val storyLocations: List? = null, + val storyFeedMedia: List? = null, + val storyPolls: List? = null, + val storyQuestions: List? = null, + val storyQuizs: List? = null, + val storyCta: List? = null, + val storySliders: List? = null, + // spotify/soundcloud button, not a sticker + val storyAppAttribution: StoryAppAttribution? = null ) : Serializable { private var dateString: String? = null var position = 0 @@ -48,6 +49,9 @@ data class StoryMedia( // val date: String by lazy { // if (takenAt <= 0) "" else Utils.datetimeParser.format(Date(takenAt * 1000L)) // } + val type: MediaItemType? + get() = valueOf(mediaType) + val date: String get() { if (takenAt <= 0) return "" diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/stories/StorySticker.kt b/app/src/main/java/awais/instagrabber/repositories/responses/stories/StorySticker.kt index 7f40f94a..1f154e30 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/stories/StorySticker.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/stories/StorySticker.kt @@ -14,6 +14,6 @@ data class StorySticker( val pollSticker: PollSticker?, // story_polls val questionSticker: QuestionSticker?, // story_questions val quizSticker: QuizSticker?, // story_quizs - val links: StoryCta?, // story_cta, requires link_text from the story + val links: List?, // story_cta, requires link_text from the story val sliderSticker: SliderSticker? // story_sliders ) : Serializable \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt index d5f3eebb..c272b2fd 100644 --- a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt +++ b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt @@ -396,7 +396,7 @@ object DownloadUtils { ) { val downloadDir = getDownloadDir(context, storyModel.user?.username) ?: return val url = - if (storyModel.mediaType == MediaItemType.MEDIA_TYPE_VIDEO) ResponseBodyUtils.getVideoUrl(storyModel) + if (storyModel.type == MediaItemType.MEDIA_TYPE_VIDEO) ResponseBodyUtils.getVideoUrl(storyModel) else ResponseBodyUtils.getImageUrl(storyModel) val extension = getFileExtensionFromUrl(url) val baseFileName = (storyModel.id + "_"