Skip to content

Commit

Permalink
Migrate to non-transitive R classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed May 7, 2023
1 parent df430ba commit 8f91e86
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 61 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class ErrorUtil {
*/
@JvmStatic
fun showSnackbar(context: Context, errorInfo: ErrorInfo) {
val rootView = if (context is Activity) context.findViewById<View>(R.id.content) else null
val rootView = if (context is Activity) {
context.findViewById<View>(androidx.constraintlayout.widget.R.id.content)
} else {
null
}
showSnackbar(context, rootView, errorInfo)
}

Expand All @@ -71,7 +75,8 @@ class ErrorUtil {
fun showSnackbar(fragment: Fragment, errorInfo: ErrorInfo) {
var rootView = fragment.view
if (rootView == null && fragment.activity != null) {
rootView = fragment.requireActivity().findViewById(R.id.content)
rootView = fragment.requireActivity()
.findViewById(androidx.constraintlayout.widget.R.id.content)
}
showSnackbar(fragment.requireContext(), rootView, errorInfo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {

var typeface = Typeface.DEFAULT
var backgroundSupplier = { ctx: Context ->
resolveDrawable(ctx, R.attr.selectableItemBackground)
resolveDrawable(ctx, androidx.appcompat.R.attr.selectableItemBackground)
}
if (doCheck) {
// If the uploadDate is null or true we should highlight the item
Expand All @@ -559,7 +559,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
LayerDrawable(
arrayOf(
resolveDrawable(ctx, R.attr.dashed_border),
resolveDrawable(ctx, R.attr.selectableItemBackground)
resolveDrawable(ctx, androidx.appcompat.R.attr.selectableItemBackground)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,18 @@ private void onPlayModeChanged(final int repeatMode, final boolean shuffled) {
switch (repeatMode) {
case com.google.android.exoplayer2.Player.REPEAT_MODE_OFF:
queueControlBinding.controlRepeat
.setImageResource(R.drawable.exo_controls_repeat_off);
.setImageResource(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_repeat_off);
break;
case com.google.android.exoplayer2.Player.REPEAT_MODE_ONE:
queueControlBinding.controlRepeat
.setImageResource(R.drawable.exo_controls_repeat_one);
.setImageResource(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_repeat_one);
break;
case com.google.android.exoplayer2.Player.REPEAT_MODE_ALL:
queueControlBinding.controlRepeat
.setImageResource(R.drawable.exo_controls_repeat_all);
.setImageResource(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_repeat_all);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,16 @@ private void changePitchControlMode(final boolean semitones) {
final Map<Boolean, TextView> pitchCtrlModeComponentMapping =
getPitchControlModeComponentMappings();
pitchCtrlModeComponentMapping.forEach((v, textView) -> textView.setBackground(
resolveDrawable(requireContext(), R.attr.selectableItemBackground)));
resolveDrawable(requireContext(),
androidx.appcompat.R.attr.selectableItemBackground)));

// Mark the selected textview
final TextView textView = pitchCtrlModeComponentMapping.get(semitones);
if (textView != null) {
textView.setBackground(new LayerDrawable(new Drawable[]{
resolveDrawable(requireContext(), R.attr.dashed_border),
resolveDrawable(requireContext(), R.attr.selectableItemBackground)
resolveDrawable(requireContext(),
androidx.appcompat.R.attr.selectableItemBackground)
}));
}

Expand Down Expand Up @@ -415,14 +417,16 @@ private void setStepSizeToUI(final double newStepSize) {
// Bring all textviews into a normal state
final Map<Double, TextView> stepSiteComponentMapping = getStepSizeComponentMappings();
stepSiteComponentMapping.forEach((v, textView) -> textView.setBackground(
resolveDrawable(requireContext(), R.attr.selectableItemBackground)));
resolveDrawable(requireContext(),
androidx.appcompat.R.attr.selectableItemBackground)));

// Mark the selected textview
final TextView textView = stepSiteComponentMapping.get(newStepSize);
if (textView != null) {
textView.setBackground(new LayerDrawable(new Drawable[]{
resolveDrawable(requireContext(), R.attr.dashed_border),
resolveDrawable(requireContext(), R.attr.selectableItemBackground)
resolveDrawable(requireContext(),
androidx.appcompat.R.attr.selectableItemBackground)
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ private NotificationConstants() {
@DrawableRes
public static final int[] ACTION_ICONS = {
0,
R.drawable.exo_icon_previous,
R.drawable.exo_icon_next,
R.drawable.exo_icon_rewind,
R.drawable.exo_icon_fastforward,
R.drawable.exo_icon_previous,
R.drawable.exo_icon_next,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_previous,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_next,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_rewind,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_fastforward,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_previous,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_next,
R.drawable.ic_pause,
R.drawable.ic_hourglass_top,
R.drawable.exo_icon_repeat_all,
R.drawable.exo_icon_shuffle_on,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_repeat_all,
com.google.android.exoplayer2.ui.R.drawable.exo_icon_shuffle_on,
R.drawable.ic_close,
};

Expand Down Expand Up @@ -126,29 +126,41 @@ private NotificationConstants() {
public static String getActionName(@NonNull final Context context, @Action final int action) {
switch (action) {
case PREVIOUS:
return context.getString(R.string.exo_controls_previous_description);
return context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_previous_description);
case NEXT:
return context.getString(R.string.exo_controls_next_description);
return context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_next_description);
case REWIND:
return context.getString(R.string.exo_controls_rewind_description);
return context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_rewind_description);
case FORWARD:
return context.getString(R.string.exo_controls_fastforward_description);
return context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_fastforward_description);
case SMART_REWIND_PREVIOUS:
return Localization.concatenateStrings(
context.getString(R.string.exo_controls_rewind_description),
context.getString(R.string.exo_controls_previous_description));
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_rewind_description),
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_previous_description));
case SMART_FORWARD_NEXT:
return Localization.concatenateStrings(
context.getString(R.string.exo_controls_fastforward_description),
context.getString(R.string.exo_controls_next_description));
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_fastforward_description),
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_next_description));
case PLAY_PAUSE:
return Localization.concatenateStrings(
context.getString(R.string.exo_controls_play_description),
context.getString(R.string.exo_controls_pause_description));
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_play_description),
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_pause_description));
case PLAY_PAUSE_BUFFERING:
return Localization.concatenateStrings(
context.getString(R.string.exo_controls_play_description),
context.getString(R.string.exo_controls_pause_description),
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_play_description),
context.getString(com.google.android.exoplayer2.ui.R.string
.exo_controls_pause_description),
context.getString(R.string.notification_action_buffering));
case REPEAT:
return context.getString(R.string.notification_action_repeat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,36 +240,53 @@ private NotificationCompat.Action getAction(
switch (selectedAction) {
case NotificationConstants.PREVIOUS:
return getAction(baseActionIcon,
R.string.exo_controls_previous_description, ACTION_PLAY_PREVIOUS);
com.google.android.exoplayer2.ui.R.string.exo_controls_previous_description,
ACTION_PLAY_PREVIOUS);

case NotificationConstants.NEXT:
return getAction(baseActionIcon,
R.string.exo_controls_next_description, ACTION_PLAY_NEXT);
com.google.android.exoplayer2.ui.R.string.exo_controls_next_description,
ACTION_PLAY_NEXT);

case NotificationConstants.REWIND:
return getAction(baseActionIcon,
R.string.exo_controls_rewind_description, ACTION_FAST_REWIND);
com.google.android.exoplayer2.ui.R.string.exo_controls_rewind_description,
ACTION_FAST_REWIND);

case NotificationConstants.FORWARD:
return getAction(baseActionIcon,
R.string.exo_controls_fastforward_description, ACTION_FAST_FORWARD);
com.google.android.exoplayer2.ui.R.string
.exo_controls_fastforward_description,
ACTION_FAST_FORWARD);

case NotificationConstants.SMART_REWIND_PREVIOUS:
if (player.getPlayQueue() != null && player.getPlayQueue().size() > 1) {
return getAction(R.drawable.exo_notification_previous,
R.string.exo_controls_previous_description, ACTION_PLAY_PREVIOUS);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_notification_previous,
com.google.android.exoplayer2.ui.R.string
.exo_controls_previous_description,
ACTION_PLAY_PREVIOUS);
} else {
return getAction(R.drawable.exo_controls_rewind,
R.string.exo_controls_rewind_description, ACTION_FAST_REWIND);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_rewind,
com.google.android.exoplayer2.ui.R.string
.exo_controls_rewind_description,
ACTION_FAST_REWIND);
}

