From 321af4cad407f3dff3f1f8ce64a13c6624cb855a Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 17 Mar 2021 22:35:49 +0900 Subject: [PATCH] Pause post video in background. Fixes https://github.com/austinhuang0131/barinsta/issues/413 --- .../fragments/PostViewV2Fragment.java | 24 +++++++++++++++++++ .../responses/AnimatedMediaFixedHeight.java | 3 ++- .../responses/AnimatedMediaImages.java | 3 ++- .../responses/directmessages/DirectItem.java | 8 ++++--- .../directmessages/DirectItemActionLog.java | 3 ++- .../DirectItemAnimatedMedia.java | 3 ++- .../directmessages/DirectItemClip.java | 3 ++- .../directmessages/DirectItemFelixShare.java | 3 ++- .../directmessages/DirectItemLink.java | 3 ++- .../directmessages/DirectItemLinkContext.java | 3 ++- .../directmessages/DirectItemPlaceholder.java | 3 ++- .../directmessages/DirectItemReelShare.java | 3 ++- .../DirectItemReelShareReactionInfo.java | 3 ++- .../directmessages/DirectItemStoryShare.java | 3 ++- .../DirectItemVideoCallEvent.java | 3 ++- .../directmessages/DirectItemVisualMedia.java | 3 ++- .../directmessages/DirectItemVoiceMedia.java | 3 ++- .../DirectThreadDirectStory.java | 3 ++- .../DirectThreadLastSeenAt.java | 3 ++- .../RavenExpiringMediaActionSummary.java | 3 ++- 20 files changed, 65 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index 4d5e6c72..4c987059 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -323,6 +323,20 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im if (bottomSheetBehavior != null) { captionState = bottomSheetBehavior.getState(); } + final Media media = viewModel.getMedia(); + if (media == null) return; + switch (media.getMediaType()) { + case MEDIA_TYPE_VIDEO: + if (videoPlayerViewHelper != null) { + videoPlayerViewHelper.pause(); + } + return; + case MEDIA_TYPE_SLIDER: + if (sliderItemsAdapter != null) { + pauseSliderPlayer(); + } + default: + } } @Override @@ -1124,6 +1138,16 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im sliderItemsAdapter.submitList(media.getCarouselMedia()); } + private void pauseSliderPlayer() { + if (binding.sliderParent.getVisibility() != View.VISIBLE) return; + final int currentItem = binding.sliderParent.getCurrentItem(); + final View view = binding.sliderParent.getChildAt(0); + if (!(view instanceof RecyclerView)) return; + final RecyclerView.ViewHolder viewHolder = ((RecyclerView) view).findViewHolderForAdapterPosition(currentItem); + if (!(viewHolder instanceof SliderVideoViewHolder)) return; + ((SliderVideoViewHolder) viewHolder).pause(); + } + private void releaseAllSliderPlayers() { if (binding.sliderParent.getVisibility() != View.VISIBLE) return; final View view = binding.sliderParent.getChildAt(0); diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaFixedHeight.java b/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaFixedHeight.java index c5ffa272..da66471b 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaFixedHeight.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaFixedHeight.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses; +import java.io.Serializable; import java.util.Objects; -public class AnimatedMediaFixedHeight { +public class AnimatedMediaFixedHeight implements Serializable { private final int height; private final int width; private final String mp4; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaImages.java b/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaImages.java index d679fc92..d16aa93a 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaImages.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/AnimatedMediaImages.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses; +import java.io.Serializable; import java.util.Objects; -public class AnimatedMediaImages { +public class AnimatedMediaImages implements Serializable { private final AnimatedMediaFixedHeight fixedHeight; public AnimatedMediaImages(final AnimatedMediaFixedHeight fixedHeight) { diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItem.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItem.java index 35f8994d..1845c61a 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItem.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItem.java @@ -2,6 +2,7 @@ package awais.instagrabber.repositories.responses.directmessages; import androidx.annotation.NonNull; +import java.io.Serializable; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -14,7 +15,7 @@ import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; -public class DirectItem implements Cloneable { +public class DirectItem implements Cloneable, Serializable { private String itemId; private final long userId; private long timestamp; @@ -43,7 +44,7 @@ public class DirectItem implements Cloneable { private final int hideInThread; private Date date; private boolean isPending; - private boolean showForwardAttribution; + private final boolean showForwardAttribution; private LocalDateTime localDateTime; public DirectItem(final String itemId, @@ -220,7 +221,8 @@ public class DirectItem implements Cloneable { public LocalDateTime getLocalDateTime() { if (localDateTime == null) { - localDateTime = Instant.ofEpochMilli(timestamp / 1000).atZone(ZoneId.systemDefault()).toLocalDateTime();; + localDateTime = Instant.ofEpochMilli(timestamp / 1000).atZone(ZoneId.systemDefault()).toLocalDateTime(); + ; } return localDateTime; } diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.java index 3e31cb23..33d620e2 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemActionLog.java @@ -1,9 +1,10 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.List; import java.util.Objects; -public class DirectItemActionLog { +public class DirectItemActionLog implements Serializable { private final String description; private final List bold; private final List textAttributes; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.java index 98158862..b948726c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemAnimatedMedia.java @@ -1,10 +1,11 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; import awais.instagrabber.repositories.responses.AnimatedMediaImages; -public final class DirectItemAnimatedMedia { +public final class DirectItemAnimatedMedia implements Serializable { private final String id; private final AnimatedMediaImages images; private final boolean isRandom; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.java index 22660187..0568220d 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemClip.java @@ -1,10 +1,11 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; import awais.instagrabber.repositories.responses.Media; -public class DirectItemClip { +public class DirectItemClip implements Serializable { private final Media clip; public DirectItemClip(final Media clip) { diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.java index fee2ef59..f230027c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemFelixShare.java @@ -1,10 +1,11 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; import awais.instagrabber.repositories.responses.Media; -public class DirectItemFelixShare { +public class DirectItemFelixShare implements Serializable { private final Media video; public DirectItemFelixShare(final Media video) { diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.java index 2fe3f49c..d4d1915e 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLink.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; -public class DirectItemLink { +public class DirectItemLink implements Serializable { private final String text; private final DirectItemLinkContext linkContext; private final String clientContext; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.java index 79beb422..6f31a711 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemLinkContext.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; -public class DirectItemLinkContext { +public class DirectItemLinkContext implements Serializable { private final String linkUrl; private final String linkTitle; private final String linkSummary; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.java index 0c6002ae..5c309504 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemPlaceholder.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; -public class DirectItemPlaceholder { +public class DirectItemPlaceholder implements Serializable { private final boolean isLinked; private final String title; private final String message; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.java index 65fe4fbf..1e434dc4 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShare.java @@ -1,10 +1,11 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; import awais.instagrabber.repositories.responses.Media; -public class DirectItemReelShare { +public class DirectItemReelShare implements Serializable { private final String text; private final String type; private final long reelOwnerId; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.java index 4b951a88..e515ca2e 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemReelShareReactionInfo.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; -public class DirectItemReelShareReactionInfo { +public class DirectItemReelShareReactionInfo implements Serializable { private final String emoji; private final String intensity; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.java index 4fc2c2cc..0e618b85 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemStoryShare.java @@ -1,10 +1,11 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; import awais.instagrabber.repositories.responses.Media; -public class DirectItemStoryShare { +public class DirectItemStoryShare implements Serializable { private final String reelId; private final String reelType; private final String text; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.java index 6bc3911d..da68d633 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVideoCallEvent.java @@ -1,9 +1,10 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.List; import java.util.Objects; -public final class DirectItemVideoCallEvent { +public final class DirectItemVideoCallEvent implements Serializable { private final String action; private final String encodedServerDataInfo; private final String description; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.java index 660f74b3..2e6bf7e7 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVisualMedia.java @@ -1,12 +1,13 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.List; import java.util.Objects; import awais.instagrabber.models.enums.RavenMediaViewMode; import awais.instagrabber.repositories.responses.Media; -public class DirectItemVisualMedia { +public class DirectItemVisualMedia implements Serializable { private final long urlExpireAtSecs; private final int playbackDurationSecs; private final List seenUserIds; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.java index 2ffa86af..006fa509 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectItemVoiceMedia.java @@ -1,10 +1,11 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; import awais.instagrabber.repositories.responses.Media; -public class DirectItemVoiceMedia { +public class DirectItemVoiceMedia implements Serializable { private final Media media; private final int seenCount; private final String viewMode; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.java index 2c74598e..8f1db622 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadDirectStory.java @@ -1,9 +1,10 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.List; import java.util.Objects; -public class DirectThreadDirectStory { +public class DirectThreadDirectStory implements Serializable { private final List items; private final int unseenCount; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.java index 7fedda5f..83eda360 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/DirectThreadLastSeenAt.java @@ -1,8 +1,9 @@ package awais.instagrabber.repositories.responses.directmessages; +import java.io.Serializable; import java.util.Objects; -public class DirectThreadLastSeenAt { +public class DirectThreadLastSeenAt implements Serializable { private final String timestamp; private final String itemId; diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.java b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.java index 17f5c151..da60b4bf 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/directmessages/RavenExpiringMediaActionSummary.java @@ -2,9 +2,10 @@ package awais.instagrabber.repositories.responses.directmessages; import com.google.gson.annotations.SerializedName; +import java.io.Serializable; import java.util.Objects; -public final class RavenExpiringMediaActionSummary { +public final class RavenExpiringMediaActionSummary implements Serializable { private final ActionType type; private final long timestamp; private final int count;