Browse Source

various story fixes, closes #1496

renovate/org.robolectric-robolectric-4.x
Austin Huang 3 years ago
parent
commit
80787c7e5e
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 15
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  2. 6
      app/src/main/java/awais/instagrabber/repositories/responses/stories/PollSticker.kt
  3. 4
      app/src/main/java/awais/instagrabber/repositories/responses/stories/QuestionSticker.kt
  4. 6
      app/src/main/java/awais/instagrabber/repositories/responses/stories/QuizSticker.kt
  5. 6
      app/src/main/java/awais/instagrabber/repositories/responses/stories/StoryMedia.kt
  6. 2
      app/src/main/java/awais/instagrabber/repositories/responses/stories/StorySticker.kt
  7. 2
      app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt

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

@ -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();

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

4
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

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

6
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
@ -17,7 +18,7 @@ data class StoryMedia(
val imageVersions2: ImageVersions2? = null,
val originalWidth: Int = 0,
val originalHeight: Int = 0,
val mediaType: MediaItemType? = null,
val mediaType: Int = 0,
val isReelMedia: Boolean = false,
val videoVersions: List<MediaCandidate>? = null,
val hasAudio: Boolean = false,
@ -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 ""

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

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

Loading…
Cancel
Save