-
Notifications
You must be signed in to change notification settings - Fork 140
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package io.github.droidkaigi.confsched2017.view.fragment; | ||
|
||
import com.annimon.stream.IntPair; | ||
import com.annimon.stream.Stream; | ||
|
||
import org.lucasr.twowayview.TwoWayLayoutManager; | ||
import org.lucasr.twowayview.widget.DividerItemDecoration; | ||
import org.lucasr.twowayview.widget.SpannableGridLayoutManager; | ||
|
@@ -23,6 +26,7 @@ | |
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.ViewTreeObserver; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
|
@@ -36,6 +40,7 @@ | |
import io.github.droidkaigi.confsched2017.databinding.FragmentSessionsBinding; | ||
import io.github.droidkaigi.confsched2017.databinding.ViewSessionCellBinding; | ||
import io.github.droidkaigi.confsched2017.model.Room; | ||
import io.github.droidkaigi.confsched2017.util.DateUtil; | ||
import io.github.droidkaigi.confsched2017.util.ViewUtil; | ||
import io.github.droidkaigi.confsched2017.view.activity.MySessionsActivity; | ||
import io.github.droidkaigi.confsched2017.view.activity.SearchActivity; | ||
|
@@ -217,6 +222,28 @@ private void renderSessions(List<SessionViewModel> adjustedSessionViewModels) { | |
binding.txtDate.setText(adjustedSessionViewModels.get(0).getFormattedDate()); | ||
binding.txtDate.setVisibility(View.VISIBLE); | ||
} | ||
scrollTo(extractTodayPos(getContext(), new Date(), adjustedSessionViewModels)); | ||
} | ||
|
||
private int extractTodayPos(Context context, Date today, List<SessionViewModel> adjustedSessionViewModels) { | ||
String todayString = DateUtil.getMonthDate(today, context); | ||
return Stream.of(adjustedSessionViewModels) | ||
.map(SessionViewModel::getFormattedDate) | ||
.indexed() | ||
.filter(pair -> todayString.equals(pair.getSecond())) | ||
.findFirst() | ||
.orElse(new IntPair<>(0, "")) | ||
.getFirst(); | ||
} | ||
|
||
private void scrollTo(int position) { | ||
binding.recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | ||
@Override | ||
public void onGlobalLayout() { | ||
binding.recyclerView.getLayoutManager().scrollToPosition(position); | ||
binding.recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't know why |
||
} | ||
}); | ||
} | ||
|
||
private void renderHeaderRow(List<Room> rooms) { | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreeee~