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 fd8c7f0fc..ff2be178a 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 @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.List; import fr.gouv.etalab.mastodon.activities.MainActivity; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; @@ -219,6 +220,15 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve public void scrollToTop(){ if( lv_notifications != null) lv_notifications.setAdapter(notificationsListAdapter); + //Store last toot id for home timeline to avoid to notify for those that have been already seen + //Store last notification id to avoid to notify for those that have been already seen + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + if (notifications != null && notifications.size() > 0) { + editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId()); + editor.apply(); + lastReadNotifications = notifications.get(0).getId(); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index f4b50dcc6..4ba8f3d08 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -338,8 +338,18 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } public void scrollToTop(){ - if( lv_status != null) + if( lv_status != null) { lv_status.setAdapter(statusListAdapter); + //Store last toot id for home timeline to avoid to notify for those that have been already seen + if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses != null && statuses.size() > 0) { + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId()); + lastReadStatus = statuses.get(0).getId(); + editor.apply(); + } + } } @Override