diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 2a23aed5f..3a520e2a0 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -1079,6 +1079,7 @@ public abstract class BaseMainActivity extends BaseActivity editor.putBoolean(Helper.SET_NOTIF_ASK, set_push_notification.isChecked()); editor.putBoolean(Helper.SET_NOTIF_MENTION, set_push_notification.isChecked()); editor.putBoolean(Helper.SET_NOTIF_SHARE, set_push_notification.isChecked()); + editor.putBoolean(Helper.SET_NOTIF_POLL, set_push_notification.isChecked()); // editor.putBoolean(Helper.SET_NOTIF_HOMETIMELINE, set_push_hometimeline.isChecked()); editor.putBoolean(Helper.SET_POPUP_PUSH, true); editor.apply(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index f41cee810..9f6dd666b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -458,6 +458,7 @@ public class Helper { MENTION, BOOST, FAV, + POLL, BACKUP, STORE, TOOT @@ -1012,6 +1013,10 @@ public class Helper { channelId = "channel_mention"; channelTitle = context.getString(R.string.channel_notif_mention); break; + case POLL: + channelId = "channel_poll"; + channelTitle = context.getString(R.string.channel_notif_poll); + break; case BACKUP: channelId = "channel_backup"; channelTitle = context.getString(R.string.channel_notif_backup); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java index b4c1e091a..15f39dd73 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java @@ -118,8 +118,9 @@ public class NotificationsSyncJob extends Job { boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true); //User disagree with all notifications - if( !notif_follow && !notif_add && !notif_mention && !notif_share) + if( !notif_follow && !notif_add && !notif_mention && !notif_share && !notif_poll) return; //Nothing is done //No account connected, the service is stopped if(!Helper.isLoggedIn(getContext())) @@ -151,6 +152,7 @@ public class NotificationsSyncJob extends Job { boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true); final String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); final List notifications = new ArrayList<>(); int pos = 0; @@ -167,6 +169,7 @@ public class NotificationsSyncJob extends Job { int newAdds = 0; int newMentions = 0; int newShare = 0; + int newPolls = 0; String notificationUrl = null; String title = null; final String message; @@ -229,11 +232,25 @@ public class NotificationsSyncJob extends Job { } } break; + case "poll": + notifType = Helper.NotifType.POLL; + if(notif_poll){ + newPolls++; + if( notificationUrl == null){ + notificationUrl = notification.getAccount().getAvatar(); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + if (notification.getAccount().getId() != null && notification.getAccount().getId().equals(userId)) + title = getContext().getString(R.string.notif_poll_self); + else + title = getContext().getString(R.string.notif_poll); + } + } + break; default: } } - int allNotifCount = newFollows + newAdds + newMentions + newShare; + int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls; if( allNotifCount > 0){ //Some others notification int other = allNotifCount -1; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java index 9645944cd..30c75aaee 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java @@ -327,7 +327,8 @@ public class LiveNotificationService extends Service implements NetworkStateRece boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); - boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share); + boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true); + boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll); String title = null; if (somethingToPush && notification != null) { switch (notification.getType()) { @@ -376,6 +377,17 @@ public class LiveNotificationService extends Service implements NetworkStateRece canSendBroadCast = false; } break; + case "poll": + notifType = Helper.NotifType.POLL; + if (notif_poll) { + if (notification.getAccount().getId() != null && notification.getAccount().getId().equals(userId)) + title = getString(R.string.notif_poll_self); + else + title = getString(R.string.notif_poll); + } else { + canSendBroadCast = false; + } + break; default: } //Some others notification diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 877c3b966..36f14e239 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -918,6 +918,7 @@ Vote A poll cannot be attached to a direct message! A poll you have voted in has ended + A poll you tooted has ended Customize Categories News