From 1198664c6fc256d1f0e0a096b0af34fa1da98c7f Mon Sep 17 00:00:00 2001 From: Kasun Date: Sat, 4 May 2019 16:38:23 +0530 Subject: [PATCH] poll notifications 3/3 add polls filter to notifications tab --- .../java/fr/gouv/etalab/mastodon/client/API.java | 6 +++++- .../client/Entities/ManageTimelines.java | 16 +++++++++++++++- .../fr/gouv/etalab/mastodon/helper/Helper.java | 1 + .../res/menu/option_filter_notifications.xml | 6 ++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 956908163..880dbbedf 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -2396,7 +2396,7 @@ public class API { return apiResponse; } final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean notif_follow, notif_add, notif_mention, notif_share; + boolean notif_follow, notif_add, notif_mention, notif_share, notif_poll; StringBuilder parameters = new StringBuilder(); if( type == DisplayNotificationsFragment.Type.ALL){ if( display) { @@ -2404,11 +2404,13 @@ public class API { notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true); notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true); notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true); + notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL_FILTER, true); }else{ notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true); } @@ -2420,6 +2422,8 @@ public class API { parameters.append("exclude_types[]=").append("reblog").append("&"); if( !notif_mention ) parameters.append("exclude_types[]=").append("mention").append("&"); + if( !notif_poll ) + parameters.append("exclude_types[]=").append("poll").append("&"); if( parameters.length() > 0) { parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16)); params.put("exclude_types[]", parameters.toString()); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/ManageTimelines.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/ManageTimelines.java index 476138c35..f4312bb96 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/ManageTimelines.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/ManageTimelines.java @@ -82,7 +82,7 @@ public class ManageTimelines { private List listTimeline; - private boolean notif_follow, notif_add, notif_mention, notif_share; + private boolean notif_follow, notif_add, notif_mention, notif_share, notif_poll; public int getPosition() { @@ -435,14 +435,21 @@ public class ManageTimelines { final MenuItem itemFollow = menu.findItem(R.id.action_follow); final MenuItem itemMention = menu.findItem(R.id.action_mention); final MenuItem itemBoost = menu.findItem(R.id.action_boost); + final MenuItem itemPoll = menu.findItem(R.id.action_poll); notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, true); notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true); notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true); notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true); + notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL_FILTER, true); itemFavourite.setChecked(notif_add); itemFollow.setChecked(notif_follow); itemMention.setChecked(notif_mention); itemBoost.setChecked(notif_share); + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) + itemPoll.setChecked(notif_poll); + else + itemPoll.setVisible(false); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { @@ -495,6 +502,13 @@ public class ManageTimelines { itemBoost.setChecked(notif_share); editor.apply(); break; + case R.id.action_poll: + editor = sharedpreferences.edit(); + notif_poll = !notif_poll; + editor.putBoolean(Helper.SET_NOTIF_POLL_FILTER, notif_poll); + itemPoll.setChecked(notif_poll); + editor.apply(); + break; } return false; } 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 9f6dd666b..c0da1e198 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 @@ -361,6 +361,7 @@ public class Helper { public static final String SET_NOTIF_ADD_FILTER = "set_notif_follow_add_filter"; public static final String SET_NOTIF_MENTION_FILTER = "set_notif_follow_mention_filter"; public static final String SET_NOTIF_SHARE_FILTER = "set_notif_follow_share_filter"; + public static final String SET_NOTIF_POLL_FILTER = "set_notif_follow_poll_filter"; public static final String SET_FILTER_REGEX_HOME = "set_filter_regex_home"; public static final String SET_FILTER_REGEX_LOCAL = "set_filter_regex_local"; public static final String SET_FILTER_REGEX_PUBLIC = "set_filter_regex_public"; diff --git a/app/src/main/res/menu/option_filter_notifications.xml b/app/src/main/res/menu/option_filter_notifications.xml index 9d91657fd..64b304de5 100644 --- a/app/src/main/res/menu/option_filter_notifications.xml +++ b/app/src/main/res/menu/option_filter_notifications.xml @@ -27,4 +27,10 @@ android:title="@string/reblog" app:actionViewClass="android.widget.CheckBox" app:showAsAction="always" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36f14e239..1d14ecf04 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -906,6 +906,7 @@ Poll + Polls Create a poll Choice 1 Choice 2