Fix bookmark issue

This commit is contained in:
tom79 2019-05-25 19:12:04 +02:00
parent 7d14a0ad85
commit 8b055d38de
4 changed files with 26 additions and 12 deletions

View File

@ -37,18 +37,20 @@ public class RetrieveFeedsAfterBookmarkAsyncTask extends AsyncTask<Void, Void, V
private OnRetrieveFeedsAfterBookmarkInterface listener;
private WeakReference<Context> contextReference;
private String max_id;
private boolean fetchMore;
public RetrieveFeedsAfterBookmarkAsyncTask(Context context, String max_id, OnRetrieveFeedsAfterBookmarkInterface onRetrieveFeedsAfterBookmarkInterface){
public RetrieveFeedsAfterBookmarkAsyncTask(Context context, String max_id, boolean fetchMore, OnRetrieveFeedsAfterBookmarkInterface onRetrieveFeedsAfterBookmarkInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveFeedsAfterBookmarkInterface;
this.max_id = max_id;
this.fetchMore = fetchMore;
}
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
apiResponse = api.getHomeTimeline(max_id);
apiResponse.setFetchmore(fetchMore);
return null;
}

View File

@ -1017,7 +1017,6 @@ public class API {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean remember_position_home = sharedpreferences.getBoolean(Helper.SET_REMEMBER_POSITION_HOME, true);
//TODO: remove forced condition
if( remember_position_home ){
if( statuses != null){
Iterator<Status> i = statuses.iterator();

View File

@ -58,6 +58,8 @@ public class APIResponse {
private String since_id, max_id;
private Instance instance;
private List<StoredStatus> storedStatuses;
private boolean fetchmore = false;
public List<Account> getAccounts() {
return accounts;
}
@ -209,4 +211,12 @@ public class APIResponse {
public void setResults(Results results) {
this.results = results;
}
public boolean isFetchmore() {
return fetchmore;
}
public void setFetchmore(boolean fetchmore) {
this.fetchmore = fetchmore;
}
}

View File

@ -30,7 +30,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -541,9 +540,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( type == RetrieveFeedsAsyncTask.Type.HOME && !firstTootsLoaded){
boolean remember_position_home = sharedpreferences.getBoolean(Helper.SET_REMEMBER_POSITION_HOME, true);
if( remember_position_home) {
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if( remember_position_home)
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, null, false,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
firstTootsLoaded = true;
}
//Let's deal with statuses
@ -688,7 +686,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
public void retrieveMissingToots(String sinceId){
if( type == RetrieveFeedsAsyncTask.Type.HOME)
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, null, false,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE )
asyncTask = new RetrieveMissingFeedsAsyncTask(context, remoteInstance, sinceId, type, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if(type == RetrieveFeedsAsyncTask.Type.TAG)
@ -713,7 +711,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
if( statuses.size() > 0)
initialBookMarkDate = statuses.get(0).getCreated_at();
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, null, false,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@ -923,7 +921,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
public void fetchMore(String max_id){
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAfterBookmarkAsyncTask(context, max_id, true,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
@ -955,9 +953,14 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
ArrayList<Status> tmpStatuses = new ArrayList<>();
for (Status tmpStatus : statuses) {
//Put the toot at its place in the list (id desc)
if (this.statuses.size() == 0){
if( !apiResponse.isFetchmore() && !this.statuses.contains(tmpStatus) && tmpStatus.getCreated_at().after(this.statuses.get(0).getCreated_at())) { //Element not already added
//Mark status at new ones when their id is greater than the last read toot id
if (type == RetrieveFeedsAsyncTask.Type.HOME && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate) ) {
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
}
tmpStatuses.add(tmpStatus);
}else if( tmpStatus.getCreated_at().after(this.statuses.get(0).getCreated_at())) { //Element not already added
}else if( apiResponse.isFetchmore() && !this.statuses.contains(tmpStatus)) { //Element not already added
//Mark status at new ones when their id is greater than the last read toot id
if (type == RetrieveFeedsAsyncTask.Type.HOME && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate) ) {
tmpStatus.setNew(true);