1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Restore scroll position

This commit is contained in:
M66B 2021-04-29 16:54:38 +02:00
parent f2d2577fbf
commit c16da8ca17
2 changed files with 31 additions and 5 deletions

View file

@ -1638,6 +1638,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
bindBody(message, false);
bindAttachments(message, attachments, true);
if (!scroll)
properties.ready(message.id);
}
});
@ -6239,6 +6242,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
void scrollBy(int x, int y);
void ready(long id);
void move(long id, String type);
void reply(TupleMessageEx message, String selected, View anchor);

View file

@ -761,6 +761,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
this, type, found, viewType,
compact, zoom, sort, ascending, filter_duplicates,
iProperties);
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT);
rvMessage.setAdapter(adapter);
sbThread.setOnTouchListener(new View.OnTouchListener() {
@ -1773,6 +1774,29 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
});
}
@Override
public void ready(long id) {
iProperties.setValue("ready", id, true);
if (!values.containsKey("expanded"))
return;
for (long expanded : values.get("expanded"))
if (!iProperties.getValue("ready", expanded))
return;
getMainHandler().post(new Runnable() {
@Override
public void run() {
try {
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.ALLOW);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
@Override
public void move(long id, String type) {
Bundle args = new Bundle();
@ -3672,11 +3696,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (rvMessage != null) {
Parcelable rv = rvMessage.getLayoutManager().onSaveInstanceState();
outState.putParcelable("fair:rv", rv);
LinearLayoutManager llm = (LinearLayoutManager) rvMessage.getLayoutManager();
outState.putInt("fair:scroll", llm.findFirstVisibleItemPosition());
}
values.remove("ready");
if (selectionTracker != null)
selectionTracker.onSaveInstanceState(outState);
@ -3704,8 +3727,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
rvMessage.getLayoutManager().onRestoreInstanceState(rv);
}
adapter.gotoPos(savedInstanceState.getInt("fair:scroll"));
if (selectionTracker != null)
selectionTracker.onRestoreInstanceState(savedInstanceState);
}