case NotificationConstants.SMART_FORWARD_NEXT:
if (player.getPlayQueue() != null && player.getPlayQueue().size() > 1) {
return getAction(R.drawable.exo_notification_next,
R.string.exo_controls_next_description, ACTION_PLAY_NEXT);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_notification_next,
com.google.android.exoplayer2.ui.R.string
.exo_controls_next_description,
ACTION_PLAY_NEXT);
} else {
return getAction(R.drawable.exo_controls_fastforward,
R.string.exo_controls_fastforward_description, ACTION_FAST_FORWARD);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_fastforward,
com.google.android.exoplayer2.ui.R.string
.exo_controls_fastforward_description,
ACTION_FAST_FORWARD);
}

case NotificationConstants.PLAY_PAUSE_BUFFERING:
Expand All @@ -286,37 +303,60 @@ private NotificationCompat.Action getAction(
case NotificationConstants.PLAY_PAUSE:
if (player.getCurrentState() == Player.STATE_COMPLETED) {
return getAction(R.drawable.ic_replay,
R.string.exo_controls_pause_description, ACTION_PLAY_PAUSE);
com.google.android.exoplayer2.ui.R.string
.exo_controls_pause_description,
ACTION_PLAY_PAUSE);
} else if (player.isPlaying()
|| player.getCurrentState() == Player.STATE_PREFLIGHT
|| player.getCurrentState() == Player.STATE_BLOCKED
|| player.getCurrentState() == Player.STATE_BUFFERING) {
return getAction(R.drawable.exo_notification_pause,
R.string.exo_controls_pause_description, ACTION_PLAY_PAUSE);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_notification_pause,
com.google.android.exoplayer2.ui.R.string
.exo_controls_pause_description,
ACTION_PLAY_PAUSE);
} else {
return getAction(R.drawable.exo_notification_play,
R.string.exo_controls_play_description, ACTION_PLAY_PAUSE);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_notification_play,
com.google.android.exoplayer2.ui.R.string
.exo_controls_play_description,
ACTION_PLAY_PAUSE);
}

