From dc63d054dcf21f7b69e0775c14a5f1b69af90d48 Mon Sep 17 00:00:00 2001 From: Grishka Date: Sat, 12 Feb 2022 15:36:43 +0300 Subject: [PATCH] Show and play videos --- .../android/model/Attachment.java | 1 - .../displayitems/GifVStatusDisplayItem.java | 6 +-- .../ui/displayitems/StatusDisplayItem.java | 6 ++- .../displayitems/VideoStatusDisplayItem.java | 41 +++++++++++++++++++ .../android/ui/photoviewer/PhotoViewer.java | 5 ++- .../main/res/layout/display_item_video.xml | 21 ++++++++++ 6 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/VideoStatusDisplayItem.java create mode 100644 mastodon/src/main/res/layout/display_item_video.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java b/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java index 131f8742..ff64abf5 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java @@ -20,7 +20,6 @@ public class Attachment extends BaseModel{ public Type type; @RequiredField public String url; - @RequiredField public String previewUrl; public String remoteUrl; public String description; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GifVStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GifVStatusDisplayItem.java index 26bcb97b..c2aa8edb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GifVStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/GifVStatusDisplayItem.java @@ -14,9 +14,9 @@ import org.joinmastodon.android.model.Status; import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; public class GifVStatusDisplayItem extends ImageStatusDisplayItem{ - public GifVStatusDisplayItem(String parentID, Status status, Attachment photo, BaseStatusListFragment parentFragment, int index, int totalPhotos){ - super(parentID, parentFragment, photo, status, index, totalPhotos); - request=new UrlImageLoaderRequest(photo.previewUrl, 1000, 1000); + public GifVStatusDisplayItem(String parentID, Status status, Attachment attachment, BaseStatusListFragment parentFragment, int index, int totalPhotos){ + super(parentID, parentFragment, attachment, status, index, totalPhotos); + request=new UrlImageLoaderRequest(attachment.previewUrl, 1000, 1000); } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 8d5dc757..da7ad97f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -48,6 +48,7 @@ public abstract class StatusDisplayItem{ case TEXT -> new TextStatusDisplayItem.Holder(activity, parent); case PHOTO -> new PhotoStatusDisplayItem.Holder(activity, parent); case GIFV -> new GifVStatusDisplayItem.Holder(activity, parent); + case VIDEO -> new VideoStatusDisplayItem.Holder(activity, parent); case FOOTER -> new FooterStatusDisplayItem.Holder(activity, parent); default -> throw new UnsupportedOperationException(); }; @@ -69,7 +70,7 @@ public abstract class StatusDisplayItem{ int photoIndex=0; int totalPhotos=0; for(Attachment attachment:statusForContent.mediaAttachments){ - if(attachment.type==Attachment.Type.IMAGE || attachment.type==Attachment.Type.GIFV){ + if(attachment.type==Attachment.Type.IMAGE || attachment.type==Attachment.Type.GIFV || attachment.type==Attachment.Type.VIDEO){ totalPhotos++; } } @@ -80,6 +81,9 @@ public abstract class StatusDisplayItem{ }else if(attachment.type==Attachment.Type.GIFV){ items.add(new GifVStatusDisplayItem(parentID, status, attachment, fragment, photoIndex, totalPhotos)); photoIndex++; + }else if(attachment.type==Attachment.Type.VIDEO){ + items.add(new VideoStatusDisplayItem(parentID, status, attachment, fragment, photoIndex, totalPhotos)); + photoIndex++; } } items.add(new FooterStatusDisplayItem(parentID, fragment, statusForContent, accountID)); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/VideoStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/VideoStatusDisplayItem.java new file mode 100644 index 00000000..86dd906a --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/VideoStatusDisplayItem.java @@ -0,0 +1,41 @@ +package org.joinmastodon.android.ui.displayitems; + +import android.app.Activity; +import android.graphics.Outline; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewOutlineProvider; + +import org.joinmastodon.android.R; +import org.joinmastodon.android.fragments.BaseStatusListFragment; +import org.joinmastodon.android.model.Attachment; +import org.joinmastodon.android.model.Status; + +import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; + +public class VideoStatusDisplayItem extends ImageStatusDisplayItem{ + public VideoStatusDisplayItem(String parentID, Status status, Attachment attachment, BaseStatusListFragment parentFragment, int index, int totalPhotos){ + super(parentID, parentFragment, attachment, status, index, totalPhotos); + request=new UrlImageLoaderRequest(attachment.previewUrl, 1000, 1000); + } + + @Override + public Type getType(){ + return Type.VIDEO; + } + + public static class Holder extends ImageStatusDisplayItem.Holder{ + + public Holder(Activity activity, ViewGroup parent){ + super(activity, R.layout.display_item_video, parent); + View play=findViewById(R.id.play_button); + play.setOutlineProvider(new ViewOutlineProvider(){ + @Override + public void getOutline(View view, Outline outline){ + outline.setOval(0, 0, view.getWidth(), view.getHeight()); + outline.setAlpha(.99f); // fixes shadow rendering + } + }); + } + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java index 073461de..41a3b507 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java @@ -26,6 +26,7 @@ import org.joinmastodon.android.model.Attachment; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -52,7 +53,7 @@ public class PhotoViewer implements ZoomPanView.Listener{ public PhotoViewer(Activity activity, List attachments, int index, Listener listener){ this.activity=activity; - this.attachments=attachments; + this.attachments=attachments.stream().filter(a->a.type==Attachment.Type.IMAGE || a.type==Attachment.Type.GIFV || a.type==Attachment.Type.VIDEO).collect(Collectors.toList()); currentIndex=index; this.listener=listener; @@ -242,7 +243,7 @@ public class PhotoViewer implements ZoomPanView.Listener{ Attachment att=attachments.get(position); return switch(att.type){ case IMAGE -> 0; - case GIFV -> 1; + case GIFV, VIDEO -> 1; default -> throw new IllegalStateException("Unexpected value: "+att.type); }; } diff --git a/mastodon/src/main/res/layout/display_item_video.xml b/mastodon/src/main/res/layout/display_item_video.xml new file mode 100644 index 00000000..13937f21 --- /dev/null +++ b/mastodon/src/main/res/layout/display_item_video.xml @@ -0,0 +1,21 @@ + + + + + + + + \ No newline at end of file