17
17
import android .support .v17 .leanback .widget .OnActionClickedListener ;
18
18
import android .text .TextUtils ;
19
19
import android .util .DisplayMetrics ;
20
- import android .util .Log ;
21
- import android .widget .Toast ;
22
20
23
21
import com .google .gson .Gson ;
24
22
import com .google .gson .reflect .TypeToken ;
@@ -46,7 +44,7 @@ public class VideoDetailsFragment extends DetailsFragment {
46
44
47
45
private static final int ACTION_WATCH = 1 ;
48
46
49
- private Movie selectedMovie ;
47
+ private Movie mSelectedMovie ;
50
48
51
49
private Target mBackgroundTarget ;
52
50
private DisplayMetrics mMetrics ;
@@ -55,10 +53,10 @@ public class VideoDetailsFragment extends DetailsFragment {
55
53
public void onCreate (Bundle savedInstanceState ) {
56
54
super .onCreate (savedInstanceState );
57
55
58
- selectedMovie = (Movie ) getActivity ().getIntent ().getSerializableExtra ( EXTRA_MOVIE );
56
+ mSelectedMovie = (Movie ) getActivity ().getIntent ().getSerializableExtra ( EXTRA_MOVIE );
59
57
60
58
initBackground ();
61
- new DetailRowBuilderTask ().execute ( selectedMovie );
59
+ new DetailRowBuilderTask ().execute ( mSelectedMovie );
62
60
63
61
}
64
62
@@ -70,9 +68,9 @@ private void initBackground() {
70
68
mMetrics = new DisplayMetrics ();
71
69
getActivity ().getWindowManager ().getDefaultDisplay ().getMetrics (mMetrics );
72
70
73
- if ( selectedMovie != null && !TextUtils .isEmpty ( selectedMovie .getBackgroundImageUrl () ) ) {
71
+ if ( mSelectedMovie != null && !TextUtils .isEmpty ( mSelectedMovie .getBackgroundImageUrl () ) ) {
74
72
try {
75
- updateBackground (new URI (selectedMovie .getBackgroundImageUrl ()));
73
+ updateBackground (new URI (mSelectedMovie .getBackgroundImageUrl ()));
76
74
} catch (URISyntaxException e ) { }
77
75
}
78
76
}
@@ -95,20 +93,19 @@ protected void updateBackground(URI uri) {
95
93
96
94
private class DetailRowBuilderTask extends AsyncTask <Movie , Integer , DetailsOverviewRow > {
97
95
@ Override
98
- protected DetailsOverviewRow doInBackground (Movie ... movies ) {
99
- Log .e ( "VideoDetailsFragment" , "doInBackground" );
100
- selectedMovie = movies [0 ];
96
+ protected DetailsOverviewRow doInBackground ( Movie ... movies ) {
97
+ mSelectedMovie = movies [0 ];
101
98
DetailsOverviewRow row = null ;
102
99
try {
103
- row = new DetailsOverviewRow (selectedMovie );
100
+ row = new DetailsOverviewRow ( mSelectedMovie );
104
101
Bitmap poster = Picasso .with ( getActivity () )
105
- .load ( selectedMovie .getCardImageUrl () )
106
- .resize (Utils .dpToPx ( getActivity ().getResources ().getInteger ( R .integer .detail_thumbnail_square_size ), getActivity ().getApplicationContext ()),
107
- Utils .dpToPx ( getActivity ().getResources ().getInteger ( R .integer .detail_thumbnail_square_size ), getActivity ().getApplicationContext ()) )
102
+ .load ( mSelectedMovie .getCardImageUrl () )
103
+ .resize (Utils .dpToPx ( getActivity ().getResources ().getInteger ( R .integer .detail_thumbnail_square_size ), getActivity ().getApplicationContext () ),
104
+ Utils .dpToPx ( getActivity ().getResources ().getInteger ( R .integer .detail_thumbnail_square_size ), getActivity ().getApplicationContext () ) )
108
105
.centerCrop ()
109
106
.get ();
110
- row .setImageBitmap (getActivity (), poster );
111
- } catch (IOException e ) {
107
+ row .setImageBitmap ( getActivity (), poster );
108
+ } catch ( IOException e ) {
112
109
getActivity ().finish ();
113
110
return null ;
114
111
} catch ( NullPointerException e ) {
@@ -123,43 +120,37 @@ protected DetailsOverviewRow doInBackground(Movie... movies) {
123
120
}
124
121
125
122
@ Override
126
- protected void onPostExecute (DetailsOverviewRow detailRow ) {
127
- Log .e ( "VideoDetailsFragment" , "onPostExecute" );
123
+ protected void onPostExecute ( DetailsOverviewRow detailRow ) {
128
124
if ( detailRow == null )
129
125
return ;
130
126
131
- Log .e ( "VideoDetailsFragment" , "detailRow != null" );
132
-
133
127
ClassPresenterSelector ps = new ClassPresenterSelector ();
134
128
DetailsOverviewRowPresenter dorPresenter =
135
- new DetailsOverviewRowPresenter (new DetailsDescriptionPresenter ());
129
+ new DetailsOverviewRowPresenter ( new DetailsDescriptionPresenter () );
136
130
// set detail background and style
137
131
dorPresenter .setBackgroundColor ( getResources ().getColor ( R .color .detail_background ) );
138
132
dorPresenter .setStyleLarge ( true );
139
133
dorPresenter .setOnActionClickedListener ( new OnActionClickedListener () {
140
134
@ Override
141
- public void onActionClicked (Action action ) {
135
+ public void onActionClicked ( Action action ) {
142
136
if (action .getId () == ACTION_WATCH ) {
143
137
Intent intent = new Intent ( getActivity (), PlayerActivity .class );
144
- intent .putExtra ( EXTRA_MOVIE , selectedMovie );
145
- intent .putExtra ( EXTRA_SHOULD_AUTO_START , true );
146
- startActivity (intent );
147
- }
148
- else {
149
- Toast .makeText (getActivity (), action .toString (), Toast .LENGTH_SHORT ).show ();
138
+ intent .putExtra ( EXTRA_MOVIE , mSelectedMovie );
139
+ intent .putExtra ( EXTRA_SHOULD_AUTO_START , true );
140
+ startActivity ( intent );
150
141
}
151
142
}
152
143
});
153
144
154
- ps .addClassPresenter (DetailsOverviewRow .class , dorPresenter );
155
- ps .addClassPresenter (ListRow .class ,
156
- new ListRowPresenter ());
145
+ ps .addClassPresenter ( DetailsOverviewRow .class , dorPresenter );
146
+ ps .addClassPresenter ( ListRow .class ,
147
+ new ListRowPresenter () );
157
148
158
149
159
- ArrayObjectAdapter adapter = new ArrayObjectAdapter (ps );
160
- adapter .add (detailRow );
150
+ ArrayObjectAdapter adapter = new ArrayObjectAdapter ( ps );
151
+ adapter .add ( detailRow );
161
152
loadRelatedMedia ( adapter );
162
- setAdapter (adapter );
153
+ setAdapter ( adapter );
163
154
}
164
155
165
156
private void loadRelatedMedia ( ArrayObjectAdapter adapter ) {
@@ -170,7 +161,7 @@ private void loadRelatedMedia( ArrayObjectAdapter adapter ) {
170
161
List <Movie > movies = gson .fromJson ( json , collection );
171
162
List <Movie > related = new ArrayList <Movie >();
172
163
for ( Movie movie : movies ) {
173
- if ( movie .getCategory ().equals ( selectedMovie .getCategory () ) ) {
164
+ if ( movie .getCategory ().equals ( mSelectedMovie .getCategory () ) ) {
174
165
related .add ( movie );
175
166
}
176
167
}
0 commit comments