From 8f91e86a95a0e77d54b443f7adaaee4f5ecca35f Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 7 May 2023 10:55:40 +0530 Subject: [PATCH] Migrate to non-transitive R classes. --- .../org/schabi/newpipe/error/ErrorUtil.kt | 9 +- .../schabi/newpipe/local/feed/FeedFragment.kt | 4 +- .../newpipe/player/PlayQueueActivity.java | 9 +- .../helper/PlaybackParameterDialog.java | 12 ++- .../notification/NotificationConstants.java | 52 ++++++---- .../player/notification/NotificationUtil.java | 94 +++++++++++++------ .../newpipe/player/ui/VideoPlayerUi.java | 9 +- 7 files changed, 128 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt index daa59850949..a1c89454a30 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt @@ -54,7 +54,11 @@ class ErrorUtil { */ @JvmStatic fun showSnackbar(context: Context, errorInfo: ErrorInfo) { - val rootView = if (context is Activity) context.findViewById(R.id.content) else null + val rootView = if (context is Activity) { + context.findViewById(androidx.constraintlayout.widget.R.id.content) + } else { + null + } showSnackbar(context, rootView, errorInfo) } @@ -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) } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 9fe90969f1c..c684654faf7 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -546,7 +546,7 @@ class FeedFragment : BaseStateFragment() { 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 @@ -559,7 +559,7 @@ class FeedFragment : BaseStateFragment() { LayerDrawable( arrayOf( resolveDrawable(ctx, R.attr.dashed_border), - resolveDrawable(ctx, R.attr.selectableItemBackground) + resolveDrawable(ctx, androidx.appcompat.R.attr.selectableItemBackground) ) ) } diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java index cd71c64e9e8..02d5c570bb1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java @@ -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; } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index 796208a0498..4388af8a036 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -342,14 +342,16 @@ private void changePitchControlMode(final boolean semitones) { final Map 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) })); } @@ -415,14 +417,16 @@ private void setStepSizeToUI(final double newStepSize) { // Bring all textviews into a normal state final Map 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) })); } diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationConstants.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationConstants.java index 89bf0b22ae2..4213714b1b1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationConstants.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationConstants.java @@ -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, }; @@ -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); diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index 05c2e3af6dd..99dd8f4e65e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -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: @@ -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: diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java index 2638ff041a8..53b533972a9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java @@ -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); } }