Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3372369 authored by Yining Liu's avatar Yining Liu Committed by Android (Google) Code Review
Browse files

Merge "Update title texts for the lockscreen show viewed toggle" into main

parents 9444eed6 9c3f286e
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -9352,8 +9352,11 @@ Data usage charges may apply.</string>
    <!-- Notification Settings > Notifications on lock screen > Title for showing notifications on the lock screen. [CHAR LIMIT=100] -->
    <string name="lockscreen_notification_what_to_show_title">What to show on lock screen</string>
    <!-- Notification Settings > Notifications on lock screen > Title for showing seen notifications toggle. [CHAR LIMIT=60] -->
    <string name="lock_screen_notification_show_seen_title">Show seen notifications</string>
    <!-- Notification Settings > Notifications on lock screen > Title for showing viewed notifications toggle at full list mode. [CHAR LIMIT=NONE] -->
    <string name="lock_screen_notification_show_viewed_notifs">Show viewed notifications</string>
    <!-- Notification Settings > Notifications on lock screen > Title for showing seen notifications toggle at compact mode. [CHAR LIMIT=NONE] -->
    <string name="lock_screen_notification_show_viewed_notif_icons">Show viewed notification icons</string>
    <!-- Notification Settings > Notifications on lock screen > Title for hiding silent notifications toggle. [CHAR LIMIT=60] -->
    <string name="lock_screen_notification_show_silent_title">Show silent notifications</string>
+2 −3
Original line number Diff line number Diff line
@@ -50,9 +50,8 @@
        settings:controller="com.android.settings.notification.LockScreenWhatToShowController">

        <SwitchPreferenceCompat
            android:key="lock_screen_notification_show_seen_toggle"
            android:title="@string/lock_screen_notification_show_seen_title"
            settings:controller="com.android.settings.notification.LockScreenNotificationShowSeenController" />
            android:key="lock_screen_notification_show_viewed_toggle"
            settings:controller="com.android.settings.notification.LockScreenNotificationShowViewedController" />

        <SwitchPreferenceCompat
            android:key="lock_screen_notification_show_silent_toggle"
+32 −2
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.settings.notification;

import static android.provider.Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM;
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS;

import static com.android.settings.notification.lockscreen.MinimalismPreferenceController.LS_MINIMALISM_ON;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -35,13 +38,14 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.server.notification.Flags;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;

/**
 * Controls the toggle that determines whether to hide seen notifications from the lock screen.
 * Toggle for setting: Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS
 */
public class LockScreenNotificationShowSeenController extends TogglePreferenceController
public class LockScreenNotificationShowViewedController extends TogglePreferenceController
        implements LifecycleEventObserver {

    // 0 is the default value for phones, we treat 0 as off as usage
@@ -60,7 +64,7 @@ public class LockScreenNotificationShowSeenController extends TogglePreferenceCo
        }
    };

    public LockScreenNotificationShowSeenController(@NonNull Context context,
    public LockScreenNotificationShowViewedController(@NonNull Context context,
            @NonNull String preferenceKey) {
        super(context, preferenceKey);
        mContentResolver = context.getContentResolver();
@@ -70,6 +74,9 @@ public class LockScreenNotificationShowSeenController extends TogglePreferenceCo
    public void displayPreference(@NonNull PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
        if (mPreference != null) {
            mPreference.setTitle(getTitleResForState());
        }
    }

    @Override
@@ -85,6 +92,11 @@ public class LockScreenNotificationShowSeenController extends TogglePreferenceCo
                    /* notifyForDescendants= */ false,
                    mContentObserver
            );
            mContentResolver.registerContentObserver(
                    Settings.Secure.getUriFor(LOCK_SCREEN_NOTIFICATION_MINIMALISM),
                    /* notifyForDescendants= */ false,
                    mContentObserver
            );
        } else if (event == Lifecycle.Event.ON_PAUSE) {
            mContentResolver.unregisterContentObserver(mContentObserver);
        }
@@ -95,6 +107,24 @@ public class LockScreenNotificationShowSeenController extends TogglePreferenceCo
        super.updateState(preference);
        setChecked(lockScreenShowSeenNotifications());
        preference.setVisible(isAvailable());
        preference.setTitle(getTitleResForState());
    }

    private int getTitleResForState() {
        if (lockScreenMinimalism()) {
            return R.string.lock_screen_notification_show_viewed_notif_icons;
        } else {
            return R.string.lock_screen_notification_show_viewed_notifs;
        }
    }

    /**
     * @return whether to show seen notifications on lockscreen
     */
    private boolean lockScreenMinimalism() {
        if (!Flags.notificationMinimalism()) return false;
        return Settings.Secure.getInt(mContext.getContentResolver(),
                LOCK_SCREEN_NOTIFICATION_MINIMALISM, LS_MINIMALISM_ON) == LS_MINIMALISM_ON;
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class MinimalismPreferenceController
    private static final int LS_SHOW_NOTIF_ON = 1;
    private static final int LS_SHOW_NOTIF_OFF = 0;
    private static final int LS_MINIMALISM_OFF = 0;
    private static final int LS_MINIMALISM_ON = 1;
    public static final int LS_MINIMALISM_ON = 1;
    private static final String KEY_MINIMALISM_PREFERENCE = "ls_minimalism";
    private static final String KEY_FULL_LIST_ILLUSTRATION = "full_list_illustration";
    private static final String KEY_COMPACT_ILLUSTRATION = "compact_illustration";