mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Bonus fix: Made `single_choice_dialog_view` scrollable + use viewbinding
				
					
				
			This commit is contained in:
		| @@ -369,11 +369,13 @@ public class RouterActivity extends AppCompatActivity { | |||||||
|  |  | ||||||
|     private void showDialog(final List<AdapterChoiceItem> choices) { |     private void showDialog(final List<AdapterChoiceItem> choices) { | ||||||
|         final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |         final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); | ||||||
|         final Context themeWrapperContext = getThemeWrapperContext(); |  | ||||||
|  |  | ||||||
|         final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext); |         final Context themeWrapperContext = getThemeWrapperContext(); | ||||||
|         final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(getLayoutInflater()) |         final LayoutInflater layoutInflater = LayoutInflater.from(themeWrapperContext); | ||||||
|                 .list; |  | ||||||
|  |         final SingleChoiceDialogViewBinding binding = | ||||||
|  |                 SingleChoiceDialogViewBinding.inflate(layoutInflater); | ||||||
|  |         final RadioGroup radioGroup = binding.list; | ||||||
|  |  | ||||||
|         final DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> { |         final DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> { | ||||||
|             final int indexOfChild = radioGroup.indexOfChild( |             final int indexOfChild = radioGroup.indexOfChild( | ||||||
| @@ -392,7 +394,7 @@ public class RouterActivity extends AppCompatActivity { | |||||||
|  |  | ||||||
|         alertDialogChoice = new AlertDialog.Builder(themeWrapperContext) |         alertDialogChoice = new AlertDialog.Builder(themeWrapperContext) | ||||||
|                 .setTitle(R.string.preferred_open_action_share_menu_title) |                 .setTitle(R.string.preferred_open_action_share_menu_title) | ||||||
|                 .setView(radioGroup) |                 .setView(binding.getRoot()) | ||||||
|                 .setCancelable(true) |                 .setCancelable(true) | ||||||
|                 .setNegativeButton(R.string.just_once, dialogButtonsClickListener) |                 .setNegativeButton(R.string.just_once, dialogButtonsClickListener) | ||||||
|                 .setPositiveButton(R.string.always, dialogButtonsClickListener) |                 .setPositiveButton(R.string.always, dialogButtonsClickListener) | ||||||
| @@ -424,7 +426,8 @@ public class RouterActivity extends AppCompatActivity { | |||||||
|  |  | ||||||
|         int id = 12345; |         int id = 12345; | ||||||
|         for (final AdapterChoiceItem item : choices) { |         for (final AdapterChoiceItem item : choices) { | ||||||
|             final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater).getRoot(); |             final RadioButton radioButton = ListRadioIconItemBinding.inflate(layoutInflater) | ||||||
|  |                     .getRoot(); | ||||||
|             radioButton.setText(item.description); |             radioButton.setText(item.description); | ||||||
|             radioButton.setCompoundDrawablesRelativeWithIntrinsicBounds( |             radioButton.setCompoundDrawablesRelativeWithIntrinsicBounds( | ||||||
|                     AppCompatResources.getDrawable(themeWrapperContext, item.icon), |                     AppCompatResources.getDrawable(themeWrapperContext, item.icon), | ||||||
|   | |||||||
| @@ -663,8 +663,7 @@ public final class VideoDetailFragment | |||||||
|             binding.detailControlsCrashThePlayer.setOnClickListener( |             binding.detailControlsCrashThePlayer.setOnClickListener( | ||||||
|                     v -> VideoDetailPlayerCrasher.onCrashThePlayer( |                     v -> VideoDetailPlayerCrasher.onCrashThePlayer( | ||||||
|                             this.getContext(), |                             this.getContext(), | ||||||
|                             this.player, |                             this.player) | ||||||
|                             getLayoutInflater()) |  | ||||||
|             ); |             ); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,9 @@ | |||||||
| package org.schabi.newpipe.fragments.detail; | package org.schabi.newpipe.fragments.detail; | ||||||
|  |  | ||||||
|  | import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW; | ||||||
|  | import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_DECODING_FAILED; | ||||||
|  | import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECIFIED; | ||||||
|  |  | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
| import android.view.ContextThemeWrapper; | import android.view.ContextThemeWrapper; | ||||||
| @@ -29,10 +33,6 @@ import java.util.LinkedHashMap; | |||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.function.Supplier; | import java.util.function.Supplier; | ||||||
|  |  | ||||||
| import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW; |  | ||||||
| import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_DECODING_FAILED; |  | ||||||
| import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECIFIED; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Outsourced logic for crashing the player in the {@link VideoDetailFragment}. |  * Outsourced logic for crashing the player in the {@link VideoDetailFragment}. | ||||||
|  */ |  */ | ||||||
| @@ -97,8 +97,7 @@ public final class VideoDetailPlayerCrasher { | |||||||
|  |  | ||||||
|     public static void onCrashThePlayer( |     public static void onCrashThePlayer( | ||||||
|             @NonNull final Context context, |             @NonNull final Context context, | ||||||
|             @Nullable final Player player, |             @Nullable final Player player | ||||||
|             @NonNull final LayoutInflater layoutInflater |  | ||||||
|     ) { |     ) { | ||||||
|         if (player == null) { |         if (player == null) { | ||||||
|             Log.d(TAG, "Player is not available"); |             Log.d(TAG, "Player is not available"); | ||||||
| @@ -109,16 +108,15 @@ public final class VideoDetailPlayerCrasher { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // -- Build the dialog/UI -- |         // -- Build the dialog/UI -- | ||||||
|  |  | ||||||
|         final Context themeWrapperContext = getThemeWrapperContext(context); |         final Context themeWrapperContext = getThemeWrapperContext(context); | ||||||
|  |  | ||||||
|         final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext); |         final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext); | ||||||
|         final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(layoutInflater) |  | ||||||
|                 .list; |  | ||||||
|  |  | ||||||
|         final AlertDialog alertDialog = new AlertDialog.Builder(getThemeWrapperContext(context)) |         final SingleChoiceDialogViewBinding binding = | ||||||
|  |                 SingleChoiceDialogViewBinding.inflate(inflater); | ||||||
|  |  | ||||||
|  |         final AlertDialog alertDialog = new AlertDialog.Builder(themeWrapperContext) | ||||||
|                 .setTitle("Choose an exception") |                 .setTitle("Choose an exception") | ||||||
|                 .setView(radioGroup) |                 .setView(binding.getRoot()) | ||||||
|                 .setCancelable(true) |                 .setCancelable(true) | ||||||
|                 .setNegativeButton(R.string.cancel, null) |                 .setNegativeButton(R.string.cancel, null) | ||||||
|                 .create(); |                 .create(); | ||||||
| @@ -136,11 +134,9 @@ public final class VideoDetailPlayerCrasher { | |||||||
|             ); |             ); | ||||||
|             radioButton.setOnClickListener(v -> { |             radioButton.setOnClickListener(v -> { | ||||||
|                 tryCrashPlayerWith(player, entry.getValue().get()); |                 tryCrashPlayerWith(player, entry.getValue().get()); | ||||||
|                 if (alertDialog != null) { |  | ||||||
|                 alertDialog.cancel(); |                 alertDialog.cancel(); | ||||||
|                 } |  | ||||||
|             }); |             }); | ||||||
|             radioGroup.addView(radioButton); |             binding.list.addView(radioButton); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         alertDialog.show(); |         alertDialog.show(); | ||||||
|   | |||||||
| @@ -10,7 +10,6 @@ import android.view.View; | |||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| import android.widget.CheckBox; | import android.widget.CheckBox; | ||||||
| import android.widget.ImageView; | import android.widget.ImageView; | ||||||
| import android.widget.LinearLayout; |  | ||||||
| import android.widget.RadioButton; | import android.widget.RadioButton; | ||||||
| import android.widget.RadioGroup; | import android.widget.RadioGroup; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
| @@ -25,6 +24,8 @@ import androidx.preference.Preference; | |||||||
| import androidx.preference.PreferenceViewHolder; | import androidx.preference.PreferenceViewHolder; | ||||||
|  |  | ||||||
| import org.schabi.newpipe.R; | import org.schabi.newpipe.R; | ||||||
|  | import org.schabi.newpipe.databinding.ListRadioIconItemBinding; | ||||||
|  | import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding; | ||||||
| import org.schabi.newpipe.player.MainPlayer; | import org.schabi.newpipe.player.MainPlayer; | ||||||
| import org.schabi.newpipe.player.NotificationConstants; | import org.schabi.newpipe.player.NotificationConstants; | ||||||
| import org.schabi.newpipe.util.DeviceUtils; | import org.schabi.newpipe.util.DeviceUtils; | ||||||
| @@ -189,13 +190,12 @@ public class NotificationActionsPreference extends Preference { | |||||||
|  |  | ||||||
|         void openActionChooserDialog() { |         void openActionChooserDialog() { | ||||||
|             final LayoutInflater inflater = LayoutInflater.from(getContext()); |             final LayoutInflater inflater = LayoutInflater.from(getContext()); | ||||||
|             final LinearLayout rootLayout = (LinearLayout) inflater.inflate( |             final SingleChoiceDialogViewBinding binding = | ||||||
|                     R.layout.single_choice_dialog_view, null, false); |                     SingleChoiceDialogViewBinding.inflate(inflater); | ||||||
|             final RadioGroup radioGroup = rootLayout.findViewById(android.R.id.list); |  | ||||||
|  |  | ||||||
|             final AlertDialog alertDialog = new AlertDialog.Builder(getContext()) |             final AlertDialog alertDialog = new AlertDialog.Builder(getContext()) | ||||||
|                     .setTitle(SLOT_TITLES[i]) |                     .setTitle(SLOT_TITLES[i]) | ||||||
|                     .setView(radioGroup) |                     .setView(binding.getRoot()) | ||||||
|                     .setCancelable(true) |                     .setCancelable(true) | ||||||
|                     .create(); |                     .create(); | ||||||
|  |  | ||||||
| @@ -207,8 +207,8 @@ public class NotificationActionsPreference extends Preference { | |||||||
|  |  | ||||||
|             for (int id = 0; id < NotificationConstants.SLOT_ALLOWED_ACTIONS[i].length; ++id) { |             for (int id = 0; id < NotificationConstants.SLOT_ALLOWED_ACTIONS[i].length; ++id) { | ||||||
|                 final int action = NotificationConstants.SLOT_ALLOWED_ACTIONS[i][id]; |                 final int action = NotificationConstants.SLOT_ALLOWED_ACTIONS[i][id]; | ||||||
|                 final RadioButton radioButton |                 final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater) | ||||||
|                         = (RadioButton) inflater.inflate(R.layout.list_radio_icon_item, null); |                         .getRoot(); | ||||||
|  |  | ||||||
|                 // if present set action icon with correct color |                 // if present set action icon with correct color | ||||||
|                 if (NotificationConstants.ACTION_ICONS[action] != 0) { |                 if (NotificationConstants.ACTION_ICONS[action] != 0) { | ||||||
| @@ -230,7 +230,7 @@ public class NotificationActionsPreference extends Preference { | |||||||
|                 radioButton.setLayoutParams(new RadioGroup.LayoutParams( |                 radioButton.setLayoutParams(new RadioGroup.LayoutParams( | ||||||
|                         ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); |                         ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); | ||||||
|                 radioButton.setOnClickListener(radioButtonsClickListener); |                 radioButton.setOnClickListener(radioButtonsClickListener); | ||||||
|                 radioGroup.addView(radioButton); |                 binding.list.addView(radioButton); | ||||||
|             } |             } | ||||||
|             alertDialog.show(); |             alertDialog.show(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +1,14 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?><!-- --> | ||||||
| <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" | <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     android:fadeScrollbars="false"> | ||||||
|  |  | ||||||
|  |     <RadioGroup | ||||||
|         android:id="@android:id/list" |         android:id="@android:id/list" | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="wrap_content" |         android:layout_height="wrap_content" | ||||||
|         android:paddingTop="?attr/listPreferredItemPaddingLeft" /> |         android:paddingTop="?attr/listPreferredItemPaddingLeft" /> | ||||||
|  | </ScrollView> | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 litetex
					litetex