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