1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

various story fixes, closes #1496

This commit is contained in:
Austin Huang 2021-06-30 11:32:39 -04:00
parent 19d3434dbf
commit 80787c7e5e
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
7 changed files with 52 additions and 47 deletions

View File

@ -473,11 +473,11 @@ public class StoryViewerFragment extends Fragment {
poll = (PollSticker) tag;
final List<Tally> 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<Tally> 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();

View File

@ -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<Tally>?,
var viewerVote: Int = -1
val tallies: List<Tally>,
var viewerVote: Int?
) : Serializable

View File

@ -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

View File

@ -8,7 +8,7 @@ import awais.instagrabber.repositories.responses.User
data class QuizSticker(
val quizId: Long?,
val question: String?,
val tallies: List<Tally>?,
var viewerAnswer: Int? = -1,
val correctAnswer: Int?
val tallies: List<Tally>,
var viewerAnswer: Int?,
val correctAnswer: Int
) : Serializable

View File

@ -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<MediaCandidate>? = 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<StorySticker>? = null,
val storyHashtags: List<StorySticker>? = null,
val storyLocations: List<StorySticker>? = null,
val storyFeedMedia: List<StorySticker>? = null,
val storyPolls: List<StorySticker>? = null,
val storyQuestions: List<StorySticker>? = null,
val storyQuizs: List<StorySticker>? = null,
val storyCta: List<StorySticker>? = null,
val storySliders: List<StorySticker>? = 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<MediaCandidate>? = 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<StorySticker>? = null,
val storyHashtags: List<StorySticker>? = null,
val storyLocations: List<StorySticker>? = null,
val storyFeedMedia: List<StorySticker>? = null,
val storyPolls: List<StorySticker>? = null,
val storyQuestions: List<StorySticker>? = null,
val storyQuizs: List<StorySticker>? = null,
val storyCta: List<StorySticker>? = null,
val storySliders: List<StorySticker>? = 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 ""

View File

@ -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<StoryCta?>?, // story_cta, requires link_text from the story
val sliderSticker: SliderSticker? // story_sliders
) : Serializable

View File

@ -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 + "_"