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 7170b61e5..821071c6d 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 @@ -241,10 +241,10 @@ public abstract class BaseMainActivity extends AppCompatActivity 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); - 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_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); itemFavourite.setChecked(notif_add); itemFollow.setChecked(notif_follow); itemMention.setChecked(notif_mention); @@ -275,28 +275,28 @@ public abstract class BaseMainActivity extends AppCompatActivity case R.id.action_favorite: SharedPreferences.Editor editor = sharedpreferences.edit(); notif_add = !notif_add; - editor.putBoolean(Helper.SET_NOTIF_ADD, notif_add); + editor.putBoolean(Helper.SET_NOTIF_ADD_FILTER, notif_add); itemFavourite.setChecked(notif_add); editor.apply(); break; case R.id.action_follow: editor = sharedpreferences.edit(); notif_follow = !notif_follow; - editor.putBoolean(Helper.SET_NOTIF_FOLLOW, notif_follow); + editor.putBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, notif_follow); itemFollow.setChecked(notif_follow); editor.apply(); break; case R.id.action_mention: editor = sharedpreferences.edit(); notif_mention = !notif_mention; - editor.putBoolean(Helper.SET_NOTIF_MENTION, notif_mention); + editor.putBoolean(Helper.SET_NOTIF_MENTION_FILTER, notif_mention); itemMention.setChecked(notif_mention); editor.apply(); break; case R.id.action_boost: editor = sharedpreferences.edit(); notif_share = !notif_share; - editor.putBoolean(Helper.SET_NOTIF_SHARE, notif_share); + editor.putBoolean(Helper.SET_NOTIF_SHARE_FILTER, notif_share); itemBoost.setChecked(notif_share); editor.apply(); break; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMissingNotificationsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMissingNotificationsAsyncTask.java index 5d10d1bdb..e2b04db7e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMissingNotificationsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMissingNotificationsAsyncTask.java @@ -53,7 +53,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask tempNotifications; while (loopInc < 10){ - APIResponse apiResponse = api.getNotificationsSince(since_id, 40); + APIResponse apiResponse = api.getNotificationsSince(since_id, 40, false); String max_id = apiResponse.getMax_id(); since_id = apiResponse.getSince_id(); tempNotifications = apiResponse.getNotifications(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java index db86366d1..5e1c91b4c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java @@ -40,8 +40,9 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask private String token; private boolean refreshData; private WeakReference contextReference; + private boolean display; - public RetrieveNotificationsAsyncTask(Context context, String instance, String token, String max_id, String acct, String userId, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){ + public RetrieveNotificationsAsyncTask(Context context, boolean display, String instance, String token, String max_id, String acct, String userId, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){ this.contextReference = new WeakReference<>(context); this.max_id = max_id; this.listener = onRetrieveNotificationsInterface; @@ -50,6 +51,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask this.userId = userId; this.token = token; this.refreshData = true; + this.display = display; } @@ -58,9 +60,9 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask API api = new API(this.contextReference.get(), instance, token); if( acct == null) - apiResponse = api.getNotifications(max_id); + apiResponse = api.getNotifications(max_id, display); else - apiResponse = api.getNotificationsSince(max_id); + apiResponse = api.getNotificationsSince(max_id, display); return null; } 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 2960a4c7d..23788bb89 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 @@ -1187,8 +1187,8 @@ public class API { * @param since_id String since max * @return APIResponse */ - public APIResponse getNotificationsSince(String since_id){ - return getNotifications(null, since_id, notificationPerPage); + public APIResponse getNotificationsSince(String since_id, boolean display){ + return getNotifications(null, since_id, notificationPerPage, display); } /** @@ -1196,8 +1196,8 @@ public class API { * @param since_id String since max * @return APIResponse */ - public APIResponse getNotificationsSince(String since_id, int notificationPerPage){ - return getNotifications(null, since_id, notificationPerPage); + public APIResponse getNotificationsSince(String since_id, int notificationPerPage, boolean display){ + return getNotifications(null, since_id, notificationPerPage, display); } /** @@ -1205,8 +1205,8 @@ public class API { * @param max_id String id max * @return APIResponse */ - public APIResponse getNotifications(String max_id){ - return getNotifications(max_id, null, notificationPerPage); + public APIResponse getNotifications(String max_id, boolean display){ + return getNotifications(max_id, null, notificationPerPage, display); } /** * Retrieves notifications for the authenticated account *synchronously* @@ -1215,7 +1215,7 @@ public class API { * @param limit int limit - max value 40 * @return APIResponse */ - private APIResponse getNotifications(String max_id, String since_id, int limit){ + private APIResponse getNotifications(String max_id, String since_id, int limit, boolean display){ RequestParams params = new RequestParams(); if( max_id != null ) @@ -1227,10 +1227,18 @@ public class API { params.put("limit",String.valueOf(limit)); final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); - 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_follow, notif_add, notif_mention, notif_share; + if( !display) { + 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); + }else { + 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); + } if( !notif_follow ) params.add("exclude_types[]", "follow"); if( !notif_add ) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java index 68a93b436..a57b87374 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java @@ -106,7 +106,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve if (firstVisibleItem + visibleItemCount == totalItemCount) { if (!flag_loading) { flag_loading = true; - asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); nextElementLoader.setVisibility(View.VISIBLE); } } else { @@ -125,14 +125,14 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve flag_loading = true; swiped = true; MainActivity.countNewNotifications = 0; - asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4, R.color.mastodonC2, R.color.mastodonC3); - asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return rootView; @@ -251,7 +251,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve flag_loading = true; swiped = true; MainActivity.countNewNotifications = 0; - asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } 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 34b3975c7..73c72486e 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 @@ -232,6 +232,11 @@ public class Helper { public static final String SET_NOTIF_ASK = "set_notif_follow_ask"; public static final String SET_NOTIF_MENTION = "set_notif_follow_mention"; public static final String SET_NOTIF_SHARE = "set_notif_follow_share"; + public static final String SET_NOTIF_FOLLOW_FILTER = "set_notif_follow_filter"; + 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_VALIDATION = "set_share_validation"; public static final String SET_NOTIF_VALIDATION_FAV = "set_share_validation_fav"; public static final String SET_WIFI_ONLY = "set_wifi_only"; 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 e34f7dc0b..cae69b09f 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 @@ -125,7 +125,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications //Retrieve users in db that owner has. for (Account account: accounts) { String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); - new RetrieveNotificationsAsyncTask(getContext(), account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveNotificationsAsyncTask(getContext(), false, account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }