Fix `When reselected tab then scroll succeeded, the other tab scroll too.`
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
@@ -145,7 +145,8 @@ class BottomSheetDaySessionsFragment : DaggerFragment() {
binding.isCollapsed = isCollapsed
}
}
- sessionPagesStore.reselectedTab.nonNull().observe(viewLifecycleOwner) {
+ sessionPagesStore.onGoingSessionOnTabReselected(args.day).nonNull()
+ .observe(viewLifecycleOwner) {
binding.sessionsRecycler.scrollToPosition(it)
}
}

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
@@ -115,19 +115,16 @@ class SessionPagesStore @Inject constructor(
}
}.map { it.orEmpty() }
+ private val reselectedTab: LiveData<Int> = dispatcher
+ .subscribe<Action.SessionPageReselected>()
+ .map { it.dayNumber }
+ .toSingleLiveData(0)
+
val selectedTab: LiveData<SessionPage> = dispatcher
.subscribe<Action.SessionPageSelected>()
.map { it.sessionPage }
.toLiveData(SessionPage.pages[0])
- val reselectedTab: LiveData<Int> = dispatcher
- .subscribe<Action.SessionPageReselected>()
- .map { action ->
- filteredSessions.value
- ?.filter { session -> session.dayNumber == action.dayNumber }
- ?.indexOfFirst { session -> session.isOnGoing } ?: -1
- }.toSingleLiveData(-1)
-
fun filteredSessionsByDay(day: Int): LiveData<List<Session>> {
return filteredSessions
.map { sessions ->
@@ -149,4 +146,16 @@ class SessionPagesStore @Inject constructor(
.filter { session -> session.isFavorited }
}
}
+
+ fun onGoingSessionOnTabReselected(day: Int): LiveData<Int> {
+ return reselectedTab
+ .map { reselectedDay ->
+ if (reselectedDay != day) -1
+ else {
+ filteredSessions.value
+ ?.filter { session -> session.dayNumber == reselectedDay }
+ ?.indexOfFirst { session -> session.isOnGoing } ?: -1
+ }
+ }
+ }
}

Fix `When reselected tab then scroll succeeded, the other tab scroll too.`