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

Commit ca576593 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Introduce the VolumeDialogSliderComponent to incapsulate and slider...

Merge "Introduce the VolumeDialogSliderComponent to incapsulate and slider logic together" into main
parents 1e9b8eb4 4cc79be1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.volume.dialog.dagger

import com.android.systemui.volume.dialog.dagger.scope.VolumeDialog
import com.android.systemui.volume.dialog.dagger.scope.VolumeDialogScope
import com.android.systemui.volume.dialog.sliders.dagger.VolumeDialogSliderComponent
import dagger.BindsInstance
import dagger.Subcomponent
import kotlinx.coroutines.CoroutineScope
@@ -40,6 +41,8 @@ interface VolumeDialogComponent {

    @VolumeDialogScope fun volumeDialog(): com.android.systemui.volume.dialog.VolumeDialog

    fun sliderComponentFactory(): VolumeDialogSliderComponent.Factory

    @Subcomponent.Factory
    interface Factory {

+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.dialog.sliders.dagger

import com.android.systemui.volume.dialog.sliders.domain.model.VolumeDialogSliderType
import com.android.systemui.volume.dialog.sliders.ui.VolumeDialogSliderViewBinder
import dagger.BindsInstance
import dagger.Subcomponent

/**
 * This component hosts all the stuff, that Volume Dialog sliders need. It's recreated alongside
 * each slider view.
 */
@VolumeDialogSliderScope
@Subcomponent
interface VolumeDialogSliderComponent {

    fun sliderViewBinder(): VolumeDialogSliderViewBinder

    @Subcomponent.Factory
    interface Factory {

        fun create(@BindsInstance sliderType: VolumeDialogSliderType): VolumeDialogSliderComponent
    }
}
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.dialog.sliders.dagger

import javax.inject.Scope

/**
 * Volume Panel Slider dependency injection scope. This scope is created for each of the volume
 * sliders in the dialog.
 */
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Scope
annotation class VolumeDialogSliderScope
+5 −13
Original line number Diff line number Diff line
@@ -17,22 +17,21 @@
package com.android.systemui.volume.dialog.sliders.domain.interactor

import com.android.systemui.plugins.VolumeDialogController
import com.android.systemui.volume.dialog.dagger.scope.VolumeDialogScope
import com.android.systemui.volume.dialog.domain.interactor.VolumeDialogStateInteractor
import com.android.systemui.volume.dialog.shared.model.VolumeDialogStreamModel
import com.android.systemui.volume.dialog.sliders.dagger.VolumeDialogSliderScope
import com.android.systemui.volume.dialog.sliders.domain.model.VolumeDialogSliderType
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull

/** Operates a state of particular slider of the Volume Dialog. */
@VolumeDialogSliderScope
class VolumeDialogSliderInteractor
@AssistedInject
@Inject
constructor(
    @Assisted private val sliderType: VolumeDialogSliderType,
    private val sliderType: VolumeDialogSliderType,
    volumeDialogStateInteractor: VolumeDialogStateInteractor,
    private val volumeDialogController: VolumeDialogController,
) {
@@ -56,11 +55,4 @@ constructor(
            setActiveStream(sliderType.audioStream)
        }
    }

    @VolumeDialogScope
    @AssistedFactory
    interface Factory {

        fun create(sliderType: VolumeDialogSliderType): VolumeDialogSliderInteractor
    }
}
+6 −16
Original line number Diff line number Diff line
@@ -24,16 +24,14 @@ import com.android.systemui.lifecycle.WindowLifecycleState
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.lifecycle.viewModel
import com.android.systemui.res.R
import com.android.systemui.volume.dialog.dagger.scope.VolumeDialogScope
import com.android.systemui.volume.dialog.shared.model.VolumeDialogStreamModel
import com.android.systemui.volume.dialog.sliders.dagger.VolumeDialogSliderScope
import com.android.systemui.volume.dialog.sliders.ui.viewmodel.VolumeDialogSliderViewModel
import com.android.systemui.volume.dialog.ui.utils.JankListenerFactory
import com.android.systemui.volume.dialog.ui.utils.awaitAnimation
import com.google.android.material.slider.LabelFormatter
import com.google.android.material.slider.Slider
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import javax.inject.Inject
import kotlin.math.roundToInt
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.launchIn
@@ -41,10 +39,11 @@ import kotlinx.coroutines.flow.onEach

private const val PROGRESS_CHANGE_ANIMATION_DURATION_MS = 80L

@VolumeDialogSliderScope
class VolumeDialogSliderViewBinder
@AssistedInject
@Inject
constructor(
    @Assisted private val viewModelProvider: () -> VolumeDialogSliderViewModel,
    private val viewModelFactory: VolumeDialogSliderViewModel.Factory,
    private val jankListenerFactory: JankListenerFactory,
) {

@@ -58,7 +57,7 @@ constructor(
                viewModel(
                    traceName = "VolumeDialogSliderViewBinder",
                    minWindowLifecycleState = WindowLifecycleState.ATTACHED,
                    factory = { viewModelProvider() },
                    factory = { viewModelFactory.create() },
                ) { viewModel ->
                    sliderView.addOnChangeListener { _, value, fromUser ->
                        viewModel.setStreamVolume(value.roundToInt(), fromUser)
@@ -85,15 +84,6 @@ constructor(
            )
        }
    }

    @AssistedFactory
    @VolumeDialogScope
    interface Factory {

        fun create(
            viewModelProvider: () -> VolumeDialogSliderViewModel
        ): VolumeDialogSliderViewBinder
    }
}

private suspend fun Slider.setValueAnimated(
Loading