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);
//Get the previous bookmark value
bookmark = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
bookmark = "99116597419219731";
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
if( account == null){
Helper.logout(getApplicationContext());

View File

@ -571,9 +571,23 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if( status.isFetchMore()) {
holder.fetch_more.setVisibility(View.VISIBLE);
holder.fetch_more.setEnabled(true);
}else
}else {
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)
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
else
@ -1246,18 +1260,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
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){
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
if (bookmark != null){
if (Long.parseLong(tmpStatus.getId()) > Long.parseLong(bookmark)) {
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
//Toots are older than the bookmark -> no special treatment with them
if( Long.parseLong(statuses.get(0).getId()) < Long.parseLong(bookmark)){
this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
}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( this.statuses != null) {
int loop = 0;
while (loop < this.statuses.size() && Long.parseLong(tmpStatus.getId()) < Long.parseLong(this.statuses.get(loop).getId())){
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);
if( lastLoop > 0 )
lv_status.scrollToPosition((lastLoop));
}
}
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 {
this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
}
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
//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.apply();
}
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME)
//Display new value in counter
try {