Skip to content

Commit 2985258

Browse files
committed
Bonus fix: Made single_choice_dialog_view scrollable + use viewbinding
1 parent 911ac65 commit 2985258

5 files changed

Lines changed: 42 additions & 36 deletions

File tree

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,13 @@ public boolean isAvailableAndSelected(@StringRes final int wantedKey) {
369369

370370
private void showDialog(final List<AdapterChoiceItem> choices) {
371371
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
372+
372373
final Context themeWrapperContext = getThemeWrapperContext();
374+
final LayoutInflater layoutInflater = LayoutInflater.from(themeWrapperContext);
373375

374-
final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext);
375-
final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(getLayoutInflater())
376-
.list;
376+
final SingleChoiceDialogViewBinding binding =
377+
SingleChoiceDialogViewBinding.inflate(layoutInflater);
378+
final RadioGroup radioGroup = binding.list;
377379

378380
final DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> {
379381
final int indexOfChild = radioGroup.indexOfChild(
@@ -392,7 +394,7 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
392394

393395
alertDialogChoice = new AlertDialog.Builder(themeWrapperContext)
394396
.setTitle(R.string.preferred_open_action_share_menu_title)
395-
.setView(radioGroup)
397+
.setView(binding.getRoot())
396398
.setCancelable(true)
397399
.setNegativeButton(R.string.just_once, dialogButtonsClickListener)
398400
.setPositiveButton(R.string.always, dialogButtonsClickListener)
@@ -424,7 +426,8 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
424426

425427
int id = 12345;
426428
for (final AdapterChoiceItem item : choices) {
427-
final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater).getRoot();
429+
final RadioButton radioButton = ListRadioIconItemBinding.inflate(layoutInflater)
430+
.getRoot();
428431
radioButton.setText(item.description);
429432
radioButton.setCompoundDrawablesRelativeWithIntrinsicBounds(
430433
AppCompatResources.getDrawable(themeWrapperContext, item.icon),

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ protected void initListeners() {
663663
binding.detailControlsCrashThePlayer.setOnClickListener(
664664
v -> VideoDetailPlayerCrasher.onCrashThePlayer(
665665
this.getContext(),
666-
this.player,
667-
getLayoutInflater())
666+
this.player)
668667
);
669668
}
670669

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailPlayerCrasher.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.schabi.newpipe.fragments.detail;
22

3+
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW;
4+
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_DECODING_FAILED;
5+
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECIFIED;
6+
37
import android.content.Context;
48
import android.util.Log;
59
import android.view.ContextThemeWrapper;
@@ -29,10 +33,6 @@
2933
import java.util.Map;
3034
import java.util.function.Supplier;
3135

32-
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW;
33-
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_DECODING_FAILED;
34-
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECIFIED;
35-
3636
/**
3737
* Outsourced logic for crashing the player in the {@link VideoDetailFragment}.
3838
*/
@@ -97,8 +97,7 @@ private static Context getThemeWrapperContext(final Context context) {
9797

9898
public static void onCrashThePlayer(
9999
@NonNull final Context context,
100-
@Nullable final Player player,
101-
@NonNull final LayoutInflater layoutInflater
100+
@Nullable final Player player
102101
) {
103102
if (player == null) {
104103
Log.d(TAG, "Player is not available");
@@ -109,16 +108,15 @@ public static void onCrashThePlayer(
109108
}
110109

111110
// -- Build the dialog/UI --
112-
113111
final Context themeWrapperContext = getThemeWrapperContext(context);
114-
115112
final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext);
116-
final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(layoutInflater)
117-
.list;
118113

119-
final AlertDialog alertDialog = new AlertDialog.Builder(getThemeWrapperContext(context))
114+
final SingleChoiceDialogViewBinding binding =
115+
SingleChoiceDialogViewBinding.inflate(inflater);
116+
117+
final AlertDialog alertDialog = new AlertDialog.Builder(themeWrapperContext)
120118
.setTitle("Choose an exception")
121-
.setView(radioGroup)
119+
.setView(binding.getRoot())
122120
.setCancelable(true)
123121
.setNegativeButton(R.string.cancel, null)
124122
.create();
@@ -136,11 +134,9 @@ public static void onCrashThePlayer(
136134
);
137135
radioButton.setOnClickListener(v -> {
138136
tryCrashPlayerWith(player, entry.getValue().get());
139-
if (alertDialog != null) {
140-
alertDialog.cancel();
141-
}
137+
alertDialog.cancel();
142138
});
143-
radioGroup.addView(radioButton);
139+
binding.list.addView(radioButton);
144140
}
145141

146142
alertDialog.show();

app/src/main/java/org/schabi/newpipe/settings/custom/NotificationActionsPreference.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.view.ViewGroup;
1111
import android.widget.CheckBox;
1212
import android.widget.ImageView;
13-
import android.widget.LinearLayout;
1413
import android.widget.RadioButton;
1514
import android.widget.RadioGroup;
1615
import android.widget.TextView;
@@ -25,6 +24,8 @@
2524
import androidx.preference.PreferenceViewHolder;
2625

2726
import org.schabi.newpipe.R;
27+
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
28+
import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding;
2829
import org.schabi.newpipe.player.MainPlayer;
2930
import org.schabi.newpipe.player.NotificationConstants;
3031
import org.schabi.newpipe.util.DeviceUtils;
@@ -189,13 +190,12 @@ void updateInfo() {
189190

190191
void openActionChooserDialog() {
191192
final LayoutInflater inflater = LayoutInflater.from(getContext());
192-
final LinearLayout rootLayout = (LinearLayout) inflater.inflate(
193-
R.layout.single_choice_dialog_view, null, false);
194-
final RadioGroup radioGroup = rootLayout.findViewById(android.R.id.list);
193+
final SingleChoiceDialogViewBinding binding =
194+
SingleChoiceDialogViewBinding.inflate(inflater);
195195

196196
final AlertDialog alertDialog = new AlertDialog.Builder(getContext())
197197
.setTitle(SLOT_TITLES[i])
198-
.setView(radioGroup)
198+
.setView(binding.getRoot())
199199
.setCancelable(true)
200200
.create();
201201

@@ -207,8 +207,8 @@ void openActionChooserDialog() {
207207

208208
for (int id = 0; id < NotificationConstants.SLOT_ALLOWED_ACTIONS[i].length; ++id) {
209209
final int action = NotificationConstants.SLOT_ALLOWED_ACTIONS[i][id];
210-
final RadioButton radioButton
211-
= (RadioButton) inflater.inflate(R.layout.list_radio_icon_item, null);
210+
final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater)
211+
.getRoot();
212212

213213
// if present set action icon with correct color
214214
if (NotificationConstants.ACTION_ICONS[action] != 0) {
@@ -230,7 +230,7 @@ void openActionChooserDialog() {
230230
radioButton.setLayoutParams(new RadioGroup.LayoutParams(
231231
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
232232
radioButton.setOnClickListener(radioButtonsClickListener);
233-
radioGroup.addView(radioButton);
233+
binding.list.addView(radioButton);
234234
}
235235
alertDialog.show();
236236

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:id="@android:id/list"
1+
<?xml version="1.0" encoding="utf-8"?><!-- -->
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
43
android:layout_width="match_parent"
5-
android:layout_height="wrap_content"
6-
android:paddingTop="?attr/listPreferredItemPaddingLeft" />
4+
android:layout_height="match_parent"
5+
android:fadeScrollbars="false">
6+
7+
<RadioGroup
8+
android:id="@android:id/list"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:paddingTop="?attr/listPreferredItemPaddingLeft" />
12+
</ScrollView>
13+
14+

0 commit comments

Comments
 (0)