Move code of getting index to Fragment
MODIFY
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/BottomSheetDaySessionsFragment.kt
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/BottomSheetDaySessionsFragment.kt
@@ -146,7 +146,7 @@ class BottomSheetDaySessionsFragment : DaggerFragment() {
}
sessionPagesStore.reselectedTab.observe(viewLifecycleOwner) {
if (SessionPage.pageOfDay(args.day) == it) {
- scrollToCurrentSession(args.day)
+ scrollToCurrentSession()
}
}
}
@@ -156,8 +156,10 @@ class BottomSheetDaySessionsFragment : DaggerFragment() {
super.onDestroyView()
}
- private fun scrollToCurrentSession(day: Int) {
- val position = sessionPagesStore.onGoingSessionIndex(day)
+ private fun scrollToCurrentSession() {
+ val position = sessionPagesStore.filteredSessions.value.orEmpty()
+ .filter { session -> session.dayNumber == args.day }
+ .indexOfFirst { session -> session.isOnGoing }
binding.sessionsRecycler.scrollToPosition(position)
}

MODIFY
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/store/SessionPagesStore.kt
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/store/SessionPagesStore.kt
@@ -107,7 +107,7 @@ class SessionPagesStore @Inject constructor(
}
val filtersValue: Filters get() = filters.requireValue()
- private val filteredSessions: LiveData<List<Session>> = sessions
+ val filteredSessions: LiveData<List<Session>> = sessions
.combineWith(filters) { sessions, filters ->
sessions ?: return@combineWith listOf<Session>()
sessions.filter { session ->
@@ -146,8 +146,4 @@ class SessionPagesStore @Inject constructor(
.filter { session -> session.isFavorited }
}
}
-
- fun onGoingSessionIndex(day: Int) = filteredSessions.value.orEmpty()
- .filter { session -> session.dayNumber == day }
- .indexOfFirst { session -> session.isOnGoing }
}

Move code of getting index to Fragment