Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If today matches the opening date, scroll to that day. #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sys1yagi
Copy link
Contributor

Issue

None

Overview (Required)

If today matches the opening date, scroll to that day.

Links

Screenshot

Before After
a

@Override
public void onGlobalLayout() {
binding.recyclerView.getLayoutManager().scrollToPosition(position);
binding.recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know why OnGlobalLayoutListener is needed 🙇
Is it enough just to call binding.recyclerView.getLayoutManager().scrollToPosition(position); ?

@sys1yagi sys1yagi changed the title Scroll to the day of the current day. If today matches the opening date, scroll to that day. Mar 10, 2017
.indexed()
.filter(pair -> todayString.equals(pair.getSecond()))
.findFirst()
.orElse(new IntPair<>(0, ""))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no match, position 0 is returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to use Stream? In this case, just for loop seems easy. What do you think?

for (int i = 0; i<= adjustedSessionViewModels.size(); i++) {
  SessionViewModel viewModel = adjustedSessionViewModels.get(i);
  if (todayString.equals(viewModel.getFormattedDate()) {
    return i;
  }
  return 0;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreeee~

@konifar
Copy link
Contributor

konifar commented Mar 11, 2017

👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants