1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Remove hardcoded and duplicate strings, use exoplayer ones

This commit is contained in:
Stypox 2020-09-22 16:46:09 +02:00
parent 7317737e90
commit 11e048abb1
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
5 changed files with 95 additions and 86 deletions

View File

@ -6,9 +6,9 @@ import android.content.SharedPreferences;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.Localization;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -41,22 +41,6 @@ public final class NotificationConstants {
PLAY_PAUSE, PLAY_PAUSE_BUFFERING, REPEAT, SHUFFLE, CLOSE})
public @interface Action { }
@StringRes
public static final int[] ACTION_SUMMARIES = {
R.string.notification_action_nothing,
R.string.notification_action_previous,
R.string.notification_action_next,
R.string.notification_action_rewind,
R.string.notification_action_forward,
R.string.notification_action_smart_rewind_previous,
R.string.notification_action_smart_forward_next,
R.string.notification_action_play_pause,
R.string.notification_action_play_pause_buffering,
R.string.notification_action_repeat,
R.string.notification_action_shuffle,
R.string.close,
};
@DrawableRes
public static final int[] ACTION_ICONS = {
0,
@ -110,6 +94,46 @@ public final class NotificationConstants {
R.string.notification_slot_compact_2_key,
};
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);
case NEXT:
return context.getString(R.string.exo_controls_next_description);
case REWIND:
return context.getString(R.string.exo_controls_rewind_description);
case FORWARD:
return context.getString(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));
case SMART_FORWARD_NEXT:
return Localization.concatenateStrings(
context.getString(R.string.exo_controls_fastforward_description),
context.getString(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));
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(R.string.notification_action_buffering));
case REPEAT:
return context.getString(R.string.notification_action_repeat);
case SHUFFLE:
return context.getString(R.string.notification_action_shuffle);
case CLOSE:
return context.getString(R.string.close);
case NOTHING: default:
return context.getString(R.string.notification_action_nothing);
}
}
/**
* @param context the context to use
* @param sharedPreferences the shared preferences to query values from

View File

@ -12,6 +12,7 @@ import android.util.Log;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
@ -214,75 +215,89 @@ public final class NotificationUtil {
final int baseActionIcon = NotificationConstants.ACTION_ICONS[selectedAction];
switch (selectedAction) {
case NotificationConstants.PREVIOUS:
return getAction(player, baseActionIcon, "Previous", ACTION_PLAY_PREVIOUS);
return getAction(player, baseActionIcon,
R.string.exo_controls_previous_description, ACTION_PLAY_PREVIOUS);
case NotificationConstants.NEXT:
return getAction(player, baseActionIcon, "Next", ACTION_PLAY_NEXT);
return getAction(player, baseActionIcon,
R.string.exo_controls_next_description, ACTION_PLAY_NEXT);
case NotificationConstants.REWIND:
return getAction(player, baseActionIcon, "Rewind", ACTION_FAST_REWIND);
return getAction(player, baseActionIcon,
R.string.exo_controls_rewind_description, ACTION_FAST_REWIND);
case NotificationConstants.FORWARD:
return getAction(player, baseActionIcon, "Forward", ACTION_FAST_FORWARD);
return getAction(player, baseActionIcon,
R.string.exo_controls_fastforward_description, ACTION_FAST_FORWARD);
case NotificationConstants.SMART_REWIND_PREVIOUS:
if (player.playQueue != null && player.playQueue.size() > 1) {
return getAction(player, R.drawable.exo_notification_previous,
"Previous", ACTION_PLAY_PREVIOUS);
R.string.exo_controls_previous_description, ACTION_PLAY_PREVIOUS);
} else {
return getAction(player, R.drawable.exo_controls_rewind,
"Rewind", ACTION_FAST_REWIND);
R.string.exo_controls_rewind_description, ACTION_FAST_REWIND);
}
case NotificationConstants.SMART_FORWARD_NEXT:
if (player.playQueue != null && player.playQueue.size() > 1) {
return getAction(player, R.drawable.exo_notification_next,
"Next", ACTION_PLAY_NEXT);
R.string.exo_controls_next_description, ACTION_PLAY_NEXT);
} else {
return getAction(player, R.drawable.exo_controls_fastforward,
"Forward", ACTION_FAST_FORWARD);
R.string.exo_controls_fastforward_description, ACTION_FAST_FORWARD);
}
case NotificationConstants.PLAY_PAUSE:
final boolean pauseOrPlay = player.isPlaying()
if (player.isPlaying()
|| player.getCurrentState() == BasePlayer.STATE_PREFLIGHT
|| player.getCurrentState() == BasePlayer.STATE_BLOCKED
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING;
return getAction(player,
pauseOrPlay ? R.drawable.exo_notification_pause
: R.drawable.exo_notification_play,
pauseOrPlay ? "Pause" : "Play",
ACTION_PLAY_PAUSE);
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING) {
return getAction(player, R.drawable.exo_notification_pause,
R.string.exo_controls_pause_description, ACTION_PLAY_PAUSE);
} else {
return getAction(player, R.drawable.exo_notification_play,
R.string.exo_controls_play_description, ACTION_PLAY_PAUSE);
}
case NotificationConstants.PLAY_PAUSE_BUFFERING:
if (player.getCurrentState() == BasePlayer.STATE_PREFLIGHT
|| player.getCurrentState() == BasePlayer.STATE_BLOCKED
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING) {
return getAction(player, R.drawable.ic_hourglass_top_white_24dp_png,
"Buffering", ACTION_BUFFERING);
R.string.notification_action_buffering, ACTION_BUFFERING);
} else if (player.isPlaying()) {
return getAction(player, R.drawable.exo_notification_pause,
R.string.exo_controls_pause_description, ACTION_PLAY_PAUSE);
} else {
return getAction(player,
player.isPlaying() ? R.drawable.exo_notification_pause
: R.drawable.exo_notification_play,
player.isPlaying() ? "Pause" : "Play",
ACTION_PLAY_PAUSE);
return getAction(player, R.drawable.exo_notification_play,
R.string.exo_controls_play_description, ACTION_PLAY_PAUSE);
}
case NotificationConstants.REPEAT:
return getAction(player, getRepeatModeDrawable(player.getRepeatMode()),
getRepeatModeTitle(player.getRepeatMode()), ACTION_REPEAT);
if (player.getRepeatMode() == REPEAT_MODE_ALL) {
return getAction(player, R.drawable.exo_media_action_repeat_all,
R.string.exo_controls_repeat_all_description, ACTION_REPEAT);
} else if (player.getRepeatMode() == REPEAT_MODE_ONE) {
return getAction(player, R.drawable.exo_media_action_repeat_one,
R.string.exo_controls_repeat_one_description, ACTION_REPEAT);
} else /* player.getRepeatMode() == REPEAT_MODE_OFF */ {
return getAction(player, R.drawable.exo_media_action_repeat_off,
R.string.exo_controls_repeat_off_description, ACTION_REPEAT);
}
case NotificationConstants.SHUFFLE:
final boolean shuffled = player.playQueue != null && player.playQueue.isShuffled();
return getAction(player,
shuffled ? R.drawable.exo_controls_shuffle_on
: R.drawable.exo_controls_shuffle_off,
shuffled ? "ShuffleOn" : "ShuffleOff",
ACTION_SHUFFLE);
if (player.playQueue != null && player.playQueue.isShuffled()) {
return getAction(player, R.drawable.exo_controls_shuffle_on,
R.string.exo_controls_shuffle_on_description, ACTION_SHUFFLE);
} else {
return getAction(player, R.drawable.exo_controls_shuffle_off,
R.string.exo_controls_shuffle_off_description, ACTION_SHUFFLE);
}
case NotificationConstants.CLOSE:
return getAction(player, R.drawable.ic_close_white_24dp_png,
"Close", ACTION_CLOSE);
R.string.close, ACTION_CLOSE);
case NotificationConstants.NOTHING:
default:
@ -293,31 +308,11 @@ public final class NotificationUtil {
private NotificationCompat.Action getAction(final VideoPlayerImpl player,
@DrawableRes final int drawable,
final String title,
@StringRes final int title,
final String intentAction) {
return new NotificationCompat.Action(drawable, title, PendingIntent.getBroadcast(
player.context, NOTIFICATION_ID, new Intent(intentAction), FLAG_UPDATE_CURRENT));
}
@DrawableRes
private int getRepeatModeDrawable(final int repeatMode) {
if (repeatMode == REPEAT_MODE_ALL) {
return R.drawable.exo_controls_repeat_all;
} else if (repeatMode == REPEAT_MODE_ONE) {
return R.drawable.exo_controls_repeat_one;
} else /* repeatMode == REPEAT_MODE_OFF */ {
return R.drawable.exo_controls_repeat_off;
}
}
private String getRepeatModeTitle(final int repeatMode) {
if (repeatMode == REPEAT_MODE_ALL) {
return "RepeatAll";
} else if (repeatMode == REPEAT_MODE_ONE) {
return "RepeatOne";
} else /* repeatMode == REPEAT_MODE_OFF */ {
return "RepeatOff";
}
return new NotificationCompat.Action(drawable, player.context.getString(title),
PendingIntent.getBroadcast(player.context, NOTIFICATION_ID,
new Intent(intentAction), FLAG_UPDATE_CURRENT));
}
private Intent getIntentForNotification(final VideoPlayerImpl player) {

View File

@ -209,7 +209,7 @@ public class NotificationSettingsFragment extends Fragment {
NotificationConstants.ACTION_ICONS[selectedAction]));
}
summary.setText(NotificationConstants.ACTION_SUMMARIES[selectedAction]);
summary.setText(NotificationConstants.getActionName(requireContext(), selectedAction));
}
void openActionChooserDialog() {
@ -225,8 +225,7 @@ public class NotificationSettingsFragment extends Fragment {
.create();
final View.OnClickListener radioButtonsClickListener = v -> {
final int id = ((RadioButton) v).getId();
selectedAction = NotificationConstants.SLOT_ALLOWED_ACTIONS[i][id];
selectedAction = NotificationConstants.SLOT_ALLOWED_ACTIONS[i][v.getId()];
updateInfo();
alertDialog.dismiss();
};
@ -253,7 +252,7 @@ public class NotificationSettingsFragment extends Fragment {
}
}
radioButton.setText(NotificationConstants.ACTION_SUMMARIES[action]);
radioButton.setText(NotificationConstants.getActionName(requireContext(), action));
radioButton.setChecked(action == selectedAction);
radioButton.setId(id);
radioButton.setLayoutParams(new RadioGroup.LayoutParams(

View File

@ -12,7 +12,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_alignBaseline="@+id/autoplay_switch"
android:text="@string/next_video_title"
android:text="@string/exo_controls_next_description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="12sp"
tools:ignore="RtlHardcoded" />

View File

@ -69,16 +69,9 @@
<string name="notification_actions_summary">Edit each notification action below by tapping on it.\nSelect up to three of them to be shown in the compact notification by using the checkboxes on the right.</string>
<string name="notification_actions_at_most_three">You can select at most three actions to show in the compact notification!</string>
<string name="notification_action_previous">Previous</string>
<string name="notification_action_next">Next</string>
<string name="notification_action_rewind">Rewind</string>
<string name="notification_action_forward">Forward</string>
<string name="notification_action_smart_rewind_previous">Rewind / Previous</string>
<string name="notification_action_smart_forward_next">Forward / Next</string>
<string name="notification_action_play_pause_buffering">Play / Pause / Buffering</string>
<string name="notification_action_play_pause">Play / Pause</string>
<string name="notification_action_repeat">Repeat</string>
<string name="notification_action_shuffle">Shuffle</string>
<string name="notification_action_buffering">Buffering</string>
<string name="notification_action_nothing">Nothing</string>
<string name="play_audio">Audio</string>
@ -126,7 +119,6 @@
<string name="resume_on_audio_focus_gain_title">Resume playing</string>
<string name="resume_on_audio_focus_gain_summary">Continue playing after interruptions (e.g. phonecalls)</string>
<string name="download_dialog_title">Download</string>
<string name="next_video_title">Next</string>
<string name="autoplay_title">Autoplay</string>
<string name="show_next_and_similar_title">Show \'Next\' and \'Similar\' videos</string>
<string name="show_hold_to_append_title">Show \"Hold to append\" tip</string>
@ -159,7 +151,6 @@
<string name="background_player_append">Queued on background player</string>
<string name="popup_playing_append">Queued on popup player</string>
<string name="c3s_url" translatable="false">https://www.c3s.cc/</string>
<string name="play_btn_text">Play</string>
<string name="content">Content</string>
<string name="show_age_restricted_content_title">Age restricted content</string>
<string name="video_is_age_restricted">Show age restricted video. Future changes are possible from the settings.</string>