@@ -59,17 +59,20 @@ private static void loadCustomSpeeds() {
59
59
if (speedStrings .length == 0 ) {
60
60
throw new IllegalArgumentException ();
61
61
}
62
+
62
63
customPlaybackSpeeds = new float [speedStrings .length ];
63
64
for (int i = 0 , length = speedStrings .length ; i < length ; i ++) {
64
65
final float speed = Float .parseFloat (speedStrings [i ]);
65
66
if (speed <= 0 || arrayContains (customPlaybackSpeeds , speed )) {
66
67
throw new IllegalArgumentException ();
67
68
}
69
+
68
70
if (speed >= MAXIMUM_PLAYBACK_SPEED ) {
69
71
resetCustomSpeeds (str ("revanced_custom_playback_speeds_invalid" , MAXIMUM_PLAYBACK_SPEED ));
70
72
loadCustomSpeeds ();
71
73
return ;
72
74
}
75
+
73
76
customPlaybackSpeeds [i ] = speed ;
74
77
}
75
78
} catch (Exception ex ) {
@@ -89,10 +92,12 @@ private static boolean arrayContains(float[] array, float value) {
89
92
/**
90
93
* Initialize a settings preference list with the available playback speeds.
91
94
*/
95
+ @ SuppressWarnings ("deprecation" )
92
96
public static void initializeListPreference (ListPreference preference ) {
93
97
if (preferenceListEntries == null ) {
94
98
preferenceListEntries = new String [customPlaybackSpeeds .length ];
95
99
preferenceListEntryValues = new String [customPlaybackSpeeds .length ];
100
+
96
101
int i = 0 ;
97
102
for (float speed : customPlaybackSpeeds ) {
98
103
String speedString = String .valueOf (speed );
@@ -101,6 +106,7 @@ public static void initializeListPreference(ListPreference preference) {
101
106
i ++;
102
107
}
103
108
}
109
+
104
110
preference .setEntries (preferenceListEntries );
105
111
preference .setEntryValues (preferenceListEntryValues );
106
112
}
@@ -111,52 +117,67 @@ public static void initializeListPreference(ListPreference preference) {
111
117
public static void onFlyoutMenuCreate (RecyclerView recyclerView ) {
112
118
recyclerView .getViewTreeObserver ().addOnDrawListener (() -> {
113
119
try {
114
- // For some reason, the custom playback speed flyout panel is activated when the user opens the share panel. (A/B tests)
115
- // Check the child count of playback speed flyout panel to prevent this issue.
116
- // Child count of playback speed flyout panel is always 8.
117
- if (! PlaybackSpeedMenuFilterPatch . isPlaybackSpeedMenuVisible || recyclerView . getChildCount () == 0 ) {
120
+ if ( PlaybackSpeedMenuFilterPatch . isPlaybackRateSelectorMenuVisible ) {
121
+ if ( hideLithoMenuAndShowOldSpeedMenu ( recyclerView , 5 )) {
122
+ PlaybackSpeedMenuFilterPatch . isPlaybackRateSelectorMenuVisible = false ;
123
+ }
118
124
return ;
119
125
}
126
+ } catch (Exception ex ) {
127
+ Logger .printException (() -> "isPlaybackRateSelectorMenuVisible failure failure: " , ex );
128
+ }
120
129
121
- View firstChild = recyclerView .getChildAt (0 );
122
- if (!(firstChild instanceof ViewGroup )) {
123
- return ;
124
- }
125
- ViewGroup PlaybackSpeedParentView = (ViewGroup ) firstChild ;
126
- if (PlaybackSpeedParentView .getChildCount () != 8 ) {
127
- return ;
130
+ try {
131
+ if (PlaybackSpeedMenuFilterPatch .isOldPlaybackSpeedMenuVisible ) {
132
+ if (hideLithoMenuAndShowOldSpeedMenu (recyclerView , 8 )) {
133
+ PlaybackSpeedMenuFilterPatch .isOldPlaybackSpeedMenuVisible = false ;
134
+ }
128
135
}
136
+ } catch (Exception ex ) {
137
+ Logger .printException (() -> "isOldPlaybackSpeedMenuVisible failure: " , ex );
138
+ }
139
+ });
140
+ }
129
141
130
- PlaybackSpeedMenuFilterPatch .isPlaybackSpeedMenuVisible = false ;
131
-
132
- ViewParent parentView3rd = Utils .getParentView (recyclerView , 3 );
133
- if (!(parentView3rd instanceof ViewGroup )) {
134
- return ;
135
- }
136
- ViewParent parentView4th = parentView3rd .getParent ();
137
- if (!(parentView4th instanceof ViewGroup )) {
138
- return ;
139
- }
142
+ private static boolean hideLithoMenuAndShowOldSpeedMenu (RecyclerView recyclerView , int expectedChildCount ) {
143
+ if (recyclerView .getChildCount () == 0 ) {
144
+ return false ;
145
+ }
140
146
141
- // Dismiss View [R.id.touch_outside] is the 1st ChildView of the 4th ParentView.
142
- // This only shows in phone layout.
143
- final var touchInsidedView = ((ViewGroup ) parentView4th ).getChildAt (0 );
144
- touchInsidedView .setSoundEffectsEnabled (false );
145
- touchInsidedView .performClick ();
147
+ View firstChild = recyclerView .getChildAt (0 );
148
+ if (!(firstChild instanceof ViewGroup )) {
149
+ return false ;
150
+ }
146
151
147
- // In tablet layout there is no Dismiss View, instead we just hide all two parent views.
148
- ((ViewGroup ) parentView3rd ).setVisibility (View .GONE );
149
- ((ViewGroup ) parentView4th ).setVisibility (View .GONE );
152
+ ViewGroup PlaybackSpeedParentView = (ViewGroup ) firstChild ;
153
+ if (PlaybackSpeedParentView .getChildCount () != expectedChildCount ) {
154
+ return false ;
155
+ }
150
156
151
- // This works without issues for both tablet and phone layouts,
152
- // So no code is needed to check whether the current device is a tablet or phone.
157
+ ViewParent parentView3rd = Utils .getParentView (recyclerView , 3 );
158
+ if (!(parentView3rd instanceof ViewGroup )) {
159
+ return true ;
160
+ }
153
161
154
- // Close the new Playback speed menu and show the old one.
155
- showOldPlaybackSpeedMenu ();
156
- } catch (Exception ex ) {
157
- Logger .printException (() -> "onFlyoutMenuCreate failure" , ex );
162
+ ViewParent parentView4th = parentView3rd .getParent ();
163
+ if (!(parentView4th instanceof ViewGroup )) {
164
+ return true ;
158
165
}
159
- });
166
+
167
+ // Dismiss View [R.id.touch_outside] is the 1st ChildView of the 4th ParentView.
168
+ // This only shows in phone layout.
169
+ final var touchInsidedView = ((ViewGroup ) parentView4th ).getChildAt (0 );
170
+ touchInsidedView .setSoundEffectsEnabled (false );
171
+ touchInsidedView .performClick ();
172
+
173
+ // In tablet layout there is no Dismiss View, instead we just hide all two parent views.
174
+ ((ViewGroup ) parentView3rd ).setVisibility (View .GONE );
175
+ ((ViewGroup ) parentView4th ).setVisibility (View .GONE );
176
+
177
+ // Close the litho speed menu and show the old one.
178
+ showOldPlaybackSpeedMenu ();
179
+
180
+ return true ;
160
181
}
161
182
162
183
public static void showOldPlaybackSpeedMenu () {
0 commit comments