@@ -81,7 +81,7 @@ private class ExtractorRunnable implements Runnable {
8181 private Handler h = new Handler ();
8282 private Class extractorClass ;
8383 private String videoUrl ;
84- public ExtractorRunnable (String videoUrl , Class extractorClass , VideoItemDetailFragment f ) {
84+ public ExtractorRunnable (String videoUrl , Class extractorClass ) {
8585 this .extractorClass = extractorClass ;
8686 this .videoUrl = videoUrl ;
8787 }
@@ -96,18 +96,21 @@ public void run() {
9696 BitmapFactory .decodeStream (
9797 new URL (videoInfo .thumbnail_url )
9898 .openConnection ()
99- .getInputStream ()), SetThumbnailRunnable .VIDEO_THUMBNAIL ));
99+ .getInputStream ()),
100+ SetThumbnailRunnable .VIDEO_THUMBNAIL ));
100101 h .post (new SetThumbnailRunnable (
101102 BitmapFactory .decodeStream (
102103 new URL (videoInfo .uploader_thumbnail_url )
103104 .openConnection ()
104- .getInputStream ()), SetThumbnailRunnable .CHANNEL_THUMBNAIL ));
105+ .getInputStream ()),
106+ SetThumbnailRunnable .CHANNEL_THUMBNAIL ));
105107 if (showNextVideoItem ) {
106108 h .post (new SetThumbnailRunnable (
107109 BitmapFactory .decodeStream (
108110 new URL (videoInfo .nextVideo .thumbnail_url )
109111 .openConnection ()
110- .getInputStream ()), SetThumbnailRunnable .NEXT_VIDEO_THUMBNAIL ));
112+ .getInputStream ()),
113+ SetThumbnailRunnable .NEXT_VIDEO_THUMBNAIL ));
111114 }
112115 }
113116 } catch (Exception e ) {
@@ -176,29 +179,28 @@ public void updateThumbnail(Bitmap thumbnail, int id) {
176179 }
177180
178181 public void updateInfo (VideoInfo info ) {
179- Activity a = getActivity ();
180182 currentVideoInfo = info ;
181183 try {
182184 VideoInfoItemViewCreator videoItemViewCreator =
183185 new VideoInfoItemViewCreator (LayoutInflater .from (getActivity ()));
184186
185- ScrollView contentMainView = (ScrollView ) a .findViewById (R .id .detailMainContent );
186- ProgressBar progressBar = (ProgressBar ) a .findViewById (R .id .detailProgressBar );
187- TextView videoTitleView = (TextView ) a .findViewById (R .id .detailVideoTitleView );
188- TextView uploaderView = (TextView ) a .findViewById (R .id .detailUploaderView );
189- TextView viewCountView = (TextView ) a .findViewById (R .id .detailViewCountView );
190- TextView thumbsUpView = (TextView ) a .findViewById (R .id .detailThumbsUpCountView );
191- TextView thumbsDownView = (TextView ) a .findViewById (R .id .detailThumbsDownCountView );
192- TextView uploadDateView = (TextView ) a .findViewById (R .id .detailUploadDateView );
193- TextView descriptionView = (TextView ) a .findViewById (R .id .detailDescriptionView );
194- ImageView thumbnailView = (ImageView ) a .findViewById (R .id .detailThumbnailView );
195- FrameLayout nextVideoFrame = (FrameLayout ) a .findViewById (R .id .detailNextVideoFrame );
187+ ScrollView contentMainView = (ScrollView ) activity .findViewById (R .id .detailMainContent );
188+ ProgressBar progressBar = (ProgressBar ) activity .findViewById (R .id .detailProgressBar );
189+ TextView videoTitleView = (TextView ) activity .findViewById (R .id .detailVideoTitleView );
190+ TextView uploaderView = (TextView ) activity .findViewById (R .id .detailUploaderView );
191+ TextView viewCountView = (TextView ) activity .findViewById (R .id .detailViewCountView );
192+ TextView thumbsUpView = (TextView ) activity .findViewById (R .id .detailThumbsUpCountView );
193+ TextView thumbsDownView = (TextView ) activity .findViewById (R .id .detailThumbsDownCountView );
194+ TextView uploadDateView = (TextView ) activity .findViewById (R .id .detailUploadDateView );
195+ TextView descriptionView = (TextView ) activity .findViewById (R .id .detailDescriptionView );
196+ ImageView thumbnailView = (ImageView ) activity .findViewById (R .id .detailThumbnailView );
197+ FrameLayout nextVideoFrame = (FrameLayout ) activity .findViewById (R .id .detailNextVideoFrame );
196198 RelativeLayout nextVideoRootFrame =
197- (RelativeLayout ) a .findViewById (R .id .detailNextVideoRootLayout );
199+ (RelativeLayout ) activity .findViewById (R .id .detailNextVideoRootLayout );
198200 View nextVideoView = videoItemViewCreator
199201 .getViewByVideoInfoItem (null , nextVideoFrame , info .nextVideo );
200202 nextVideoFrame .addView (nextVideoView );
201- Button nextVideoButton = (Button ) a .findViewById (R .id .detailNextVideoButton );
203+ Button nextVideoButton = (Button ) activity .findViewById (R .id .detailNextVideoButton );
202204
203205 contentMainView .setVisibility (View .VISIBLE );
204206 progressBar .setVisibility (View .GONE );
@@ -210,10 +212,12 @@ public void updateInfo(VideoInfo info) {
210212 case VideoInfo .VIDEO_AVAILABLE : {
211213 videoTitleView .setText (info .title );
212214 uploaderView .setText (info .uploader );
213- viewCountView .setText (info .view_count + " " + a .getString (R .string .viewSufix ));
215+ viewCountView .setText (info .view_count
216+ + " " + activity .getString (R .string .viewSufix ));
214217 thumbsUpView .setText (info .like_count );
215218 thumbsDownView .setText (info .dislike_count );
216- uploadDateView .setText (a .getString (R .string .uploadDatePrefix ) + " " + info .upload_date );
219+ uploadDateView .setText (
220+ activity .getString (R .string .uploadDatePrefix ) + " " + info .upload_date );
217221 descriptionView .setText (Html .fromHtml (info .description ));
218222 descriptionView .setMovementMethod (LinkMovementMethod .getInstance ());
219223
@@ -236,20 +240,25 @@ public void updateInfo(VideoInfo info) {
236240 nextVideoButton .setOnClickListener (new View .OnClickListener () {
237241 @ Override
238242 public void onClick (View v ) {
239- Intent detailIntent = new Intent (getActivity (), VideoItemDetailActivity .class );
240- detailIntent .putExtra (VideoItemDetailFragment .ARG_ITEM_ID , currentVideoInfo .nextVideo .id );
241- detailIntent .putExtra (VideoItemDetailFragment .VIDEO_URL , currentVideoInfo .nextVideo .webpage_url );
243+ Intent detailIntent =
244+ new Intent (getActivity (), VideoItemDetailActivity .class );
245+ detailIntent .putExtra (
246+ VideoItemDetailFragment .ARG_ITEM_ID , currentVideoInfo .nextVideo .id );
247+ detailIntent .putExtra (
248+ VideoItemDetailFragment .VIDEO_URL , currentVideoInfo .nextVideo .webpage_url );
242249 //todo: make id dynamic the following line is crap
243250 detailIntent .putExtra (VideoItemDetailFragment .STREAMING_SERVICE , 0 );
244251 startActivity (detailIntent );
245252 }
246253 });
247254 break ;
248255 case VideoInfo .VIDEO_UNAVAILABLE_GEMA :
249- thumbnailView .setImageBitmap (BitmapFactory .decodeResource (getResources (), R .drawable .gruese_die_gema_unangebracht ));
256+ thumbnailView .setImageBitmap (BitmapFactory .decodeResource (
257+ getResources (), R .drawable .gruese_die_gema_unangebracht ));
250258 break ;
251259 case VideoInfo .VIDEO_UNAVAILABLE :
252- thumbnailView .setImageBitmap (BitmapFactory .decodeResource (getResources (), R .drawable .not_available_monkey ));
260+ thumbnailView .setImageBitmap (BitmapFactory .decodeResource (
261+ getResources (), R .drawable .not_available_monkey ));
253262 break ;
254263 default :
255264 Log .e (TAG , "Video Available Status not known." );
@@ -304,15 +313,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
304313 @ Override
305314 public void onActivityCreated (Bundle savedInstanceBundle ) {
306315 super .onActivityCreated (savedInstanceBundle );
307- FloatingActionButton playVideoButton = (FloatingActionButton ) getActivity ().findViewById (R .id .playVideoButton );
316+ FloatingActionButton playVideoButton =
317+ (FloatingActionButton ) getActivity ().findViewById (R .id .playVideoButton );
308318
319+ // Sometimes when this fragment is not visible it still gets initiated
320+ // then we must not try to access objects of this fragment.
321+ // Otherwise the applications would crash.
309322 if (playVideoButton != null ) {
310-
311323 try {
312324 StreamingService streamingService = ServiceList .getService (
313325 getArguments ().getInt (STREAMING_SERVICE ));
314326 extractorThread = new Thread (new ExtractorRunnable (
315- getArguments ().getString (VIDEO_URL ), streamingService .getExtractorClass (), this ));
327+ getArguments ().getString (VIDEO_URL ), streamingService .getExtractorClass ()));
316328 autoPlayEnabled = getArguments ().getBoolean (AUTO_PLAY );
317329 extractorThread .start ();
318330 } catch (Exception e ) {
@@ -321,13 +333,15 @@ public void onActivityCreated(Bundle savedInstanceBundle) {
321333
322334 if (PreferenceManager .getDefaultSharedPreferences (getActivity ())
323335 .getBoolean (getString (R .string .leftHandLayout ), false ) && checkIfLandscape ()) {
324- RelativeLayout .LayoutParams oldLayout = (RelativeLayout .LayoutParams ) playVideoButton .getLayoutParams ();
336+ RelativeLayout .LayoutParams oldLayout =
337+ (RelativeLayout .LayoutParams ) playVideoButton .getLayoutParams ();
325338 RelativeLayout .LayoutParams layoutParams = new RelativeLayout .LayoutParams (
326339 RelativeLayout .LayoutParams .WRAP_CONTENT ,
327340 RelativeLayout .LayoutParams .WRAP_CONTENT );
328341 layoutParams .addRule (RelativeLayout .ALIGN_PARENT_BOTTOM );
329342 layoutParams .addRule (RelativeLayout .ALIGN_PARENT_LEFT );
330- layoutParams .setMargins (oldLayout .leftMargin , oldLayout .topMargin , oldLayout .rightMargin , oldLayout .bottomMargin );
343+ layoutParams .setMargins (oldLayout .leftMargin , oldLayout .topMargin ,
344+ oldLayout .rightMargin , oldLayout .bottomMargin );
331345 playVideoButton .setLayoutParams (layoutParams );
332346 }
333347
@@ -337,6 +351,16 @@ public void onClick(View v) {
337351 actionBarHandler .playVideo ();
338352 }
339353 });
354+
355+ Button similarVideosButton = (Button ) activity .findViewById (R .id .detailShowSimilarButton );
356+ similarVideosButton .setOnClickListener (new View .OnClickListener () {
357+ @ Override
358+ public void onClick (View v ) {
359+ Intent intent = new Intent (activity , VideoItemListActivity .class );
360+ intent .putExtra (VideoItemListActivity .VIDEO_INFO_ITEMS , currentVideoInfo .relatedVideos );
361+ activity .startActivity (intent );
362+ }
363+ });
340364 }
341365 }
342366
0 commit comments