case NotificationConstants.REPEAT:
if (player.getRepeatMode() == REPEAT_MODE_ALL) {
return getAction(R.drawable.exo_media_action_repeat_all,
R.string.exo_controls_repeat_all_description, ACTION_REPEAT);
return getAction(
com.google.android.exoplayer2.ext.mediasession.R.drawable
.exo_media_action_repeat_all,
com.google.android.exoplayer2.ui.R.string
.exo_controls_repeat_all_description,
ACTION_REPEAT);
} else if (player.getRepeatMode() == REPEAT_MODE_ONE) {
return getAction(R.drawable.exo_media_action_repeat_one,
R.string.exo_controls_repeat_one_description, ACTION_REPEAT);
return getAction(com.google.android.exoplayer2.ext.mediasession.R.drawable
.exo_media_action_repeat_one,
com.google.android.exoplayer2.ui.R.string
.exo_controls_repeat_one_description,
ACTION_REPEAT);
} else /* player.getRepeatMode() == REPEAT_MODE_OFF */ {
return getAction(R.drawable.exo_media_action_repeat_off,
R.string.exo_controls_repeat_off_description, ACTION_REPEAT);
return getAction(com.google.android.exoplayer2.ext.mediasession.R.drawable
.exo_media_action_repeat_off,
com.google.android.exoplayer2.ui.R.string
.exo_controls_repeat_off_description,
ACTION_REPEAT);
}

case NotificationConstants.SHUFFLE:
if (player.getPlayQueue() != null && player.getPlayQueue().isShuffled()) {
return getAction(R.drawable.exo_controls_shuffle_on,
R.string.exo_controls_shuffle_on_description, ACTION_SHUFFLE);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_shuffle_on,
com.google.android.exoplayer2.ui.R.string
.exo_controls_shuffle_on_description, ACTION_SHUFFLE);
} else {
return getAction(R.drawable.exo_controls_shuffle_off,
R.string.exo_controls_shuffle_off_description, ACTION_SHUFFLE);
return getAction(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_shuffle_off,
com.google.android.exoplayer2.ui.R.string
.exo_controls_shuffle_off_description,
ACTION_SHUFFLE);
}

case NotificationConstants.CLOSE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,14 @@ public void onRepeatModeChanged(@RepeatMode final int repeatMode) {
super.onRepeatModeChanged(repeatMode);

if (repeatMode == REPEAT_MODE_ALL) {
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_all);
binding.repeatButton.setImageResource(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_repeat_all);
} else if (repeatMode == REPEAT_MODE_ONE) {
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_one);
binding.repeatButton.setImageResource(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_repeat_one);
} else /* repeatMode == REPEAT_MODE_OFF */ {
binding.repeatButton.setImageResource(R.drawable.exo_controls_repeat_off);
binding.repeatButton.setImageResource(com.google.android.exoplayer2.ui.R.drawable
.exo_controls_repeat_off);
}
}

Expand Down

0 comments on commit 8f91e86

Please sign in to comment.