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

Commit 86866994 authored by George Lin's avatar George Lin Committed by Automerger Merge Worker
Browse files

Merge "Fix clock preview when changin clock size" into udc-dev am: 370130f1

parents 4a0c6ea8 370130f1
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -176,23 +176,23 @@ object ClockSettingsBinder {
                            ::Pair,
                        )
                        .collect { (clockId, size) ->
                            clockHostView.removeAllViews()
                            val clockView =
                                if (size == ClockSize.DYNAMIC) {
                                    clockViewFactory.getLargeView(clockId)
                                } else {
                                    clockViewFactory.getSmallView(clockId)
                                when (size) {
                                    ClockSize.DYNAMIC -> clockViewFactory.getLargeView(clockId)
                                    ClockSize.SMALL -> clockViewFactory.getSmallView(clockId)
                                }
                            // The clock view might still be attached to an existing parent. Detach
                            // before adding to another parent.
                            (clockView.parent as? ViewGroup)?.removeView(clockView)
                            clockHostView.removeAllViews()
                            clockHostView.addView(clockView)

                            when (size) {
                                ClockSize.DYNAMIC -> {
                                    sizeOptions.radioButtonDynamic.isChecked = true
                                    sizeOptions.radioButtonSmall.isChecked = false
                                    clockHostView.doOnPreDraw {
                                        it.pivotX = (it.width / 2).toFloat()
                                        it.pivotY = (it.height / 2).toFloat()
                                        it.pivotX = it.width / 2F
                                        it.pivotY = it.height / 2F
                                    }
                                }
                                ClockSize.SMALL -> {
+14 −8
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ class ClockCarouselView(
    private lateinit var clockViewFactory: ClockViewFactory
    private var toCenterClockController: ClockController? = null
    private var offCenterClockController: ClockController? = null
    private var toCenterClockView: View? = null
    private var offCenterClockView: View? = null
    private var toCenterClockScaleView: View? = null
    private var offCenterClockScaleView: View? = null
    private var toCenterClockHostView: ClockHostView? = null
    private var offCenterClockHostView: ClockHostView? = null
    private var toCenterCardView: View? = null
@@ -125,8 +125,8 @@ class ClockCarouselView(
                    val scalingUpClockId = adapter.clockIds[scalingUpIdx]
                    offCenterClockController = clockViewFactory.getController(scalingDownClockId)
                    toCenterClockController = clockViewFactory.getController(scalingUpClockId)
                    offCenterClockView = motionLayout.findViewById(R.id.clock_scale_view_2)
                    toCenterClockView =
                    offCenterClockScaleView = motionLayout.findViewById(R.id.clock_scale_view_2)
                    toCenterClockScaleView =
                        motionLayout.findViewById(
                            if (endId == R.id.next) R.id.clock_scale_view_3
                            else R.id.clock_scale_view_1
@@ -166,10 +166,10 @@ class ClockCarouselView(
                        ?.onPickerCarouselSwiping(progress)
                    val scalingDownScale = getScalingDownScale(progress)
                    val scalingUpScale = getScalingUpScale(progress)
                    offCenterClockView?.scaleX = scalingDownScale
                    offCenterClockView?.scaleY = scalingDownScale
                    toCenterClockView?.scaleX = scalingUpScale
                    toCenterClockView?.scaleY = scalingUpScale
                    offCenterClockScaleView?.scaleX = scalingDownScale
                    offCenterClockScaleView?.scaleY = scalingDownScale
                    toCenterClockScaleView?.scaleX = scalingUpScale
                    toCenterClockScaleView?.scaleY = scalingUpScale
                }

                private fun onSmallClockViewTransition(progress: Float) {
@@ -339,6 +339,7 @@ class ClockCarouselView(
                        isMiddleView,
                        clockScaleView,
                        clockId,
                        clockHostView,
                    )
                ClockSize.SMALL ->
                    initializeSmallClockView(
@@ -354,7 +355,12 @@ class ClockCarouselView(
            isMiddleView: Boolean,
            clockScaleView: View,
            clockId: String,
            clockHostView: ClockHostView,
        ) {
            clockHostView.doOnPreDraw {
                it.pivotX = it.width / 2F
                it.pivotY = it.height / 2F
            }
            if (isMiddleView) {
                clockScaleView.scaleX = 1f
                clockScaleView.scaleY = 1f
+21 −6
Original line number Diff line number Diff line
@@ -53,16 +53,31 @@ class ClockViewFactory(
            ?: initClockController(clockId).also { clockControllers[clockId] = it }
    }

    /**
     * Reset the large view to its initial state when getting the view. This is because some view
     * configs, e.g. animation state, might change during the reuse of the clock view in the app.
     */
    fun getLargeView(clockId: String): View {
        return getController(clockId).largeClock.view
        return getController(clockId).largeClock.let {
            it.animations.onPickerCarouselSwiping(1F)
            it.view
        }
    }

    /**
     * Reset the small view to its initial state when getting the view. This is because some view
     * configs, e.g. translation X, might change during the reuse of the clock view in the app.
     */
    fun getSmallView(clockId: String): View {
        return smallClockFrames[clockId]
        val smallClockFrame =
            smallClockFrames[clockId]
                ?: createSmallClockFrame().also {
                    it.addView(getController(clockId).smallClock.view)
                    smallClockFrames[clockId] = it
                }
        smallClockFrame.translationX = 0F
        smallClockFrame.translationY = 0F
        return smallClockFrame
    }

    private fun createSmallClockFrame(): FrameLayout {