11package org .schabi .newpipe ;
22
33import android .app .Activity ;
4+ import android .content .Intent ;
45import android .graphics .Bitmap ;
56import android .graphics .BitmapFactory ;
67import android .os .Bundle ;
1516import android .view .LayoutInflater ;
1617import android .view .View ;
1718import android .view .ViewGroup ;
19+ import android .widget .Button ;
20+ import android .widget .FrameLayout ;
1821import android .widget .ImageView ;
1922import android .widget .ProgressBar ;
2023import android .widget .RelativeLayout ;
24+ import android .widget .ScrollView ;
2125import android .widget .TextView ;
2226
2327import java .net .URL ;
@@ -57,6 +61,7 @@ public class VideoItemDetailFragment extends Fragment {
5761
5862 private boolean autoPlayEnabled = false ;
5963 private Thread extractorThread = null ;
64+ private VideoInfo currentVideoInfo = null ;
6065
6166 private class ExtractorRunnable implements Runnable {
6267 private Handler h = new Handler ();
@@ -83,6 +88,11 @@ public void run() {
8388 new URL (videoInfo .uploader_thumbnail_url )
8489 .openConnection ()
8590 .getInputStream ()), SetThumbnailRunnable .CHANNEL_THUMBNAIL ));
91+ h .post (new SetThumbnailRunnable (
92+ BitmapFactory .decodeStream (
93+ new URL (videoInfo .nextVideo .thumbnail_url )
94+ .openConnection ()
95+ .getInputStream ()), SetThumbnailRunnable .NEXT_VIDEO_THUMBNAIL ));
8696 }
8797 } catch (Exception e ) {
8898 e .printStackTrace ();
@@ -103,8 +113,9 @@ public void run() {
103113 }
104114
105115 private class SetThumbnailRunnable implements Runnable {
106- public static final int CHANNEL_THUMBNAIL = 2 ;
107116 public static final int VIDEO_THUMBNAIL = 1 ;
117+ public static final int CHANNEL_THUMBNAIL = 2 ;
118+ public static final int NEXT_VIDEO_THUMBNAIL = 3 ;
108119 private Bitmap thumbnail ;
109120 private int thumbnailId ;
110121 public SetThumbnailRunnable (Bitmap thumbnail , int id ) {
@@ -123,19 +134,25 @@ public void updateThumbnail(Bitmap thumbnail, int id) {
123134 try {
124135 switch (id ) {
125136 case SetThumbnailRunnable .VIDEO_THUMBNAIL :
126-
127137 thumbnailView = (ImageView ) a .findViewById (R .id .detailThumbnailView );
128138 break ;
129139 case SetThumbnailRunnable .CHANNEL_THUMBNAIL :
130140 thumbnailView = (ImageView ) a .findViewById (R .id .detailUploaderThumbnailView );
131141 break ;
142+ case SetThumbnailRunnable .NEXT_VIDEO_THUMBNAIL :
143+ FrameLayout nextVideoFrame = (FrameLayout ) a .findViewById (R .id .detailNextVideoFrame );
144+ thumbnailView = (ImageView ) nextVideoFrame .findViewById (R .id .itemThumbnailView );
145+ currentVideoInfo .nextVideo .thumbnail = thumbnail ;
146+ break ;
132147 default :
133148 Log .d (TAG , "Error: Thumbnail id not known" );
134149 return ;
135150 }
151+
136152 if (thumbnailView != null ) {
137153 thumbnailView .setImageBitmap (thumbnail );
138154 }
155+
139156 } catch (java .lang .NullPointerException e ) {
140157 // No god programm design i know. :/
141158 Log .w (TAG , "updateThumbnail(): Fragment closed before thread ended work" );
@@ -144,7 +161,12 @@ public void updateThumbnail(Bitmap thumbnail, int id) {
144161
145162 public void updateInfo (VideoInfo info ) {
146163 Activity a = getActivity ();
164+ currentVideoInfo = info ;
147165 try {
166+ VideoInfoItemViewCreator videoItemViewCreator =
167+ new VideoInfoItemViewCreator (LayoutInflater .from (getActivity ()));
168+
169+ ScrollView contentMainView = (ScrollView ) a .findViewById (R .id .detailMainContent );
148170 ProgressBar progressBar = (ProgressBar ) a .findViewById (R .id .detailProgressBar );
149171 TextView videoTitleView = (TextView ) a .findViewById (R .id .detailVideoTitleView );
150172 TextView uploaderView = (TextView ) a .findViewById (R .id .detailUploaderView );
@@ -154,28 +176,14 @@ public void updateInfo(VideoInfo info) {
154176 TextView uploadDateView = (TextView ) a .findViewById (R .id .detailUploadDateView );
155177 TextView descriptionView = (TextView ) a .findViewById (R .id .detailDescriptionView );
156178 ImageView thumbnailView = (ImageView ) a .findViewById (R .id .detailThumbnailView );
157- ImageView uploaderThumbnailView = (ImageView ) a .findViewById (R .id .detailUploaderThumbnailView );
158- ImageView thumbsUpPic = ( ImageView ) a . findViewById ( R . id . detailThumbsUpImgView );
159- ImageView thumbsDownPic = ( ImageView ) a . findViewById ( R . id . detailThumbsDownImgView );
160- View textSeperationLine = a . findViewById ( R . id . textSeperationLine );
161-
179+ FrameLayout nextVideoFrame = (FrameLayout ) a .findViewById (R .id .detailNextVideoFrame );
180+ View nextVideoView = videoItemViewCreator
181+ . getViewByVideoInfoItem ( null , nextVideoFrame , info . nextVideo );
182+ nextVideoFrame . addView ( nextVideoView );
183+ Button nextVideoButton = ( Button ) a . findViewById ( R . id . detailNextVideoButton );
162184
163- if (textSeperationLine != null ) {
164- textSeperationLine .setVisibility (View .VISIBLE );
165- }
185+ contentMainView .setVisibility (View .VISIBLE );
166186 progressBar .setVisibility (View .GONE );
167- videoTitleView .setVisibility (View .VISIBLE );
168- uploaderView .setVisibility (View .VISIBLE );
169- uploadDateView .setVisibility (View .VISIBLE );
170- viewCountView .setVisibility (View .VISIBLE );
171- thumbsUpView .setVisibility (View .VISIBLE );
172- thumbsDownView .setVisibility (View .VISIBLE );
173- uploadDateView .setVisibility (View .VISIBLE );
174- descriptionView .setVisibility (View .VISIBLE );
175- thumbnailView .setVisibility (View .VISIBLE );
176- uploaderThumbnailView .setVisibility (View .VISIBLE );
177- thumbsUpPic .setVisibility (View .VISIBLE );
178- thumbsDownPic .setVisibility (View .VISIBLE );
179187
180188 switch (info .videoAvailableStatus ) {
181189 case VideoInfo .VIDEO_AVAILABLE : {
@@ -203,6 +211,18 @@ public void updateInfo(VideoInfo info) {
203211 }
204212 ActionBarHandler .getHandler ().setStreams (streamList , info .audioStreams );
205213 }
214+
215+ nextVideoButton .setOnClickListener (new View .OnClickListener () {
216+ @ Override
217+ public void onClick (View v ) {
218+ Intent detailIntent = new Intent (getActivity (), VideoItemDetailActivity .class );
219+ detailIntent .putExtra (VideoItemDetailFragment .ARG_ITEM_ID , currentVideoInfo .nextVideo .id );
220+ detailIntent .putExtra (VideoItemDetailFragment .VIDEO_URL , currentVideoInfo .nextVideo .webpage_url );
221+ //todo: make id dynamic the following line is crap
222+ detailIntent .putExtra (VideoItemDetailFragment .STREAMING_SERVICE , 0 );
223+ startActivity (detailIntent );
224+ }
225+ });
206226 break ;
207227 case VideoInfo .VIDEO_UNAVAILABLE_GEMA :
208228 thumbnailView .setImageBitmap (BitmapFactory .decodeResource (getResources (), R .drawable .gruese_die_gema_unangebracht ));
0 commit comments