Navigate with fetch more button

This commit is contained in:
stom79 2017-12-06 19:12:52 +01:00
parent 05ebe32ba7
commit 6c3a30b75b
3 changed files with 49 additions and 32 deletions

View File

@ -576,7 +576,6 @@ public abstract class BaseMainActivity extends AppCompatActivity
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
//Get the previous bookmark value //Get the previous bookmark value
bookmark = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null); bookmark = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
bookmark = "99116597419219731";
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId); Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
if( account == null){ if( account == null){
Helper.logout(getApplicationContext()); Helper.logout(getApplicationContext());

View File

@ -571,9 +571,23 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if( status.isFetchMore()) { if( status.isFetchMore()) {
holder.fetch_more.setVisibility(View.VISIBLE); holder.fetch_more.setVisibility(View.VISIBLE);
holder.fetch_more.setEnabled(true); holder.fetch_more.setEnabled(true);
}else }else {
holder.fetch_more.setVisibility(View.GONE); holder.fetch_more.setVisibility(View.GONE);
}
holder.fetch_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
status.setFetchMore(false);
holder.fetch_more.setEnabled(false);
holder.fetch_more.setVisibility(View.GONE);
DisplayStatusFragment homeFragment = ((BaseMainActivity) context).getHomeFragment();
if( homeFragment != null)
homeFragment.fetchMore(status.getId());
}
});
if( status.getReblog() == null) if( status.getReblog() == null)
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count())); holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
else else
@ -1246,18 +1260,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
} }
holder.status_show_more.setVisibility(View.GONE); holder.status_show_more.setVisibility(View.GONE);
holder.fetch_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(status.isFetchMore()) {
status.setFetchMore(false);
holder.fetch_more.setEnabled(false);
DisplayStatusFragment homeFragment = ((BaseMainActivity) context).getHomeFragment();
if( homeFragment != null)
homeFragment.fetchMore(status.getId());
}
}
});
} }

View File

@ -272,29 +272,45 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( context instanceof BaseMainActivity){ if( context instanceof BaseMainActivity){
bookmark = ((BaseMainActivity) context).getBookmark(); bookmark = ((BaseMainActivity) context).getBookmark();
} }
for (Status tmpStatus : statuses) {
//Mark status at new ones when their id is greater than the bookmark id / Also increments counter //Toots are older than the bookmark -> no special treatment with them
if (bookmark != null){ if( Long.parseLong(statuses.get(0).getId()) < Long.parseLong(bookmark)){
if (Long.parseLong(tmpStatus.getId()) > Long.parseLong(bookmark)) { this.statuses.addAll(statuses);
tmpStatus.setNew(true); statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
MainActivity.countNewStatus++; }else { //Toots are younger than the bookmark
int lastLoop = 0;
for (Status tmpStatus : statuses) {
//Mark status at new ones when their id is greater than the bookmark id / Also increments counter
if (bookmark != null) {
if (Long.parseLong(tmpStatus.getId()) > Long.parseLong(bookmark)) {
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
}
} }
//Put the toot at its place in the list (id desc)
if (this.statuses != null) {
int loop = 0;
while (loop < this.statuses.size() && Long.parseLong(tmpStatus.getId()) < Long.parseLong(this.statuses.get(loop).getId())) {
loop++;
}
if( Long.parseLong(statuses.get(0).getId()) != Long.parseLong(bookmark) ) {
this.statuses.add(loop, tmpStatus);
statusListAdapter.notifyItemInserted(loop);
lastLoop = loop; //Record the last position of the inserted toot in this.statuses
}
}
} }
//Put the toot at its place in the list (id desc) if (bookmark != null && Long.parseLong(statuses.get((statuses.size() - 1)).getId()) > Long.parseLong(bookmark)) {
if( this.statuses != null) { statuses.get(statuses.size() - 1).setFetchMore(true);
int loop = 0; if( lastLoop > 0 )
while (loop < this.statuses.size() && Long.parseLong(tmpStatus.getId()) < Long.parseLong(this.statuses.get(loop).getId())){ lv_status.scrollToPosition((lastLoop));
loop++;
}
this.statuses.add(loop, tmpStatus);
} }
} }
if( bookmark != null && Long.parseLong(statuses.get((statuses.size()-1)).getId()) > Long.parseLong(bookmark)) {
statuses.get(statuses.size() - 1).setFetchMore(true);
lv_status.scrollToPosition((statuses.size()-1));
}
}else { }else {
this.statuses.addAll(statuses); this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
} }
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) { if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
//Update the id of the last toot retrieved //Update the id of the last toot retrieved
@ -304,7 +320,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId()); editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
editor.apply(); editor.apply();
} }
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME) if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME)
//Display new value in counter //Display new value in counter
try { try {