diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/NotificationsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/NotificationsFragment.java new file mode 100644 index 000000000..75d9d9326 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/NotificationsFragment.java @@ -0,0 +1,25 @@ +package org.joinmastodon.android.fragments.settings; + +import org.joinmastodon.android.R; +import org.joinmastodon.android.model.PushNotification; +import org.joinmastodon.android.model.PushSubscription; + +import java.util.ArrayList; + +public class NotificationsFragment extends SettingsBaseFragment { + @Override + public void addItems(ArrayList items) { + items.add(notificationPolicyItem = new NotificationPolicyItem()); + PushSubscription pushSubscription = getPushSubscription(); + boolean switchEnabled = pushSubscription.policy != PushSubscription.Policy.NONE; + + items.add(new SwitchItem(R.string.notify_favorites, R.drawable.ic_fluent_star_24_regular, pushSubscription.alerts.favourite, i -> onNotificationsChanged(PushNotification.Type.FAVORITE, i.checked), switchEnabled)); + items.add(new SwitchItem(R.string.notify_follow, R.drawable.ic_fluent_person_add_24_regular, pushSubscription.alerts.follow, i -> onNotificationsChanged(PushNotification.Type.FOLLOW, i.checked), switchEnabled)); + items.add(new SwitchItem(R.string.notify_reblog, R.drawable.ic_fluent_arrow_repeat_all_24_regular, pushSubscription.alerts.reblog, i -> onNotificationsChanged(PushNotification.Type.REBLOG, i.checked), switchEnabled)); + items.add(new SwitchItem(R.string.notify_mention, R.drawable.ic_fluent_mention_24_regular, pushSubscription.alerts.mention, i -> onNotificationsChanged(PushNotification.Type.MENTION, i.checked), switchEnabled)); + items.add(new SwitchItem(R.string.sk_notify_posts, R.drawable.ic_fluent_chat_24_regular, pushSubscription.alerts.status, i -> onNotificationsChanged(PushNotification.Type.STATUS, i.checked), switchEnabled)); + items.add(new SwitchItem(R.string.sk_notify_update, R.drawable.ic_fluent_history_24_regular, pushSubscription.alerts.update, i -> onNotificationsChanged(PushNotification.Type.UPDATE, i.checked), switchEnabled)); + items.add(new SwitchItem(R.string.sk_notify_poll_results, R.drawable.ic_fluent_poll_24_regular, pushSubscription.alerts.poll, i -> onNotificationsChanged(PushNotification.Type.POLL, i.checked), switchEnabled)); + + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java index 4e4d4f6b0..0810cdcf0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java @@ -505,7 +505,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple onNotificationsChanged(value, newState); } index++; - while(items.get(index) instanceof SwitchItem si){ + while(items.size() > index && items.get(index) instanceof SwitchItem si){ si.enabled=si.checked=newState; RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(index); if(holder!=null) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java index 64141cca3..d9dad5c5c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java @@ -10,5 +10,6 @@ public class SettingsMainFragment extends SettingsBaseFragment{ items.add(new SettingsCategoryItem(R.string.settings_theme, SettingsAppearanceFragment.class, R.drawable.ic_fluent_color_24_regular)); items.add(new SettingsCategoryItem(R.string.settings_behavior, BehaviourFragment.class, R.drawable.ic_fluent_chat_settings_24_regular)); items.add(new SettingsCategoryItem(R.string.sk_timelines, TimeLineFragment.class, R.drawable.ic_fluent_timeline_24_regular)); + items.add(new SettingsCategoryItem(R.string.settings_notifications, NotificationsFragment.class, R.drawable.ic_fluent_alert_28_regular_badged)); } }