mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
Customize only 2 notification actions on Android 13+
This commit is contained in:
parent
5a4dae2070
commit
30f0db1d28
@ -6,6 +6,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -35,6 +36,7 @@ import org.schabi.newpipe.util.ThemeHelper;
|
|||||||
import org.schabi.newpipe.views.FocusOverlayView;
|
import org.schabi.newpipe.views.FocusOverlayView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class NotificationActionsPreference extends Preference {
|
public class NotificationActionsPreference extends Preference {
|
||||||
@ -56,6 +58,11 @@ public class NotificationActionsPreference extends Preference {
|
|||||||
public void onBindViewHolder(@NonNull final PreferenceViewHolder holder) {
|
public void onBindViewHolder(@NonNull final PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(holder);
|
super.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
((TextView) holder.itemView.findViewById(R.id.summary))
|
||||||
|
.setText(R.string.notification_actions_summary_android13);
|
||||||
|
}
|
||||||
|
|
||||||
holder.itemView.setClickable(false);
|
holder.itemView.setClickable(false);
|
||||||
setupActions(holder.itemView);
|
setupActions(holder.itemView);
|
||||||
}
|
}
|
||||||
@ -137,11 +144,19 @@ public class NotificationActionsPreference extends Preference {
|
|||||||
|
|
||||||
NotificationSlot(final int actionIndex, final View parentView) {
|
NotificationSlot(final int actionIndex, final View parentView) {
|
||||||
this.i = actionIndex;
|
this.i = actionIndex;
|
||||||
|
selectedAction = Objects.requireNonNull(getSharedPreferences()).getInt(
|
||||||
|
getContext().getString(NotificationConstants.SLOT_PREF_KEYS[i]),
|
||||||
|
NotificationConstants.SLOT_DEFAULTS[i]);
|
||||||
final View view = parentView.findViewById(SLOT_ITEMS[i]);
|
final View view = parentView.findViewById(SLOT_ITEMS[i]);
|
||||||
|
|
||||||
|
// only show the last two notification slots on Android 13+
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || i >= 3) {
|
||||||
setupSelectedAction(view);
|
setupSelectedAction(view);
|
||||||
setupTitle(view);
|
setupTitle(view);
|
||||||
setupCheckbox(view);
|
setupCheckbox(view);
|
||||||
|
} else {
|
||||||
|
view.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupTitle(final View view) {
|
void setupTitle(final View view) {
|
||||||
@ -153,6 +168,14 @@ public class NotificationActionsPreference extends Preference {
|
|||||||
|
|
||||||
void setupCheckbox(final View view) {
|
void setupCheckbox(final View view) {
|
||||||
final CheckBox compactSlotCheckBox = view.findViewById(R.id.notificationActionCheckBox);
|
final CheckBox compactSlotCheckBox = view.findViewById(R.id.notificationActionCheckBox);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
// there are no compact slots to customize on Android 33+
|
||||||
|
compactSlotCheckBox.setVisibility(View.GONE);
|
||||||
|
view.findViewById(R.id.notificationActionCheckBoxClickableArea)
|
||||||
|
.setVisibility(View.GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
compactSlotCheckBox.setChecked(compactSlots.contains(i));
|
compactSlotCheckBox.setChecked(compactSlots.contains(i));
|
||||||
view.findViewById(R.id.notificationActionCheckBoxClickableArea).setOnClickListener(
|
view.findViewById(R.id.notificationActionCheckBoxClickableArea).setOnClickListener(
|
||||||
v -> {
|
v -> {
|
||||||
@ -174,9 +197,6 @@ public class NotificationActionsPreference extends Preference {
|
|||||||
void setupSelectedAction(final View view) {
|
void setupSelectedAction(final View view) {
|
||||||
icon = view.findViewById(R.id.notificationActionIcon);
|
icon = view.findViewById(R.id.notificationActionIcon);
|
||||||
summary = view.findViewById(R.id.notificationActionSummary);
|
summary = view.findViewById(R.id.notificationActionSummary);
|
||||||
selectedAction = getSharedPreferences().getInt(
|
|
||||||
getContext().getString(NotificationConstants.SLOT_PREF_KEYS[i]),
|
|
||||||
NotificationConstants.SLOT_DEFAULTS[i]);
|
|
||||||
updateInfo();
|
updateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
android:paddingTop="16dp">
|
android:paddingTop="16dp">
|
||||||
|
|
||||||
<org.schabi.newpipe.views.NewPipeTextView
|
<org.schabi.newpipe.views.NewPipeTextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/summary"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
@ -29,7 +29,7 @@
|
|||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
app:layout_constraintTop_toBottomOf="@+id/summary" />
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/notificationAction1"
|
android:id="@+id/notificationAction1"
|
||||||
|
@ -57,7 +57,8 @@
|
|||||||
<string name="notification_action_2_title">Third action button</string>
|
<string name="notification_action_2_title">Third action button</string>
|
||||||
<string name="notification_action_3_title">Fourth action button</string>
|
<string name="notification_action_3_title">Fourth action button</string>
|
||||||
<string name="notification_action_4_title">Fifth action button</string>
|
<string name="notification_action_4_title">Fifth action button</string>
|
||||||
<string name="notification_actions_summary">Edit each notification action below by tapping on it. Select up to three of them to be shown in the compact notification by using the checkboxes on the right</string>
|
<string name="notification_actions_summary">Edit each notification action below by tapping on it. Select up to three of them to be shown in the compact notification by using the checkboxes on the right.</string>
|
||||||
|
<string name="notification_actions_summary_android13">Edit each notification action below by tapping on it. The first three actions (play/pause, previous and next) are set by the system and cannot be customized.</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_actions_at_most_three">You can select at most three actions to show in the compact notification!</string>
|
||||||
<string name="notification_action_repeat">Repeat</string>
|
<string name="notification_action_repeat">Repeat</string>
|
||||||
<string name="notification_action_shuffle">Shuffle</string>
|
<string name="notification_action_shuffle">Shuffle</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user