Fixed/improved scroll to top/bottom of expanded message

pull/161/head
M66B 5 years ago
parent 3e3d0006bc
commit 77440f7181

@ -1028,32 +1028,37 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void scrollToVisibleItem(LinearLayoutManager llm, boolean bottom) { private void scrollToVisibleItem(LinearLayoutManager llm, boolean bottom) {
int pos = llm.findLastVisibleItemPosition(); int first = llm.findFirstVisibleItemPosition();
if (pos == RecyclerView.NO_POSITION) int last = llm.findLastVisibleItemPosition();
if (first == RecyclerView.NO_POSITION || last == RecyclerView.NO_POSITION)
return; return;
int pos = (bottom ? last : first);
do { do {
Long key = adapter.getKeyAtPosition(pos); Long key = adapter.getKeyAtPosition(pos);
if (key != null && iProperties.getValue("expanded", key)) { if (key != null && iProperties.getValue("expanded", key)) {
int first = llm.findFirstVisibleItemPosition(); View child = llm.findViewByPosition(pos);
View child = rvMessage.getChildAt(pos - (first < 0 ? 0 : first));
if (child != null) { if (child != null) {
TranslateAnimation bounce = new TranslateAnimation( TranslateAnimation bounce = new TranslateAnimation(
0, 0, Helper.dp2pixels(getContext(), bottom ? -12 : 12), 0); 0, 0, Helper.dp2pixels(getContext(), bottom ? -6 : 6), 0);
bounce.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)); bounce.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
child.startAnimation(bounce); child.startAnimation(bounce);
}
if (bottom && child != null) if (bottom)
llm.scrollToPositionWithOffset(pos, rvMessage.getHeight() - llm.getDecoratedMeasuredHeight(child)); llm.scrollToPositionWithOffset(pos,
else rvMessage.getHeight() - llm.getDecoratedMeasuredHeight(child) + child.getPaddingBottom());
rvMessage.scrollToPosition(pos); else
llm.scrollToPositionWithOffset(pos, -child.getPaddingTop());
break; break;
}
} }
pos--;
} while (pos >= 0); if (bottom)
pos--;
else
pos++;
} while (pos >= first && pos <= last);
} }
private void onSwipeRefresh() { private void onSwipeRefresh() {

Loading…
Cancel
Save