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

Commit f8c88c67 authored by chelseahao's avatar chelseahao Committed by Chelsea Hao
Browse files

Use context from SystemUiDialog to fix button style.

Test: atest -c com.android.systemui.qs.tiles.dialog.bluetooth
Bug: b/329308541
Flag: NA
Change-Id: I4e0bd33975fc4d44bb0680a69fca4232328a45b2
parent e21769f7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
    @Override
    protected void handleClick(@Nullable View view) {
        if (mFeatureFlags.isEnabled(Flags.BLUETOOTH_QS_TILE_DIALOG)) {
            mDialogViewModel.showDialog(mContext, view);
            mDialogViewModel.showDialog(view);
        } else {
            // Secondary clicks are header clicks, just toggle.
            final boolean isEnabled = mState.value;
+9 −14
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.qs.tiles.dialog.bluetooth

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -58,7 +57,6 @@ import kotlinx.coroutines.withContext
class BluetoothTileDialogDelegate
@AssistedInject
internal constructor(
    @Assisted private val context: Context,
    @Assisted private val initialUiProperties: BluetoothTileDialogViewModel.UiProperties,
    @Assisted private val cachedContentHeight: Int,
    @Assisted private val bluetoothToggleInitialValue: Boolean,
@@ -69,11 +67,8 @@ internal constructor(
    private val uiEventLogger: UiEventLogger,
    private val logger: BluetoothTileDialogLogger,
    private val systemuiDialogFactory: SystemUIDialog.Factory,
    mainLayoutInflater: LayoutInflater,
) : SystemUIDialog.Delegate {

    private val layoutInflater = mainLayoutInflater.cloneInContext(context)

    private val mutableBluetoothStateToggle: MutableStateFlow<Boolean> =
        MutableStateFlow(bluetoothToggleInitialValue)
    internal val bluetoothStateToggle
@@ -102,7 +97,6 @@ internal constructor(
    @AssistedFactory
    internal interface Factory {
        fun create(
            context: Context,
            initialUiProperties: BluetoothTileDialogViewModel.UiProperties,
            cachedContentHeight: Int,
            bluetoothEnabled: Boolean,
@@ -112,16 +106,15 @@ internal constructor(
    }

    override fun createDialog(): SystemUIDialog {
        val dialog = systemuiDialogFactory.create(this, context)

        return dialog
        return systemuiDialogFactory.create(this)
    }

    override fun onCreate(dialog: SystemUIDialog, savedInstanceState: Bundle?) {
        SystemUIDialog.registerDismissListener(dialog, dismissListener)
        uiEventLogger.log(BluetoothTileDialogUiEvent.BLUETOOTH_TILE_DIALOG_SHOWN)
        val context = dialog.context

        layoutInflater.inflate(R.layout.bluetooth_tile_dialog, null).apply {
        LayoutInflater.from(context).inflate(R.layout.bluetooth_tile_dialog, null).apply {
            accessibilityPaneTitle = context.getText(R.string.accessibility_desc_quick_settings)
            dialog.setContentView(this)
        }
@@ -201,7 +194,7 @@ internal constructor(
            setEnabled(true)
            alpha = ENABLED_ALPHA
        }
        getSubtitleTextView(dialog).text = context.getString(uiProperties.subTitleResId)
        getSubtitleTextView(dialog).text = dialog.context.getString(uiProperties.subTitleResId)
        getAutoOnToggleView(dialog).visibility = uiProperties.autoOnToggleVisibility
    }

@@ -215,7 +208,7 @@ internal constructor(
            setEnabled(true)
            alpha = ENABLED_ALPHA
        }
        getAutoOnToggleInfoTextView(dialog).text = context.getString(infoResId)
        getAutoOnToggleInfoTextView(dialog).text = dialog.context.getString(infoResId)
    }

    private fun setupToggle(dialog: SystemUIDialog) {
@@ -288,7 +281,7 @@ internal constructor(

    private fun setupRecyclerView(dialog: SystemUIDialog) {
        getDeviceListView(dialog).apply {
            layoutManager = LinearLayoutManager(context)
            layoutManager = LinearLayoutManager(dialog.context)
            adapter = deviceItemAdapter
        }
    }
@@ -343,7 +336,9 @@ internal constructor(
        private val asyncListDiffer = AsyncListDiffer(this, diffUtilCallback)

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DeviceItemViewHolder {
            val view = layoutInflater.inflate(R.layout.bluetooth_device_item, parent, false)
            val view =
                LayoutInflater.from(parent.context)
                    .inflate(R.layout.bluetooth_device_item, parent, false)
            return DeviceItemViewHolder(view)
        }

+4 −6
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.qs.tiles.dialog.bluetooth

import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
@@ -78,19 +77,19 @@ constructor(
    /**
     * Shows the dialog.
     *
     * @param context The context in which the dialog is displayed.
     * @param view The view from which the dialog is shown.
     */
    @kotlinx.coroutines.ExperimentalCoroutinesApi
    fun showDialog(context: Context, view: View?) {
    fun showDialog(view: View?) {
        cancelJob()

        job =
            coroutineScope.launch(mainDispatcher) {
                var updateDeviceItemJob: Job?
                var updateDialogUiJob: Job? = null
                val dialogDelegate = createBluetoothTileDialog(context)
                val dialogDelegate = createBluetoothTileDialog()
                val dialog = dialogDelegate.createDialog()
                val context = dialog.context

                view?.let {
                    dialogTransitionAnimator.showFromView(
@@ -213,7 +212,7 @@ constructor(
            }
    }

    private suspend fun createBluetoothTileDialog(context: Context): BluetoothTileDialogDelegate {
    private suspend fun createBluetoothTileDialog(): BluetoothTileDialogDelegate {
        val cachedContentHeight =
            withContext(backgroundDispatcher) {
                sharedPreferences.getInt(
@@ -223,7 +222,6 @@ constructor(
            }

        return bluetoothDialogDelegateFactory.create(
            context,
            UiProperties.build(
                bluetoothStateInteractor.isBluetoothEnabled,
                isAutoOnToggleFeatureAvailable()
+2 −13
Original line number Diff line number Diff line
@@ -109,7 +109,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {

        mBluetoothTileDialogDelegate =
            BluetoothTileDialogDelegate(
                mContext,
                uiProperties,
                CONTENT_HEIGHT,
                ENABLED,
@@ -119,14 +118,12 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
                fakeSystemClock,
                uiEventLogger,
                logger,
                sysuiDialogFactory,
                LayoutInflater.from(mContext)
                sysuiDialogFactory
            )

        whenever(
                sysuiDialogFactory.create(
                    any(SystemUIDialog.Delegate::class.java),
                    any(Context::class.java)
                    any(SystemUIDialog.Delegate::class.java)
                )
            )
            .thenAnswer {
@@ -216,7 +213,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
            LayoutInflater.from(mContext).inflate(R.layout.bluetooth_device_item, null, false)
        val viewHolder =
            BluetoothTileDialogDelegate(
                    mContext,
                    uiProperties,
                    CONTENT_HEIGHT,
                    ENABLED,
@@ -227,7 +223,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
                    uiEventLogger,
                    logger,
                    sysuiDialogFactory,
                    LayoutInflater.from(mContext)
                )
                .Adapter(bluetoothTileDialogCallback)
                .DeviceItemViewHolder(view)
@@ -273,7 +268,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
            val cachedHeight = Int.MAX_VALUE
            val dialog =
                BluetoothTileDialogDelegate(
                        mContext,
                        BluetoothTileDialogViewModel.UiProperties.build(ENABLED, ENABLED),
                        cachedHeight,
                        ENABLED,
@@ -284,7 +278,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
                        uiEventLogger,
                        logger,
                        sysuiDialogFactory,
                        LayoutInflater.from(mContext)
                    )
                    .createDialog()
            dialog.show()
@@ -298,7 +291,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
        testScope.runTest {
            val dialog =
                BluetoothTileDialogDelegate(
                        mContext,
                        BluetoothTileDialogViewModel.UiProperties.build(ENABLED, ENABLED),
                        MATCH_PARENT,
                        ENABLED,
@@ -309,7 +301,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
                        uiEventLogger,
                        logger,
                        sysuiDialogFactory,
                        LayoutInflater.from(mContext)
                    )
                    .createDialog()
            dialog.show()
@@ -323,7 +314,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
        testScope.runTest {
            val dialog =
                BluetoothTileDialogDelegate(
                        mContext,
                        BluetoothTileDialogViewModel.UiProperties.build(ENABLED, ENABLED),
                        MATCH_PARENT,
                        ENABLED,
@@ -334,7 +324,6 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
                        uiEventLogger,
                        logger,
                        sysuiDialogFactory,
                        LayoutInflater.from(mContext)
                    )
                    .createDialog()
            dialog.show()
+7 −7
Original line number Diff line number Diff line
@@ -147,7 +147,6 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
        whenever(bluetoothStateInteractor.isBluetoothEnabled).thenReturn(true)
        whenever(
                mBluetoothTileDialogDelegateDelegateFactory.create(
                    any(),
                    any(),
                    anyInt(),
                    ArgumentMatchers.anyBoolean(),
@@ -157,6 +156,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
            )
            .thenReturn(bluetoothTileDialogDelegate)
        whenever(bluetoothTileDialogDelegate.createDialog()).thenReturn(sysuiDialog)
        whenever(sysuiDialog.context).thenReturn(mContext)
        whenever(bluetoothTileDialogDelegate.bluetoothStateToggle)
            .thenReturn(getMutableStateFlow(false))
        whenever(bluetoothTileDialogDelegate.deviceItemClick)
@@ -169,7 +169,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
    @Test
    fun testShowDialog_noAnimation() {
        testScope.runTest {
            bluetoothTileDialogViewModel.showDialog(context, null)
            bluetoothTileDialogViewModel.showDialog(null)

            verify(mDialogTransitionAnimator, never()).showFromView(any(), any(), any(), any())
        }
@@ -178,7 +178,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
    @Test
    fun testShowDialog_animated() {
        testScope.runTest {
            bluetoothTileDialogViewModel.showDialog(mContext, LinearLayout(mContext))
            bluetoothTileDialogViewModel.showDialog(LinearLayout(mContext))

            verify(mDialogTransitionAnimator).showFromView(any(), any(), nullable(), anyBoolean())
        }
@@ -188,7 +188,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
    fun testShowDialog_animated_callInBackgroundThread() {
        testScope.runTest {
            backgroundExecutor.execute {
                bluetoothTileDialogViewModel.showDialog(mContext, LinearLayout(mContext))
                bluetoothTileDialogViewModel.showDialog(LinearLayout(mContext))

                verify(mDialogTransitionAnimator)
                    .showFromView(any(), any(), nullable(), anyBoolean())
@@ -199,7 +199,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
    @Test
    fun testShowDialog_fetchDeviceItem() {
        testScope.runTest {
            bluetoothTileDialogViewModel.showDialog(context, null)
            bluetoothTileDialogViewModel.showDialog(null)

            verify(deviceItemInteractor).deviceItemUpdate
        }
@@ -208,7 +208,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
    @Test
    fun testShowDialog_withBluetoothStateValue() {
        testScope.runTest {
            bluetoothTileDialogViewModel.showDialog(context, null)
            bluetoothTileDialogViewModel.showDialog(null)

            verify(bluetoothStateInteractor).bluetoothStateUpdate
        }
@@ -218,7 +218,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
    fun testStartSettingsActivity_activityLaunched_dialogDismissed() {
        testScope.runTest {
            whenever(deviceItem.cachedBluetoothDevice).thenReturn(cachedBluetoothDevice)
            bluetoothTileDialogViewModel.showDialog(context, null)
            bluetoothTileDialogViewModel.showDialog(null)

            val clickedView = View(context)
            bluetoothTileDialogViewModel.onPairNewDeviceClicked(clickedView)