feat(notification-filters): implement logic and save notification filters when they are cleared

This commit is contained in:
LucasGGamerM 2023-10-01 13:56:58 -03:00
parent 8adb1d569e
commit df2211fa15
2 changed files with 42 additions and 1 deletions

View File

@ -135,7 +135,6 @@ public class NotificationsFragment extends MastodonToolbarFragment implements Sc
return true; return true;
} else if (item.getItemId() == R.id.filter_notifications) { } else if (item.getItemId() == R.id.filter_notifications) {
Context ctx = getToolbarContext(); Context ctx = getToolbarContext();
LinearLayout linearLayout = new LinearLayout(getToolbarContext());
String[] listItems = { String[] listItems = {
ctx.getString(R.string.notification_type_mentions_and_replies), ctx.getString(R.string.notification_type_mentions_and_replies),
ctx.getString(R.string.notification_type_reblog), ctx.getString(R.string.notification_type_reblog),
@ -175,6 +174,14 @@ public class NotificationsFragment extends MastodonToolbarFragment implements Sc
this.allNotificationsFragment.reload(); this.allNotificationsFragment.reload();
}).setNeutralButton(R.string.clear, (d, which) -> { }).setNeutralButton(R.string.clear, (d, which) -> {
Arrays.fill(checkedItems, true); Arrays.fill(checkedItems, true);
getLocalPrefs().notificationFilters.mention=checkedItems[0];
getLocalPrefs().notificationFilters.reblog=checkedItems[1];
getLocalPrefs().notificationFilters.favourite=checkedItems[2];
getLocalPrefs().notificationFilters.follow=checkedItems[3];
getLocalPrefs().notificationFilters.poll=checkedItems[4];
getLocalPrefs().notificationFilters.update=checkedItems[5];
getLocalPrefs().notificationFilters.status=checkedItems[6];
getLocalPrefs().save();
this.allNotificationsFragment.reload(); this.allNotificationsFragment.reload();
}).setNegativeButton(R.string.cancel, (d, which) -> {}); }).setNegativeButton(R.string.cancel, (d, which) -> {});

View File

@ -88,6 +88,40 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
@Override @Override
protected List<StatusDisplayItem> buildDisplayItems(Notification n){ protected List<StatusDisplayItem> buildDisplayItems(Notification n){
if(!onlyMentions && !onlyPosts){
switch(n.type){
case MENTION -> {
if(!getLocalPrefs().notificationFilters.mention)
return new ArrayList<>();
}
case REBLOG -> {
if(!getLocalPrefs().notificationFilters.reblog)
return new ArrayList<>();
}
case FAVORITE -> {
if(!getLocalPrefs().notificationFilters.favourite)
return new ArrayList<>();
}
case FOLLOW, FOLLOW_REQUEST -> {
if(!getLocalPrefs().notificationFilters.follow)
return new ArrayList<>();
}
case POLL -> {
if(!getLocalPrefs().notificationFilters.poll)
return new ArrayList<>();
}
case UPDATE -> {
if(!getLocalPrefs().notificationFilters.update)
return new ArrayList<>();
}
case STATUS -> {
if(!getLocalPrefs().notificationFilters.status)
return new ArrayList<>();
}
default -> {}
}
}
NotificationHeaderStatusDisplayItem titleItem; NotificationHeaderStatusDisplayItem titleItem;
if(n.type==Notification.Type.MENTION || n.type==Notification.Type.STATUS){ if(n.type==Notification.Type.MENTION || n.type==Notification.Type.STATUS){
titleItem=null; titleItem=null;