From 5ce1e099570a0d7caa57a3dead5197db0e516794 Mon Sep 17 00:00:00 2001 From: tom79 Date: Fri, 16 Jun 2017 18:54:46 +0200 Subject: [PATCH] Fixes pull to refresh bug --- .../fragments/DisplayAccountsFragment.java | 9 ++++++++- .../DisplayFollowRequestSentFragment.java | 9 +++++++-- .../fragments/DisplayNotificationsFragment.java | 9 ++++++++- .../mastodon/fragments/DisplayStatusFragment.java | 15 ++++++++++++--- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java index 0fb6cd509..4f4cc393d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java @@ -60,6 +60,8 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou private int accountPerPage; private String targetedId; private boolean swiped; + private ListView lv_accounts; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -92,7 +94,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40); - final ListView lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts); + lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts); mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader); nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_accounts); @@ -246,6 +248,11 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou else textviewNoAction.setVisibility(View.GONE); max_id = apiResponse.getMax_id(); + if( swiped ){ + accountsListAdapter = new AccountsListAdapter(context, type, this.accounts); + lv_accounts.setAdapter(accountsListAdapter); + swiped = false; + } if( accounts != null) { for(Account tmpAccount: accounts){ this.accounts.add(tmpAccount); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java index 86df622d2..ab802dc3b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java @@ -58,7 +58,7 @@ public class DisplayFollowRequestSentFragment extends Fragment implements OnRetr private int accountPerPage; private TextView no_action_text; private boolean swiped; - + private ListView lv_accounts; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -75,7 +75,7 @@ public class DisplayFollowRequestSentFragment extends Fragment implements OnRetr swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40); - final ListView lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts); + lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts); no_action_text = (TextView) rootView.findViewById(R.id.no_action_text); mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader); nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_accounts); @@ -167,6 +167,11 @@ public class DisplayFollowRequestSentFragment extends Fragment implements OnRetr }else textviewNoAction.setVisibility(View.GONE); max_id = apiResponse.getMax_id(); + if( swiped ){ + accountsFollowRequestAdapter = new AccountsFollowRequestAdapter(context, this.accounts); + lv_accounts.setAdapter(accountsFollowRequestAdapter); + swiped = false; + } if( accounts != null) { for(Account tmpAccount: accounts){ this.accounts.add(tmpAccount); 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 d096d9039..7b2db2ef5 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 @@ -34,6 +34,7 @@ import java.util.List; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter; +import fr.gouv.etalab.mastodon.drawers.StatusListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; @@ -62,6 +63,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve private SwipeRefreshLayout swipeRefreshLayout; private int notificationPerPage; private boolean swiped; + private ListView lv_notifications; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -77,7 +79,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); notificationPerPage = sharedpreferences.getInt(Helper.SET_NOTIFICATIONS_PER_PAGE, 40); - ListView lv_notifications = (ListView) rootView.findViewById(R.id.lv_notifications); + lv_notifications = (ListView) rootView.findViewById(R.id.lv_notifications); mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader); nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_notifications); @@ -166,6 +168,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve textviewNoAction.setVisibility(View.VISIBLE); else textviewNoAction.setVisibility(View.GONE); + if( swiped ){ + notificationsListAdapter = new NotificationsListAdapter(context, this.notifications); + lv_notifications.setAdapter(notificationsListAdapter); + swiped = false; + } max_id = apiResponse.getMax_id(); if( notifications != null) { 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 c1c22f027..ccf7c6aa5 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 @@ -23,6 +23,7 @@ import android.os.Parcelable; import android.support.v4.app.Fragment; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -65,6 +66,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String tag; private int tootsPerPage; private boolean swiped; + private ListView lv_status; + private boolean isOnWifi; + private int behaviorWithAttachments; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -94,12 +98,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn firstLoad = true; swiped = false; - boolean isOnWifi = Helper.isOnWIFI(context); + isOnWifi = Helper.isOnWIFI(context); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); + behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - final ListView lv_status = (ListView) rootView.findViewById(R.id.lv_status); + lv_status = (ListView) rootView.findViewById(R.id.lv_status); tootsPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40); mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader); nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_status); @@ -264,6 +268,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn textviewNoAction.setVisibility(View.VISIBLE); else textviewNoAction.setVisibility(View.GONE); + if( swiped ){ + statusListAdapter = new StatusListAdapter(context, type, isOnWifi, behaviorWithAttachments, this.statuses); + lv_status.setAdapter(statusListAdapter); + swiped = false; + } max_id = apiResponse.getMax_id(); if( statuses != null) { for(Status tmpStatus: statuses){