Fixed scroll to top

This commit is contained in:
M66B 2019-05-15 13:37:35 +02:00
parent 8b0096f702
commit cd608fb5f7
2 changed files with 14 additions and 11 deletions

View File

@ -157,7 +157,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean authentication;
private boolean debug;
private boolean gotop = false;
private boolean gotoTop = false;
private AsyncPagedListDiffer<TupleMessageEx> differ;
private SelectionTracker<Long> selectionTracker = null;
@ -3065,16 +3065,20 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.differ.addPagedListListener(new AsyncPagedListDiffer.PagedListListener<TupleMessageEx>() {
@Override
public void onCurrentListChanged(@Nullable PagedList<TupleMessageEx> previousList, @Nullable PagedList<TupleMessageEx> currentList) {
if (gotop) {
gotop = false;
if (gotoTop) {
gotoTop = false;
properties.scrollTo(0);
}
}
});
}
void submitList(PagedList<TupleMessageEx> list, boolean gotop) {
this.gotop = gotop;
void gotoTop() {
properties.scrollTo(0);
this.gotoTop = true;
}
void submitList(PagedList<TupleMessageEx> list) {
differ.submitList(list);
}

View File

@ -2612,6 +2612,9 @@ public class FragmentMessages extends FragmentBase {
private boolean loading = false;
private void loadMessagesNext(final boolean top) {
if (top)
adapter.gotoTop();
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
LiveData<PagedList<TupleMessageEx>> liveMessages = model.getPagedList(
@ -2651,8 +2654,6 @@ public class FragmentMessages extends FragmentBase {
});
liveMessages.observe(getViewLifecycleOwner(), new Observer<PagedList<TupleMessageEx>>() {
private boolean topped = false;
@Override
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
if (messages == null)
@ -2662,10 +2663,8 @@ public class FragmentMessages extends FragmentBase {
if (handleThreadActions(messages))
return;
boolean gotop = (top && !topped);
topped = true;
Log.i("Submit messages=" + messages.size() + " top=" + gotop);
adapter.submitList(messages, gotop);
Log.i("Submit messages=" + messages.size());
adapter.submitList(messages);
// This is to workaround not drawing when the search is expanded
new Handler().post(new Runnable() {