66
77import android .content .Context ;
88import android .util .Log ;
9+ import android .util .Pair ;
910import android .view .ContextThemeWrapper ;
1011import android .view .LayoutInflater ;
1112import android .view .ViewGroup ;
2829import org .schabi .newpipe .util .ThemeHelper ;
2930
3031import java .io .IOException ;
31- import java .util .Collections ;
32- import java .util .LinkedHashMap ;
33- import java .util .Map ;
32+ import java .util .List ;
3433import java .util .function .Supplier ;
3534
3635/**
@@ -43,50 +42,34 @@ public final class VideoDetailPlayerCrasher {
4342 // https://stackoverflow.com/a/54744028
4443 private static final String TAG = "VideoDetPlayerCrasher" ;
4544
46- private static final Map <String , Supplier <ExoPlaybackException >> AVAILABLE_EXCEPTION_TYPES =
47- getExceptionTypes ();
45+ private static final String DEFAULT_MSG = "Dummy" ;
46+
47+ private static final List <Pair <String , Supplier <ExoPlaybackException >>>
48+ AVAILABLE_EXCEPTION_TYPES = List .of (
49+ new Pair <>("Source" , () -> ExoPlaybackException .createForSource (
50+ new IOException (DEFAULT_MSG ),
51+ ERROR_CODE_BEHIND_LIVE_WINDOW
52+ )),
53+ new Pair <>("Renderer" , () -> ExoPlaybackException .createForRenderer (
54+ new Exception (DEFAULT_MSG ),
55+ "Dummy renderer" ,
56+ 0 ,
57+ null ,
58+ C .FORMAT_HANDLED ,
59+ /*isRecoverable=*/ false ,
60+ ERROR_CODE_DECODING_FAILED
61+ )),
62+ new Pair <>("Unexpected" , () -> ExoPlaybackException .createForUnexpected (
63+ new RuntimeException (DEFAULT_MSG ),
64+ ERROR_CODE_UNSPECIFIED
65+ )),
66+ new Pair <>("Remote" , () -> ExoPlaybackException .createForRemote (DEFAULT_MSG ))
67+ );
4868
4969 private VideoDetailPlayerCrasher () {
5070 // No impls
5171 }
5272
53- private static Map <String , Supplier <ExoPlaybackException >> getExceptionTypes () {
54- final String defaultMsg = "Dummy" ;
55- final Map <String , Supplier <ExoPlaybackException >> exceptionTypes = new LinkedHashMap <>();
56- exceptionTypes .put (
57- "Source" ,
58- () -> ExoPlaybackException .createForSource (
59- new IOException (defaultMsg ),
60- ERROR_CODE_BEHIND_LIVE_WINDOW
61- )
62- );
63- exceptionTypes .put (
64- "Renderer" ,
65- () -> ExoPlaybackException .createForRenderer (
66- new Exception (defaultMsg ),
67- "Dummy renderer" ,
68- 0 ,
69- null ,
70- C .FORMAT_HANDLED ,
71- /*isRecoverable=*/ false ,
72- ERROR_CODE_DECODING_FAILED
73- )
74- );
75- exceptionTypes .put (
76- "Unexpected" ,
77- () -> ExoPlaybackException .createForUnexpected (
78- new RuntimeException (defaultMsg ),
79- ERROR_CODE_UNSPECIFIED
80- )
81- );
82- exceptionTypes .put (
83- "Remote" ,
84- () -> ExoPlaybackException .createForRemote (defaultMsg )
85- );
86-
87- return Collections .unmodifiableMap (exceptionTypes );
88- }
89-
9073 private static Context getThemeWrapperContext (final Context context ) {
9174 return new ContextThemeWrapper (
9275 context ,
@@ -121,10 +104,9 @@ public static void onCrashThePlayer(
121104 .setNegativeButton (R .string .cancel , null )
122105 .create ();
123106
124- for (final Map .Entry <String , Supplier <ExoPlaybackException >> entry
125- : AVAILABLE_EXCEPTION_TYPES .entrySet ()) {
107+ for (final Pair <String , Supplier <ExoPlaybackException >> entry : AVAILABLE_EXCEPTION_TYPES ) {
126108 final RadioButton radioButton = ListRadioIconItemBinding .inflate (inflater ).getRoot ();
127- radioButton .setText (entry .getKey () );
109+ radioButton .setText (entry .first );
128110 radioButton .setChecked (false );
129111 radioButton .setLayoutParams (
130112 new RadioGroup .LayoutParams (
@@ -133,7 +115,7 @@ public static void onCrashThePlayer(
133115 )
134116 );
135117 radioButton .setOnClickListener (v -> {
136- tryCrashPlayerWith (player , entry .getValue () .get ());
118+ tryCrashPlayerWith (player , entry .second .get ());
137119 alertDialog .cancel ();
138120 });
139121 binding .list .addView (radioButton );
0 commit comments