Home pager: only listen to unique state changes

Change-Id: I1c7a91ce39636e70279874bc9c66b80ab7bbead6
This commit is contained in:
SpiritCroc 2022-04-24 12:30:44 +02:00
parent f072ce0787
commit 448e62b6dd
2 changed files with 11 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.airbnb.mvrx.UniqueOnly
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@ -234,7 +235,15 @@ class HomeDetailFragment @Inject constructor(
)
}
viewModel.onEach(HomeDetailViewState::roomGroupingMethodIgnoreSwipe, HomeDetailViewState::rootSpacesOrdered, HomeDetailViewState::currentTab) { roomGroupingMethod, rootSpacesOrdered, currentTab ->
viewModel.onEach(HomeDetailViewState::roomGroupingMethodIgnoreSwipe,
HomeDetailViewState::rootSpacesOrdered,
HomeDetailViewState::currentTab,
UniqueOnly("HomeDetail_${System.identityHashCode(this)}"))
{ roomGroupingMethod, rootSpacesOrdered, currentTab ->
if (roomGroupingMethod == null) {
// Uninitialized
return@onEach
}
setupViewPager(roomGroupingMethod, rootSpacesOrdered, currentTab)
}

View File

@ -29,7 +29,7 @@ import org.matrix.android.sdk.api.util.MatrixItem
data class HomeDetailViewState(
val roomGroupingMethod: RoomGroupingMethod = RoomGroupingMethod.BySpace(null),
val roomGroupingMethodIgnoreSwipe: RoomGroupingMethod = RoomGroupingMethod.BySpace(null),
val roomGroupingMethodIgnoreSwipe: RoomGroupingMethod? = null,
val myMatrixItem: MatrixItem? = null,
val asyncRooms: Async<List<RoomSummary>> = Uninitialized,
val currentTab: HomeTab = HomeTab.RoomList(RoomListDisplayMode.ALL),