Scroll to the current session when a Day tab is reselected
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
@@ -9,6 +9,7 @@ import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.AutoTransition
import androidx.transition.TransitionManager
+import com.shopify.livedataktx.observe
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.Item
import com.xwray.groupie.databinding.ViewHolder
@@ -143,6 +144,11 @@ class BottomSheetDaySessionsFragment : DaggerFragment() {
binding.isCollapsed = isCollapsed
}
}
+ sessionPagesStore.reselectedTab.observe(viewLifecycleOwner) {
+ it?.let { position ->
+ binding.sessionsRecycler.scrollToPosition(position)
+ }
+ }
}
override fun onDestroyView() {

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
@@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.Lifecycle
import androidx.viewpager.widget.ViewPager
+import com.google.android.material.tabs.TabLayout
import com.soywiz.klock.DateTime
import com.soywiz.klock.hours
import dagger.Module
@@ -120,6 +121,23 @@ class SessionPagesFragment : DaggerFragment() {
}
)
+ binding.sessionsTabLayout.addOnTabSelectedListener(
+ object : TabLayout.OnTabSelectedListener {
+ override fun onTabReselected(tab: TabLayout.Tab?) {
+ tab?.let {
+ (SessionPage.pages[it.position] as? SessionPage.Day)?.let { page ->
+ sessionPagesActionCreator.reselectTab(page.day)
+ }
+ }
+ }
+
+ override fun onTabUnselected(tab: TabLayout.Tab?) { // no-op
+ }
+
+ override fun onTabSelected(tab: TabLayout.Tab?) { // no-op
+ }
+ })
+
(0 until binding.sessionsTabLayout.tabCount).forEach { tabIndex ->
val tab = binding.sessionsTabLayout.getTabAt(tabIndex)
tab?.let {

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,6 +30,10 @@ class SessionPagesActionCreator @Inject constructor(
dispatcher.launchAndDispatch(Action.SessionPageSelected(sessionPage))
}
+ fun reselectTab(dayNumber: Int) {
+ dispatcher.launchAndDispatch(Action.SessionPageReselected(dayNumber))
+ }
+
fun changeFilter(room: Room, checked: Boolean) {
dispatcher.launchAndDispatch(Action.RoomFilterChanged(room, checked))
}

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
@@ -119,6 +119,14 @@ class SessionPagesStore @Inject constructor(
.map { it.sessionPage }
.toLiveData(SessionPage.pages[0])
+ val reselectedTab: LiveData<Int> = dispatcher
+ .subscribe<Action.SessionPageReselected>()
+ .map { action ->
+ filteredSessions.requireValue()
+ .filter { session -> session.dayNumber == action.dayNumber }
+ .indexOfFirst { session -> session.isOnGoing }
+ }.toLiveData(0)
+
fun filteredSessionsByDay(day: Int): LiveData<List<Session>> {
return filteredSessions
.map { sessions ->

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,6 +31,7 @@ sealed class Action {
) : Action()
data class SessionPageSelected(val sessionPage: SessionPage) : Action()
+ data class SessionPageReselected(val dayNumber: Int) : Action()
class SystemPropertyLoaded(val system: SystemProperty) : Action()
open class FilterChange<T>(val value: T, open val checked: Boolean) : Action()

Scroll to the current session when a Day tab is reselected