Use SessionPage instead of integer in SessionPageReselected
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,9 +145,10 @@ class BottomSheetDaySessionsFragment : DaggerFragment() {
binding.isCollapsed = isCollapsed
}
}
- sessionPagesStore.onGoingSessionOnTabReselected(args.day).nonNull()
- .observe(viewLifecycleOwner) {
- binding.sessionsRecycler.scrollToPosition(it)
+ sessionPagesStore.reselectedTab.observe(viewLifecycleOwner) {
+ if (SessionPage.pageOfDay(args.day) == it) {
+ scrollToCurrentSession(args.day)
+ }
}
}
@@ -156,6 +157,11 @@ class BottomSheetDaySessionsFragment : DaggerFragment() {
super.onDestroyView()
}
+ private fun scrollToCurrentSession(day: Int) {
+ val position = sessionPagesStore.onGoingSessionIndex(day)
+ binding.sessionsRecycler.scrollToPosition(position)
+ }
+
companion object {
fun newInstance(
args: BottomSheetDaySessionsFragmentArgs

MODIFY
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/SessionPagesFragment.kt
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/SessionPagesFragment.kt
@@ -125,9 +125,7 @@ class SessionPagesFragment : DaggerFragment() {
object : TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab?) {
tab?.let {
- (SessionPage.pages[it.position] as? SessionPage.Day)?.let { page ->
- sessionPagesActionCreator.reselectTab(page.day)
- }
+ sessionPagesActionCreator.reselectTab(SessionPage.pages[it.position])
}
}

MODIFY
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionPagesActionCreator.kt
feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/actioncreator/SessionPagesActionCreator.kt
@@ -30,8 +30,8 @@ class SessionPagesActionCreator @Inject constructor(
dispatcher.launchAndDispatch(Action.SessionPageSelected(sessionPage))
}
- fun reselectTab(dayNumber: Int) {
- dispatcher.launchAndDispatch(Action.SessionPageReselected(dayNumber))
+ fun reselectTab(sessionPage: SessionPage) {
+ dispatcher.launchAndDispatch(Action.SessionPageReselected(sessionPage))
}
fun changeFilter(room: Room, checked: Boolean) {

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,16 +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<SessionPage> = dispatcher
+ .subscribe<Action.SessionPageReselected>()
+ .map { it.sessionPage }
+ .toSingleLiveData(SessionPage.pages[0])
+
fun filteredSessionsByDay(day: Int): LiveData<List<Session>> {
return filteredSessions
.map { sessions ->
@@ -147,15 +147,7 @@ class SessionPagesStore @Inject constructor(
}
}
- 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
- }
- }
- }
+ fun onGoingSessionIndex(day: Int) = filteredSessions.value.orEmpty()
+ .filter { session -> session.dayNumber == day }
+ .indexOfFirst { session -> session.isOnGoing }
}

MODIFY
frontendcomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/action/Action.kt
frontendcomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/action/Action.kt
@@ -31,7 +31,7 @@ sealed class Action {
) : Action()
data class SessionPageSelected(val sessionPage: SessionPage) : Action()
- data class SessionPageReselected(val dayNumber: Int) : Action()
+ data class SessionPageReselected(val sessionPage: SessionPage) : Action()
class SystemPropertyLoaded(val system: SystemProperty) : Action()
open class FilterChange<T>(val value: T, open val checked: Boolean) : Action()

Use SessionPage instead of integer in SessionPageReselected