forked from github/szkolny
[UI/Messages] Make message list scroll to last opened message.
This commit is contained in:
parent
c71b8f994c
commit
a133a96819
@ -46,9 +46,9 @@ public class MessagesListFragment extends Fragment {
|
|||||||
static final long TRANSITION_DURATION = 300L;
|
static final long TRANSITION_DURATION = 300L;
|
||||||
static final String TAP_POSITION = "tap_position";
|
static final String TAP_POSITION = "tap_position";
|
||||||
|
|
||||||
private static int tapPosition = NO_POSITION;
|
private static int[] tapPositions = {NO_POSITION, NO_POSITION};
|
||||||
private static int topPosition = NO_POSITION;
|
private static int[] topPositions = {NO_POSITION, NO_POSITION};
|
||||||
private static int bottomPosition = NO_POSITION;
|
private static int[] bottomPositions = {NO_POSITION, NO_POSITION};
|
||||||
|
|
||||||
private int messageType = Message.TYPE_RECEIVED;
|
private int messageType = Message.TYPE_RECEIVED;
|
||||||
|
|
||||||
@ -93,11 +93,11 @@ public class MessagesListFragment extends Fragment {
|
|||||||
|
|
||||||
messagesAdapter = new MessagesAdapter(app, ((parent, view1, position, id) -> {
|
messagesAdapter = new MessagesAdapter(app, ((parent, view1, position, id) -> {
|
||||||
// TODO ANIMATION
|
// TODO ANIMATION
|
||||||
/*tapPosition = position;
|
tapPositions[messageType] = position;
|
||||||
topPosition = ((LinearLayoutManager) b.emailList.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
|
topPositions[messageType] = ((LinearLayoutManager) b.emailList.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
|
||||||
bottomPosition = ((LinearLayoutManager) b.emailList.getLayoutManager()).findLastCompletelyVisibleItemPosition();
|
bottomPositions[messageType] = ((LinearLayoutManager) b.emailList.getLayoutManager()).findLastCompletelyVisibleItemPosition();
|
||||||
|
|
||||||
view1.getGlobalVisibleRect(viewRect);
|
/*view1.getGlobalVisibleRect(viewRect);
|
||||||
((Transition) MessagesListFragment.this.getExitTransition()).setEpicenterCallback(new Transition.EpicenterCallback() {
|
((Transition) MessagesListFragment.this.getExitTransition()).setEpicenterCallback(new Transition.EpicenterCallback() {
|
||||||
@Override
|
@Override
|
||||||
public Rect onGetEpicenter(@NonNull Transition transition) {
|
public Rect onGetEpicenter(@NonNull Transition transition) {
|
||||||
@ -224,17 +224,36 @@ public class MessagesListFragment extends Fragment {
|
|||||||
b.progressBar.setVisibility(View.GONE);
|
b.progressBar.setVisibility(View.GONE);
|
||||||
b.emailList.setVisibility(View.VISIBLE);
|
b.emailList.setVisibility(View.VISIBLE);
|
||||||
messagesAdapter.setData(messageFulls);
|
messagesAdapter.setData(messageFulls);
|
||||||
|
|
||||||
|
LinearLayoutManager layoutManager = (LinearLayoutManager) b.emailList.getLayoutManager();
|
||||||
|
if (tapPositions[messageType] != NO_POSITION && layoutManager != null) {
|
||||||
|
//d("MessageList", "Scrolling");
|
||||||
|
|
||||||
|
if (topPositions[messageType] > layoutManager.findLastCompletelyVisibleItemPosition()) {
|
||||||
|
b.emailList.scrollToPosition(topPositions[messageType]);
|
||||||
|
}
|
||||||
|
else if (bottomPositions[messageType] < layoutManager.findFirstCompletelyVisibleItemPosition()) {
|
||||||
|
b.emailList.scrollToPosition(bottomPositions[messageType]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
b.emailList.scrollToPosition(tapPositions[messageType]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//tapPositions[messageType] = NO_POSITION;
|
||||||
|
//topPositions[messageType] = NO_POSITION;
|
||||||
|
//bottomPositions[messageType] = NO_POSITION;
|
||||||
|
}
|
||||||
// TODO ANIMATION
|
// TODO ANIMATION
|
||||||
/*final ViewTreeObserver observer = viewParent.getViewTreeObserver();
|
/*final ViewTreeObserver observer = viewParent.getViewTreeObserver();
|
||||||
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreDraw() {
|
public boolean onPreDraw() {
|
||||||
viewParent.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
||||||
|
*//*viewParent.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||||
if (getExitTransition() == null) {
|
if (getExitTransition() == null) {
|
||||||
setExitTransition(new SlideExplode().setDuration(TRANSITION_DURATION).setInterpolator(transitionInterpolator));
|
setExitTransition(new SlideExplode().setDuration(TRANSITION_DURATION).setInterpolator(transitionInterpolator));
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearLayoutManager layoutManager = (LinearLayoutManager) b.emailList.getLayoutManager();
|
|
||||||
View view2 = layoutManager != null ? layoutManager.findViewByPosition(tapPosition) : null;
|
View view2 = layoutManager != null ? layoutManager.findViewByPosition(tapPosition) : null;
|
||||||
if (view2 != null) {
|
if (view2 != null) {
|
||||||
view2.getGlobalVisibleRect(viewRect);
|
view2.getGlobalVisibleRect(viewRect);
|
||||||
@ -248,24 +267,8 @@ public class MessagesListFragment extends Fragment {
|
|||||||
|
|
||||||
d("MessagesList", "topPosition "+topPosition);
|
d("MessagesList", "topPosition "+topPosition);
|
||||||
d("MessagesList", "tapPosition "+tapPosition);
|
d("MessagesList", "tapPosition "+tapPosition);
|
||||||
d("MessagesList", "bottomPosition "+bottomPosition);
|
d("MessagesList", "bottomPosition "+bottomPosition);*//*
|
||||||
if (tapPosition != NO_POSITION && layoutManager != null) {
|
|
||||||
d("MessageList", "Scrolling");
|
|
||||||
|
|
||||||
if (bottomPosition > layoutManager.findLastCompletelyVisibleItemPosition()) {
|
|
||||||
b.emailList.scrollToPosition(bottomPosition);
|
|
||||||
}
|
|
||||||
else if (topPosition < layoutManager.findFirstCompletelyVisibleItemPosition()) {
|
|
||||||
b.emailList.scrollToPosition(topPosition);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
b.emailList.scrollToPosition(tapPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
tapPosition = NO_POSITION;
|
|
||||||
topPosition = NO_POSITION;
|
|
||||||
bottomPosition = NO_POSITION;
|
|
||||||
}
|
|
||||||
|
|
||||||
startPostponedEnterTransition();
|
startPostponedEnterTransition();
|
||||||
return true;
|
return true;
|
||||||
@ -276,7 +279,7 @@ public class MessagesListFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
d("MessagesList", "onSaveInstanceState position "+tapPosition);
|
d("MessagesList", "onSaveInstanceState position "+tapPositions[messageType]);
|
||||||
outState.putInt(TAP_POSITION, tapPosition);
|
outState.putInt(TAP_POSITION, tapPositions[messageType]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user