From 2c11bd188998715aefa6f56bcc5c4c190f19ffaa Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Thu, 19 Nov 2015 14:40:35 +0000 Subject: [PATCH] fixed Bundle casting bug incurred during related videosdisplay --- app/src/main/java/org/schabi/newpipe/VideoInfo.java | 4 +++- .../java/org/schabi/newpipe/VideoItemDetailFragment.java | 8 +++++++- .../schabi/newpipe/services/youtube/YoutubeExtractor.java | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/VideoInfo.java index bfb90a292..5b8321a61 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfo.java @@ -2,6 +2,8 @@ package org.schabi.newpipe; import android.graphics.Bitmap; +import java.util.List; + /** * Created by Christian Schabesberger on 26.08.15. * @@ -41,7 +43,7 @@ public class VideoInfo extends AbstractVideoInfo { public int dislike_count = -1; public String average_rating = ""; public VideoPreviewInfo nextVideo = null; - public VideoPreviewInfo[] relatedVideos = null; + public List relatedVideos = null; public int startPosition = -1;//in seconds. some metadata is not passed using a VideoInfo object! public static final int VIDEO_AVAILABLE = 0x00; diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 351692f2a..81636d825 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -32,6 +32,7 @@ import android.view.MenuItem; import java.net.URL; import java.text.DateFormat; import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Locale; @@ -394,7 +395,12 @@ public class VideoItemDetailFragment extends Fragment { @Override public void onClick(View v) { Intent intent = new Intent(activity, VideoItemListActivity.class); - intent.putExtra(VideoItemListActivity.VIDEO_INFO_ITEMS, currentVideoInfo.relatedVideos); + //todo: find more elegant way to do this - converting from List to ArrayList sucks + ArrayList toParcel = new ArrayList<>(currentVideoInfo.relatedVideos); + //why oh why does the parcelable array put method have to be so damn specific + // about the class of its argument? + //why not a List? + intent.putParcelableArrayListExtra(VideoItemListActivity.VIDEO_INFO_ITEMS, toParcel); activity.startActivity(intent); } }); diff --git a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeExtractor.java b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeExtractor.java index c3ebe3a40..cb996d2ef 100644 --- a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeExtractor.java @@ -421,7 +421,9 @@ public class YoutubeExtractor extends Extractor { relatedVideos.add(extractVideoPreviewInfo(li)); } } - videoInfo.relatedVideos = relatedVideos.toArray(new VideoPreviewInfo[relatedVideos.size()]); + //todo: replace conversion + videoInfo.relatedVideos = relatedVideos; + //videoInfo.relatedVideos = relatedVideos.toArray(new VideoPreviewInfo[relatedVideos.size()]); return videoInfo; }