11package org .schabi .newpipe ;
22
3- import android .content .Context ;
43import android .content .DialogInterface ;
54import android .content .Intent ;
65import android .content .SharedPreferences ;
@@ -41,9 +40,6 @@ public class ActionBarHandler {
4140 private static final String TAG = ActionBarHandler .class .toString ();
4241 private static final String KORE_PACKET = "org.xbmc.kore" ;
4342
44- private static ActionBarHandler handler = null ;
45-
46- private Context context = null ;
4743 private String websiteUrl = "" ;
4844 private AppCompatActivity activity ;
4945 private VideoInfo .VideoStream [] videoStreams = null ;
@@ -53,13 +49,6 @@ public class ActionBarHandler {
5349
5450 SharedPreferences defaultPreferences = null ;
5551
56- public static ActionBarHandler getHandler () {
57- if (handler == null ) {
58- handler = new ActionBarHandler ();
59- }
60- return handler ;
61- }
62-
6352 class FormatItemSelectListener implements ActionBar .OnNavigationListener {
6453 @ Override
6554 public boolean onNavigationItemSelected (int itemPosition , long itemId ) {
@@ -68,6 +57,10 @@ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
6857 }
6958 }
7059
60+ public ActionBarHandler (AppCompatActivity activity ) {
61+ this .activity = activity ;
62+ }
63+
7164 public void setupNavMenu (AppCompatActivity activity ) {
7265 this .activity = activity ;
7366 activity .getSupportActionBar ().setNavigationMode (ActionBar .NAVIGATION_MODE_LIST );
@@ -78,8 +71,8 @@ public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStre
7871 selectedStream = 0 ;
7972 String [] itemArray = new String [videoStreams .length ];
8073 String defaultResolution = defaultPreferences
81- .getString (context .getString (R .string .defaultResolutionPreference ),
82- context .getString (R .string .defaultResolutionListItem ));
74+ .getString (activity .getString (R .string .defaultResolutionPreference ),
75+ activity .getString (R .string .defaultResolutionListItem ));
8376 int defaultResolutionPos = 0 ;
8477
8578 for (int i = 0 ; i < videoStreams .length ; i ++) {
@@ -100,8 +93,8 @@ public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStre
10093
10194 // set audioStream
10295 audioStream = null ;
103- String preferedFormat = PreferenceManager .getDefaultSharedPreferences (context )
104- .getString (context .getString (R .string .defaultAudioFormatPreference ), "webm" );
96+ String preferedFormat = PreferenceManager .getDefaultSharedPreferences (activity )
97+ .getString (activity .getString (R .string .defaultAudioFormatPreference ), "webm" );
10598 if (preferedFormat .equals ("webm" )) {
10699 for (VideoInfo .AudioStream s : audioStreams ) {
107100 if (s .format == VideoInfo .I_WEBMA ) {
@@ -124,12 +117,11 @@ private void selectFormatItem(int i) {
124117 selectedStream = i ;
125118 }
126119
127- public boolean setupMenu (Menu menu , MenuInflater inflater , Context context ) {
128- this .context = context ;
120+ public boolean setupMenu (Menu menu , MenuInflater inflater ) {
129121 // CAUTION set item properties programmatically otherwise it would not be accepted by
130122 // appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
131123
132- defaultPreferences = PreferenceManager .getDefaultSharedPreferences (context );
124+ defaultPreferences = PreferenceManager .getDefaultSharedPreferences (activity );
133125
134126 inflater .inflate (R .menu .videoitem_detail , menu );
135127 MenuItem playItem = menu .findItem (R .id .menu_item_play );
@@ -142,49 +134,48 @@ public boolean setupMenu(Menu menu, MenuInflater inflater, Context context) {
142134 | MenuItemCompat .SHOW_AS_ACTION_WITH_TEXT );
143135
144136 castItem .setVisible (defaultPreferences
145- .getBoolean (context .getString (R .string .showPlayWidthKodiPreference ), false ));
137+ .getBoolean (activity .getString (R .string .showPlayWidthKodiPreference ), false ));
146138
147139 return true ;
148140 }
149141
150- public boolean onItemSelected (MenuItem item , Context context ) {
151- this .context = context ;
142+ public boolean onItemSelected (MenuItem item ) {
152143 int id = item .getItemId ();
153144 switch (id ) {
154145 case R .id .menu_item_play :
155146 playVideo ();
156- break ;
147+ return true ;
157148 case R .id .menu_item_share :
158149 if (!videoTitle .isEmpty ()) {
159150 Intent intent = new Intent ();
160151 intent .setAction (Intent .ACTION_SEND );
161152 intent .putExtra (Intent .EXTRA_TEXT , websiteUrl );
162153 intent .setType ("text/plain" );
163- context .startActivity (Intent .createChooser (intent , context .getString (R .string .shareDialogTitle )));
154+ activity .startActivity (Intent .createChooser (intent , activity .getString (R .string .shareDialogTitle )));
164155 }
165- break ;
156+ return true ;
166157 case R .id .menu_item_openInBrowser : {
167158 openInBrowser ();
168159 }
169- break ;
160+ return true ;
170161 case R .id .menu_item_download :
171162 downloadVideo ();
172- break ;
163+ return true ;
173164 case R .id .action_settings : {
174- Intent intent = new Intent (context , SettingsActivity .class );
175- context .startActivity (intent );
165+ Intent intent = new Intent (activity , SettingsActivity .class );
166+ activity .startActivity (intent );
176167 }
177168 break ;
178169 case R .id .action_play_with_kodi :
179170 playWithKodi ();
180- break ;
171+ return true ;
181172 case R .id .menu_item_play_audio :
182173 playAudio ();
183- break ;
174+ return true ;
184175 default :
185176 Log .e (TAG , "Menu Item not known" );
186177 }
187- return true ;
178+ return false ;
188179 }
189180
190181 public void setVideoInfo (String websiteUrl , String videoTitle ) {
@@ -195,8 +186,8 @@ public void setVideoInfo(String websiteUrl, String videoTitle) {
195186 public void playVideo () {
196187 // ----------- THE MAGIC MOMENT ---------------
197188 if (!videoTitle .isEmpty ()) {
198- if (PreferenceManager .getDefaultSharedPreferences (context )
199- .getBoolean (context .getString (R .string .useExternalPlayer ), false )) {
189+ if (PreferenceManager .getDefaultSharedPreferences (activity )
190+ .getBoolean (activity .getString (R .string .useExternalPlayer ), false )) {
200191
201192 // External Player
202193 Intent intent = new Intent ();
@@ -208,18 +199,18 @@ public void playVideo() {
208199 intent .putExtra (Intent .EXTRA_TITLE , videoTitle );
209200 intent .putExtra ("title" , videoTitle );
210201
211- context .startActivity (intent ); // HERE !!!
202+ activity .startActivity (intent ); // HERE !!!
212203 } catch (Exception e ) {
213204 e .printStackTrace ();
214- AlertDialog .Builder builder = new AlertDialog .Builder (context );
205+ AlertDialog .Builder builder = new AlertDialog .Builder (activity );
215206 builder .setMessage (R .string .noPlayerFound )
216207 .setPositiveButton (R .string .installStreamPlayer , new DialogInterface .OnClickListener () {
217208 @ Override
218209 public void onClick (DialogInterface dialog , int which ) {
219210 Intent intent = new Intent ();
220211 intent .setAction (Intent .ACTION_VIEW );
221- intent .setData (Uri .parse (context .getString (R .string .fdroidVLCurl )));
222- context .startActivity (intent );
212+ intent .setData (Uri .parse (activity .getString (R .string .fdroidVLCurl )));
213+ activity .startActivity (intent );
223214 }
224215 })
225216 .setNegativeButton (R .string .cancel , new DialogInterface .OnClickListener () {
@@ -232,11 +223,11 @@ public void onClick(DialogInterface dialog, int which) {
232223 }
233224 } else {
234225 // Internal Player
235- Intent intent = new Intent (context , PlayVideoActivity .class );
226+ Intent intent = new Intent (activity , PlayVideoActivity .class );
236227 intent .putExtra (PlayVideoActivity .VIDEO_TITLE , videoTitle );
237228 intent .putExtra (PlayVideoActivity .STREAM_URL , videoStreams [selectedStream ].url );
238229 intent .putExtra (PlayVideoActivity .VIDEO_URL , websiteUrl );
239- context .startActivity (intent );
230+ activity .startActivity (intent );
240231 }
241232 }
242233 // --------------------------------------------
@@ -265,7 +256,7 @@ public void openInBrowser() {
265256 intent .setAction (Intent .ACTION_VIEW );
266257 intent .setData (Uri .parse (websiteUrl ));
267258
268- context .startActivity (Intent .createChooser (intent , context .getString (R .string .chooseBrowser )));
259+ activity .startActivity (Intent .createChooser (intent , activity .getString (R .string .chooseBrowser )));
269260 }
270261 }
271262
@@ -275,18 +266,18 @@ public void playWithKodi() {
275266 Intent intent = new Intent (Intent .ACTION_VIEW );
276267 intent .setPackage (KORE_PACKET );
277268 intent .setData (Uri .parse (websiteUrl .replace ("https" , "http" )));
278- context .startActivity (intent );
269+ activity .startActivity (intent );
279270 } catch (Exception e ) {
280271 e .printStackTrace ();
281- AlertDialog .Builder builder = new AlertDialog .Builder (context );
272+ AlertDialog .Builder builder = new AlertDialog .Builder (activity );
282273 builder .setMessage (R .string .koreNotFound )
283274 .setPositiveButton (R .string .installeKore , new DialogInterface .OnClickListener () {
284275 @ Override
285276 public void onClick (DialogInterface dialog , int which ) {
286277 Intent intent = new Intent ();
287278 intent .setAction (Intent .ACTION_VIEW );
288- intent .setData (Uri .parse (context .getString (R .string .fdroidKoreUrl )));
289- context .startActivity (intent );
279+ intent .setData (Uri .parse (activity .getString (R .string .fdroidKoreUrl )));
280+ activity .startActivity (intent );
290281 }
291282 })
292283 .setNegativeButton (R .string .cancel , new DialogInterface .OnClickListener () {
@@ -308,18 +299,18 @@ public void playAudio() {
308299 VideoInfo .getMimeById (audioStream .format ));
309300 intent .putExtra (Intent .EXTRA_TITLE , videoTitle );
310301 intent .putExtra ("title" , videoTitle );
311- context .startActivity (intent ); // HERE !!!
302+ activity .startActivity (intent ); // HERE !!!
312303 } catch (Exception e ) {
313304 e .printStackTrace ();
314- AlertDialog .Builder builder = new AlertDialog .Builder (context );
305+ AlertDialog .Builder builder = new AlertDialog .Builder (activity );
315306 builder .setMessage (R .string .noPlayerFound )
316307 .setPositiveButton (R .string .installStreamPlayer , new DialogInterface .OnClickListener () {
317308 @ Override
318309 public void onClick (DialogInterface dialog , int which ) {
319310 Intent intent = new Intent ();
320311 intent .setAction (Intent .ACTION_VIEW );
321- intent .setData (Uri .parse (context .getString (R .string .fdroidVLCurl )));
322- context .startActivity (intent );
312+ intent .setData (Uri .parse (activity .getString (R .string .fdroidVLCurl )));
313+ activity .startActivity (intent );
323314 }
324315 })
325316 .setNegativeButton (R .string .cancel , new DialogInterface .OnClickListener () {
0 commit comments