Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be6f23f0 authored by Abdullah Tabassum's avatar Abdullah Tabassum Committed by Android (Google) Code Review
Browse files

Merge "Restore selected color position" into udc-dev

parents 46319ff0 5d5dd426
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -92,6 +92,22 @@ object ColorPickerBinder {
                launch {
                    viewModel.colorOptions.collect { colorOptions ->
                        colorOptionAdapter.setItems(colorOptions)
                        // the same recycler view is used for different color types tabs
                        // the scroll state of each tab should be independent of others
                        var indexToFocus = 0
                        colorOptions.forEachIndexed { index, colorOption ->
                            if (colorOption.isSelected.value) {
                                indexToFocus = index
                            }
                        }
                        val linearLayoutManager =
                            object : LinearLayoutManager(view.context, HORIZONTAL, false) {
                                override fun onLayoutCompleted(state: RecyclerView.State?) {
                                    super.onLayoutCompleted(state)
                                    scrollToPosition(indexToFocus)
                                }
                            }
                        colorOptionContainerView.layoutManager = linearLayoutManager
                    }
                }
            }