Update recently sent preferences
Test: make -j RunSettingsRoboTests Bug: 74318867 Fixes: 73004227 Change-Id: Icecf1d4f0e3dd38c96919874a7f614ed93a001ab
This commit is contained in:
@@ -7358,7 +7358,7 @@
|
||||
<string name="recent_notifications">Recently sent</string>
|
||||
|
||||
<!-- 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] -->
|
||||
<string name="advanced_section_header">Advanced</string>
|
||||
|
@@ -17,35 +17,38 @@ package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.TwoTargetPreference;
|
||||
|
||||
/**
|
||||
* 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 boolean mChecked;
|
||||
private boolean mEnableSwitch = true;
|
||||
|
||||
public NotificationAppPreference(Context context) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.preference_app);
|
||||
}
|
||||
|
||||
public NotificationAppPreference(Context context, AttributeSet 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
|
||||
@@ -53,26 +56,10 @@ public class NotificationAppPreference extends TwoTargetPreference {
|
||||
return R.layout.preference_widget_master_switch;
|
||||
}
|
||||
|
||||
public void setProgress(int amount) {
|
||||
mProgress = amount;
|
||||
mProgressVisible = true;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder 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);
|
||||
if (widgetView != null) {
|
||||
widgetView.setOnClickListener(new View.OnClickListener() {
|
||||
|
@@ -81,7 +81,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
||||
private PreferenceCategory mCategory;
|
||||
private Preference mSeeAllPref;
|
||||
private Preference mDivider;
|
||||
private boolean mHasRecentApps;
|
||||
|
||||
static {
|
||||
SKIP_SYSTEM_PACKAGES.addAll(Arrays.asList(
|
||||
@@ -142,20 +141,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
refreshUi(mCategory.getContext());
|
||||
// Show total number of installed apps as See all's summary.
|
||||
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();
|
||||
|
||||
mSeeAllPref.setTitle(mContext.getString(R.string.recent_notifications_see_all_title));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -163,10 +149,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
||||
reloadData();
|
||||
final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
|
||||
if (recentApps != null && !recentApps.isEmpty()) {
|
||||
mHasRecentApps = true;
|
||||
displayRecentApps(prefContext, recentApps);
|
||||
} else {
|
||||
mHasRecentApps = false;
|
||||
displayOnlyAllAppsLink();
|
||||
}
|
||||
}
|
||||
@@ -228,7 +212,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
||||
pref.setTitle(appEntry.label);
|
||||
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
|
||||
pref.setSummary(StringUtil.formatRelativeTime(mContext,
|
||||
System.currentTimeMillis() - app.getLastNotified(), false));
|
||||
System.currentTimeMillis() - app.getLastNotified(), true));
|
||||
pref.setOrder(i);
|
||||
Bundle args = new Bundle();
|
||||
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
|
||||
|
@@ -211,28 +211,4 @@ public class NotificationAppPreferenceTest {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -290,7 +290,7 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
||||
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user