use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project android_packages_apps_Settings by omnirom.
the class ChannelListPreferenceControllerTest method testUpdateFullList_channelUpdates.
@Test
@UiThreadTest
public void testUpdateFullList_channelUpdates() {
List<NotificationChannelGroup> inGroups = new ArrayList<>();
NotificationChannelGroup inGroup = new NotificationChannelGroup("group", "Group");
NotificationChannel channelA = new NotificationChannel("channelA", "Channel A", IMPORTANCE_HIGH);
NotificationChannel channelB = new NotificationChannel("channelB", "Channel B", IMPORTANCE_NONE);
inGroup.addChannel(channelA);
inGroup.addChannel(channelB);
inGroups.add(inGroup);
NotificationsSentState sentA = new NotificationsSentState();
sentA.avgSentDaily = 2;
sentA.avgSentWeekly = 10;
NotificationsSentState sentB = new NotificationsSentState();
sentB.avgSentDaily = 0;
sentB.avgSentWeekly = 2;
mAppRow.sentByChannel.put("channelA", sentA);
// Test that the channels' properties are reflected in the preference
mController.updateFullList(mGroupList, inGroups);
{
assertEquals(1, mGroupList.getPreferenceCount());
PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
assertEquals("group", group.getKey());
assertEquals(3, group.getPreferenceCount());
assertNull(group.getPreference(0).getKey());
assertEquals("All \"Group\" notifications", group.getPreference(0).getTitle());
PrimarySwitchPreference channelAPref = (PrimarySwitchPreference) group.getPreference(1);
assertEquals("channelA", channelAPref.getKey());
assertEquals("Channel A", channelAPref.getTitle());
assertEquals(Boolean.TRUE, channelAPref.getCheckedState());
assertEquals("~2 notifications per day", channelAPref.getSummary());
assertNotNull(channelAPref.getIcon());
PrimarySwitchPreference channelBPref = (PrimarySwitchPreference) group.getPreference(2);
assertEquals("channelB", channelBPref.getKey());
assertEquals("Channel B", channelBPref.getTitle());
assertEquals(Boolean.FALSE, channelBPref.getCheckedState());
assertNull(channelBPref.getSummary());
assertNull(channelBPref.getIcon());
}
channelA.setImportance(IMPORTANCE_NONE);
channelB.setImportance(IMPORTANCE_DEFAULT);
mAppRow.sentByChannel.remove("channelA");
mAppRow.sentByChannel.put("channelB", sentB);
// Test that changing the channels' properties correctly updates the preference
mController.updateFullList(mGroupList, inGroups);
{
assertEquals(1, mGroupList.getPreferenceCount());
PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
assertEquals("group", group.getKey());
assertEquals(3, group.getPreferenceCount());
assertNull(group.getPreference(0).getKey());
assertEquals("All \"Group\" notifications", group.getPreference(0).getTitle());
PrimarySwitchPreference channelAPref = (PrimarySwitchPreference) group.getPreference(1);
assertEquals("channelA", channelAPref.getKey());
assertEquals("Channel A", channelAPref.getTitle());
assertEquals(Boolean.FALSE, channelAPref.getCheckedState());
assertNull(channelAPref.getSummary());
assertNull(channelAPref.getIcon());
PrimarySwitchPreference channelBPref = (PrimarySwitchPreference) group.getPreference(2);
assertEquals("channelB", channelBPref.getKey());
assertEquals("Channel B", channelBPref.getTitle());
assertEquals(Boolean.TRUE, channelBPref.getCheckedState());
assertEquals("~2 notifications per week", channelBPref.getSummary());
assertNotNull(channelBPref.getIcon());
}
}
use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NotificationChannelSliceTest method buildAppRow.
private AppRow buildAppRow(int channelCount, int sentCount, boolean banned) {
final AppRow appRow = new AppRow();
appRow.pkg = PACKAGE_NAME;
appRow.uid = UID;
appRow.banned = banned;
appRow.channelCount = channelCount;
appRow.sentByApp = new NotificationsSentState();
appRow.sentByApp.sentCount = sentCount;
appRow.sentByChannel = buildNotificationSentStates(channelCount, sentCount);
return appRow;
}
use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NotificationChannelSliceTest method buildNotificationSentStates.
private Map<String, NotificationsSentState> buildNotificationSentStates(int channelCount, int sentCount) {
final Map<String, NotificationBackend.NotificationsSentState> states = new ArrayMap<>();
for (int i = 0; i < channelCount; i++) {
final NotificationsSentState state = new NotificationsSentState();
// Set the avgSentWeekly for each channel: channel0 is 1, channel1: 2, channel2: 3.
state.avgSentWeekly = i + 1;
state.sentCount = sentCount;
states.put(CHANNEL_NAME_PREFIX + i, state);
}
return states;
}
use of com.android.settings.notification.NotificationBackend.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NotificationChannelSlice method getDisplayableChannels.
private List<NotificationChannel> getDisplayableChannels(NotificationBackend.AppRow appRow) {
final List<NotificationChannelGroup> channelGroupList = mNotificationBackend.getGroups(appRow.pkg, appRow.uid).getList();
final List<NotificationChannel> channels = channelGroupList.stream().flatMap(group -> group.getChannels().stream().filter(channel -> isChannelEnabled(group, channel, appRow))).collect(Collectors.toList());
// Pack the notification channel with notification sent state for sorting.
final List<NotificationChannelState> channelStates = new ArrayList<>();
for (NotificationChannel channel : channels) {
NotificationsSentState sentState = appRow.sentByChannel.get(channel.getId());
if (sentState == null) {
sentState = new NotificationsSentState();
}
channelStates.add(new NotificationChannelState(sentState, channel));
}
// Sort the notification channels with notification sent count by descending.
return channelStates.stream().sorted(CHANNEL_STATE_COMPARATOR).map(state -> state.getNotificationChannel()).limit(DEFAULT_EXPANDED_ROW_COUNT).collect(Collectors.toList());
}
Aggregations