Some fixes
This commit is contained in:
parent
fb0ee85e7f
commit
4d0c3dae7e
|
@ -35,11 +35,13 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private String since_id;
|
||||
private OnRetrieveMissingFeedsInterface listener;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = new ArrayList<>();
|
||||
private RetrieveFeedsAsyncTask.Type type;
|
||||
|
||||
public RetrieveMissingFeedsAsyncTask(Context context, String since_id, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface){
|
||||
public RetrieveMissingFeedsAsyncTask(Context context, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface){
|
||||
this.context = context;
|
||||
this.since_id = since_id;
|
||||
this.listener = onRetrieveMissingFeedsInterface;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,18 +50,27 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
int loopInc = 0;
|
||||
API api = new API(context);
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> tempStatus;
|
||||
APIResponse apiResponse = null;
|
||||
while (loopInc < 10){
|
||||
APIResponse apiResponse = api.getHomeTimelineSinceId(since_id, 80);
|
||||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||
apiResponse = api.getHomeTimelineSinceId(since_id, 80);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.LOCAL)
|
||||
apiResponse = api.getPublicTimelineSinceId(true, since_id, 80);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC)
|
||||
apiResponse = api.getPublicTimelineSinceId(false, since_id, 80);
|
||||
if (apiResponse == null)
|
||||
break;
|
||||
String max_id = apiResponse.getMax_id();
|
||||
since_id = apiResponse.getSince_id();
|
||||
tempStatus = apiResponse.getStatuses();
|
||||
if( statuses != null && tempStatus != null)
|
||||
statuses.addAll(0, tempStatus);
|
||||
loopInc++;
|
||||
if( max_id == null || max_id.equals(since_id))
|
||||
if( tempStatus == null || max_id == null || max_id.equals(since_id) || tempStatus.size() == 0)
|
||||
break;
|
||||
}
|
||||
if( statuses != null && statuses.size() > 0) {
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME && statuses != null && statuses.size() > 0) {
|
||||
MainActivity.lastHomeId = statuses.get(0).getId();
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -587,6 +587,18 @@ public class API {
|
|||
public APIResponse getPublicTimeline(boolean local, String max_id){
|
||||
return getPublicTimeline(local, max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves public timeline for the account since an Id value *synchronously*
|
||||
* @param local boolean only local timeline
|
||||
* @param since_id String id since
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getPublicTimelineSinceId(boolean local, String since_id, int tootPerPage) {
|
||||
return getPublicTimeline(local, null, since_id, tootPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves public timeline for the account *synchronously*
|
||||
* @param local boolean only local timeline
|
||||
|
|
|
@ -383,10 +383,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
editor.apply();
|
||||
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
|
||||
context.startService(streamingFederatedIntent);
|
||||
if( statuses != null && statuses.size() > 0)
|
||||
retrieveMissingToots(statuses.get(0).getId());
|
||||
}
|
||||
if( statuses != null && statuses.size() > 0)
|
||||
retrieveMissingToots(statuses.get(0).getId());
|
||||
|
||||
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
|
||||
|
||||
if( getUserVisibleHint() ){
|
||||
|
@ -397,10 +396,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
editor.apply();
|
||||
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
|
||||
context.startService(streamingLocalIntent);
|
||||
if( statuses != null && statuses.size() > 0)
|
||||
retrieveMissingToots(statuses.get(0).getId());
|
||||
}
|
||||
if( statuses != null && statuses.size() > 0)
|
||||
retrieveMissingToots(statuses.get(0).getId());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,7 +407,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
* @param sinceId String
|
||||
*/
|
||||
public void retrieveMissingToots(String sinceId){
|
||||
asyncTask = new RetrieveMissingFeedsAsyncTask(context, sinceId, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveMissingFeedsAsyncTask(context, sinceId, type, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -429,8 +427,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||
lastReadStatus = statuses.get(0).getId();
|
||||
editor.apply();
|
||||
}
|
||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC ){
|
||||
} else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC ){
|
||||
if (visible) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
|
@ -439,6 +436,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
editor.apply();
|
||||
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
|
||||
context.startService(streamingFederatedIntent);
|
||||
if( statuses != null && statuses.size() > 0)
|
||||
retrieveMissingToots(statuses.get(0).getId());
|
||||
}else {
|
||||
if( streamingFederatedIntent != null){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
@ -458,6 +457,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
editor.apply();
|
||||
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
|
||||
context.startService(streamingLocalIntent);
|
||||
if( statuses != null && statuses.size() > 0)
|
||||
retrieveMissingToots(statuses.get(0).getId());
|
||||
}else {
|
||||
if( streamingLocalIntent != null){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
@ -536,13 +537,13 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
int top = (v == null) ? 0 : v.getTop();
|
||||
for (int i = statuses.size()-1 ; i >= 0 ; i--) {
|
||||
if (!knownId.contains(statuses.get(i).getId())) {
|
||||
|
||||
statuses.get(i).setNew(true);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||
statuses.get(i).setNew(true);
|
||||
statuses.get(i).setReplies(new ArrayList<Status>());
|
||||
this.statuses.add(0, statuses.get(i));
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( !statuses.get(i).getAccount().getId().equals(userId))
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME && !statuses.get(i).getAccount().getId().equals(userId))
|
||||
MainActivity.countNewStatus++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue