From 9bc6e4795efeef63e36c6e2b535a95592b2b02ec Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 24 Sep 2017 18:44:42 +0200 Subject: [PATCH] Fixes when loading next toots. --- .../fragments/DisplayNotificationsFragment.java | 15 +++++++++------ .../mastodon/fragments/DisplayStatusFragment.java | 15 ++++++++++----- app/src/main/res/layout/fragment_status.xml | 1 - 3 files changed, 19 insertions(+), 12 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 6c5e0056d..c77db26f3 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 @@ -196,8 +196,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve } max_id = apiResponse.getMax_id(); List notifications = apiResponse.getNotifications(); - //The initial call comes from a classic tab refresh - flag_loading = (max_id == null ); + if( !swiped && firstLoad && (notifications == null || notifications.size() == 0)) textviewNoAction.setVisibility(View.VISIBLE); else @@ -215,16 +214,20 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve MainActivity.countNewNotifications++; this.notifications.add(tmpNotification); } - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId()); - editor.apply(); - lastReadNotifications = notifications.get(0).getId(); + if( firstLoad) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId()); + editor.apply(); + lastReadNotifications = notifications.get(0).getId(); + } notificationsListAdapter.notifyDataSetChanged(); } if( firstLoad ) ((MainActivity)context).updateNotifCounter(); swipeRefreshLayout.setRefreshing(false); firstLoad = false; + //The initial call comes from a classic tab refresh + flag_loading = (max_id == null ); } @Override 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 17b580350..fac4462ad 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 @@ -77,6 +77,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String lastReadStatus; private String userId; public static ArrayList tempStatuses = new ArrayList<>(); + private int lastTotalItemCount = 0; public DisplayStatusFragment(){ } @@ -311,12 +312,16 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } this.statuses.add(tmpStatus); } - lastReadStatus = statuses.get(0).getId(); - 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()); - editor.apply(); + + if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME) { + 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()); + editor.apply(); + lastReadStatus = statuses.get(0).getId(); + } statusListAdapter.notifyDataSetChanged(); + if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME) //Display new value in counter try { ((MainActivity) context).updateHomeCounter(); diff --git a/app/src/main/res/layout/fragment_status.xml b/app/src/main/res/layout/fragment_status.xml index 0a1dbf550..9810aa916 100644 --- a/app/src/main/res/layout/fragment_status.xml +++ b/app/src/main/res/layout/fragment_status.xml @@ -29,7 +29,6 @@ android:layout_height="match_parent">