From 537f853c83fa8626ddf1781584f051b144004469 Mon Sep 17 00:00:00 2001 From: stom79 Date: Mon, 20 Nov 2017 16:05:18 +0100 Subject: [PATCH] Fixes issue #42 - scrolling issue --- .../mastodon/fragments/DisplayNotificationsFragment.java | 3 ++- .../etalab/mastodon/fragments/DisplayStatusFragment.java | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) 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 b7578143c..7ea95da37 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 @@ -184,6 +184,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve swiped = false; return; } + int previousPosition = notifications.size(); max_id = apiResponse.getMax_id(); List notifications = apiResponse.getNotifications(); @@ -211,7 +212,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve MainActivity.lastNotificationId = notifications.get(0).getId(); updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId()); } - notificationsListAdapter.notifyDataSetChanged(); + notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size()); } if( firstLoad ) ((MainActivity)context).updateNotifCounter(); 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 f1b86dd62..182b8645c 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 @@ -152,6 +152,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn public void onRefresh() { max_id = null; statuses = new ArrayList<>(); + statuses.clear(); firstLoad = true; flag_loading = true; swiped = true; @@ -234,6 +235,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn flag_loading = false; return; } + int previousPosition = this.statuses.size(); List statuses = apiResponse.getStatuses(); max_id = apiResponse.getMax_id(); @@ -243,8 +245,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn else textviewNoAction.setVisibility(View.GONE); if( swiped ){ - statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); - lv_status.setAdapter(statusListAdapter); swiped = false; } @@ -260,8 +260,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn this.statuses.add(tmpStatus); } } - - if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME) { + if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) { //Update the id of the last toot retrieved MainActivity.lastHomeId = statuses.get(0).getId(); SharedPreferences.Editor editor = sharedpreferences.edit(); @@ -270,7 +269,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn editor.apply(); lastReadStatus = statuses.get(0).getId(); } - statusListAdapter.notifyDataSetChanged(); + statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME) //Display new value in counter try {