Skip to content

Commit 30f0db1

Browse files
committed
Customize only 2 notification actions on Android 13+
1 parent 5a4dae2 commit 30f0db1

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

app/src/main/java/org/schabi/newpipe/settings/custom/NotificationActionsPreference.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.Intent;
77
import android.content.SharedPreferences;
88
import android.content.res.ColorStateList;
9+
import android.os.Build;
910
import android.util.AttributeSet;
1011
import android.view.LayoutInflater;
1112
import android.view.View;
@@ -35,6 +36,7 @@
3536
import org.schabi.newpipe.views.FocusOverlayView;
3637

3738
import java.util.List;
39+
import java.util.Objects;
3840
import java.util.stream.IntStream;
3941

4042
public class NotificationActionsPreference extends Preference {
@@ -56,6 +58,11 @@ public NotificationActionsPreference(final Context context, final AttributeSet a
5658
public void onBindViewHolder(@NonNull final PreferenceViewHolder holder) {
5759
super.onBindViewHolder(holder);
5860

61+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
62+
((TextView) holder.itemView.findViewById(R.id.summary))
63+
.setText(R.string.notification_actions_summary_android13);
64+
}
65+
5966
holder.itemView.setClickable(false);
6067
setupActions(holder.itemView);
6168
}
@@ -137,11 +144,19 @@ private class NotificationSlot {
137144

138145
NotificationSlot(final int actionIndex, final View parentView) {
139146
this.i = actionIndex;
140-
147+
selectedAction = Objects.requireNonNull(getSharedPreferences()).getInt(
148+
getContext().getString(NotificationConstants.SLOT_PREF_KEYS[i]),
149+
NotificationConstants.SLOT_DEFAULTS[i]);
141150
final View view = parentView.findViewById(SLOT_ITEMS[i]);
142-
setupSelectedAction(view);
143-
setupTitle(view);
144-
setupCheckbox(view);
151+
152+
// only show the last two notification slots on Android 13+
153+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || i >= 3) {
154+
setupSelectedAction(view);
155+
setupTitle(view);
156+
setupCheckbox(view);
157+
} else {
158+
view.setVisibility(View.GONE);
159+
}
145160
}
146161

147162
void setupTitle(final View view) {
@@ -153,6 +168,14 @@ void setupTitle(final View view) {
153168

154169
void setupCheckbox(final View view) {
155170
final CheckBox compactSlotCheckBox = view.findViewById(R.id.notificationActionCheckBox);
171+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
172+
// there are no compact slots to customize on Android 33+
173+
compactSlotCheckBox.setVisibility(View.GONE);
174+
view.findViewById(R.id.notificationActionCheckBoxClickableArea)
175+
.setVisibility(View.GONE);
176+
return;
177+
}
178+
156179
compactSlotCheckBox.setChecked(compactSlots.contains(i));
157180
view.findViewById(R.id.notificationActionCheckBoxClickableArea).setOnClickListener(
158181
v -> {
@@ -174,9 +197,6 @@ void setupCheckbox(final View view) {
174197
void setupSelectedAction(final View view) {
175198
icon = view.findViewById(R.id.notificationActionIcon);
176199
summary = view.findViewById(R.id.notificationActionSummary);
177-
selectedAction = getSharedPreferences().getInt(
178-
getContext().getString(NotificationConstants.SLOT_PREF_KEYS[i]),
179-
NotificationConstants.SLOT_DEFAULTS[i]);
180200
updateInfo();
181201
}
182202

app/src/main/res/layout/settings_notification.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:paddingTop="16dp">
88

99
<org.schabi.newpipe.views.NewPipeTextView
10-
android:id="@+id/textView"
10+
android:id="@+id/summary"
1111
android:layout_width="0dp"
1212
android:layout_height="wrap_content"
1313
android:layout_marginStart="16dp"
@@ -29,7 +29,7 @@
2929
android:layout_marginTop="8dp"
3030
app:layout_constraintEnd_toEndOf="parent"
3131
app:layout_constraintStart_toStartOf="parent"
32-
app:layout_constraintTop_toBottomOf="@+id/textView" />
32+
app:layout_constraintTop_toBottomOf="@+id/summary" />
3333

3434
<include
3535
android:id="@+id/notificationAction1"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
<string name="notification_action_2_title">Third action button</string>
5858
<string name="notification_action_3_title">Fourth action button</string>
5959
<string name="notification_action_4_title">Fifth action button</string>
60-
<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>
60+
<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>
61+
<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>
6162
<string name="notification_actions_at_most_three">You can select at most three actions to show in the compact notification!</string>
6263
<string name="notification_action_repeat">Repeat</string>
6364
<string name="notification_action_shuffle">Shuffle</string>

0 commit comments

Comments
 (0)