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

Commit 5c83f14d authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Update recently sent preferences

Test: make -j RunSettingsRoboTests
Bug: 74318867
Fixes: 73004227
Change-Id: Icecf1d4f0e3dd38c96919874a7f614ed93a001ab
parent 396e91ab
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -7358,7 +7358,7 @@
    <string name="recent_notifications">Recently sent</string>
    <string name="recent_notifications">Recently sent</string>
    <!-- Preference title for showing all apps on device [CHAR_LIMIT=50]-->
    <!-- Preference title for showing all apps on device [CHAR_LIMIT=50]-->
    <string name="recent_notifications_see_all_title">See all apps</string>
    <string name="recent_notifications_see_all_title">See all from last 7 days</string>
    <!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] -->
    <!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] -->
    <string name="advanced_section_header">Advanced</string>
    <string name="advanced_section_header">Advanced</string>
+11 −24
Original line number Original line Diff line number Diff line
@@ -17,35 +17,38 @@ package com.android.settings.notification;


import android.content.Context;
import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.View;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.Switch;


import com.android.settings.R;
import com.android.settings.R;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.TwoTargetPreference;


/**
/**
 * Shows an app icon, title and summary. Has a second switch touch target.
 * Shows an app icon, title and summary. Has a second switch touch target.
 */
 */
public class NotificationAppPreference extends TwoTargetPreference {
public class NotificationAppPreference extends MasterSwitchPreference {


    private int mProgress;
    private boolean mProgressVisible;
    private Switch mSwitch;
    private Switch mSwitch;
    private boolean mChecked;
    private boolean mChecked;
    private boolean mEnableSwitch = true;
    private boolean mEnableSwitch = true;


    public NotificationAppPreference(Context context) {
    public NotificationAppPreference(Context context) {
        super(context);
        super(context);
        setLayoutResource(R.layout.preference_app);
    }
    }


    public NotificationAppPreference(Context context, AttributeSet attrs) {
    public NotificationAppPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        super(context, attrs);
        setLayoutResource(R.layout.preference_app);
    }

    public NotificationAppPreference(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public NotificationAppPreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    }


    @Override
    @Override
@@ -53,26 +56,10 @@ public class NotificationAppPreference extends TwoTargetPreference {
        return R.layout.preference_widget_master_switch;
        return R.layout.preference_widget_master_switch;
    }
    }


    public void setProgress(int amount) {
        mProgress = amount;
        mProgressVisible = true;
        notifyChanged();
    }

    @Override
    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);
        super.onBindViewHolder(view);


        view.findViewById(R.id.summary_container)
                .setVisibility(TextUtils.isEmpty(getSummary()) ? View.GONE : View.VISIBLE);
        final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
        if (mProgressVisible) {
            progress.setProgress(mProgress);
            progress.setVisibility(View.VISIBLE);
        } else {
            progress.setVisibility(View.GONE);
        }

        final View widgetView = view.findViewById(android.R.id.widget_frame);
        final View widgetView = view.findViewById(android.R.id.widget_frame);
        if (widgetView != null) {
        if (widgetView != null) {
            widgetView.setOnClickListener(new View.OnClickListener() {
            widgetView.setOnClickListener(new View.OnClickListener() {
+2 −18
Original line number Original line Diff line number Diff line
@@ -81,7 +81,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
    private PreferenceCategory mCategory;
    private PreferenceCategory mCategory;
    private Preference mSeeAllPref;
    private Preference mSeeAllPref;
    private Preference mDivider;
    private Preference mDivider;
    private boolean mHasRecentApps;


    static {
    static {
        SKIP_SYSTEM_PACKAGES.addAll(Arrays.asList(
        SKIP_SYSTEM_PACKAGES.addAll(Arrays.asList(
@@ -142,20 +141,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
    public void updateState(Preference preference) {
    public void updateState(Preference preference) {
        super.updateState(preference);
        super.updateState(preference);
        refreshUi(mCategory.getContext());
        refreshUi(mCategory.getContext());
        // Show total number of installed apps as See all's summary.
        mSeeAllPref.setTitle(mContext.getString(R.string.recent_notifications_see_all_title));
        new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
                new PackageManagerWrapper(mContext.getPackageManager())) {
            @Override
            protected void onCountComplete(int num) {
                if (mHasRecentApps) {
                    mSeeAllPref.setTitle(
                            mContext.getString(R.string.recent_notifications_see_all_title));
                } else {
                    mSeeAllPref.setSummary(mContext.getString(R.string.apps_summary, num));
                }
            }
        }.execute();

    }
    }


    @VisibleForTesting
    @VisibleForTesting
@@ -163,10 +149,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
        reloadData();
        reloadData();
        final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
        final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
        if (recentApps != null && !recentApps.isEmpty()) {
        if (recentApps != null && !recentApps.isEmpty()) {
            mHasRecentApps = true;
            displayRecentApps(prefContext, recentApps);
            displayRecentApps(prefContext, recentApps);
        } else {
        } else {
            mHasRecentApps = false;
            displayOnlyAllAppsLink();
            displayOnlyAllAppsLink();
        }
        }
    }
    }
@@ -228,7 +212,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
            pref.setTitle(appEntry.label);
            pref.setTitle(appEntry.label);
            pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
            pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
            pref.setSummary(StringUtil.formatRelativeTime(mContext,
            pref.setSummary(StringUtil.formatRelativeTime(mContext,
                    System.currentTimeMillis() - app.getLastNotified(), false));
                    System.currentTimeMillis() - app.getLastNotified(), true));
            pref.setOrder(i);
            pref.setOrder(i);
            Bundle args = new Bundle();
            Bundle args = new Bundle();
            args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
            args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
+0 −24
Original line number Original line Diff line number Diff line
@@ -211,28 +211,4 @@ public class NotificationAppPreferenceTest {


        assertThat(toggle.getContentDescription()).isEqualTo(label);
        assertThat(toggle.getContentDescription()).isEqualTo(label);
    }
    }

    @Test
    public void setSummary_showSummaryContainer() {
        final NotificationAppPreference preference = new NotificationAppPreference(mContext);
        View rootView = View.inflate(mContext, R.layout.preference_app, null /* parent */);
        PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(rootView);
        preference.setSummary("test");
        preference.onBindViewHolder(holder);

        assertThat(holder.findViewById(R.id.summary_container).getVisibility())
                .isEqualTo(View.VISIBLE);
    }

    @Test
    public void noSummary_hideSummaryContainer() {
        final NotificationAppPreference preference = new NotificationAppPreference(mContext);
        View rootView = View.inflate(mContext, R.layout.preference_app, null /* parent */);
        PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(rootView);
        preference.setSummary(null);
        preference.onBindViewHolder(holder);

        assertThat(holder.findViewById(R.id.summary_container).getVisibility())
                .isEqualTo(View.GONE);
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -290,7 +290,7 @@ public class RecentNotifyingAppsPreferenceControllerTest {


        mController.displayPreference(mScreen);
        mController.displayPreference(mScreen);


        verify(mCategory).addPreference(argThat(summaryMatches("0 minutes ago")));
        verify(mCategory).addPreference(argThat(summaryMatches("Just now")));
    }
    }


    private static ArgumentMatcher<Preference> summaryMatches(String expected) {
    private static ArgumentMatcher<Preference> summaryMatches(String expected) {