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

View File

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