Fixes an issue with the flag which blocks to load more toots in home timeline

This commit is contained in:
tom79 2017-08-19 19:02:42 +02:00
parent 8d0cd411af
commit 5aeb018eb8
3 changed files with 7 additions and 10 deletions

View File

@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import android.os.SystemClock;
import java.util.List;
@ -50,6 +51,7 @@ public class RetrieveRepliesAsyncTask extends AsyncTask<Void, Void, Void> {
API api = new API(context);
for (fr.gouv.etalab.mastodon.client.Entities.Status status : statuses) {
fr.gouv.etalab.mastodon.client.Entities.Context statusContext = api.getStatusContext((status.getReblog() != null) ? status.getReblog().getId() : status.getId());
SystemClock.sleep(25);
status.setReplies(statusContext.getDescendants());
}
apiResponse = new APIResponse();

View File

@ -22,6 +22,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;
@ -233,7 +234,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
@Override
public void onRetrieveAccounts(APIResponse apiResponse) {
flag_loading = (apiResponse.getMax_id() == null );
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
@ -241,7 +242,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
if( show_error_messages)
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
flag_loading = false;
swipeRefreshLayout.setRefreshing(false);
swiped = false;
return;
@ -265,6 +265,5 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
flag_loading = accounts != null && accounts.size() < accountPerPage;
}
}

View File

@ -260,7 +260,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
flag_loading = (apiResponse.getMax_id() == null );
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted
@ -269,13 +269,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
if( show_error_messages)
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
flag_loading = false;
swipeRefreshLayout.setRefreshing(false);
swiped = false;
return;
}else if( apiResponse.getError() != null && apiResponse.getError().getError().startsWith("404 -")) {
flag_loading = false;
}
List<Status> statuses = apiResponse.getStatuses();
if( !swiped && firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
@ -294,8 +292,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
statusListAdapter.notifyDataSetChanged();
}
swipeRefreshLayout.setRefreshing(false);
if( flag_loading )
flag_loading = statuses != null && statuses.size() < tootsPerPage;
//Store last toot id for home timeline to avoid to notify for those that have been already seen
if(statuses != null && statuses.size() > 0 && type == RetrieveFeedsAsyncTask.Type.HOME ){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -341,6 +338,5 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
}
statusListAdapter.notifyDataSetChanged();
}
}