summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chelsea Hao <chelseahao@google.com> 2024-03-21 13:11:48 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-03-21 13:11:48 +0000
commitd05d24232a6d36781796dd77ffef1e3264aedfff (patch)
tree03b8d9cfb0d41e2e3d2768d49c2a73944326fd66
parentd7f79f7d084bf67a511334afe57c6848d4ec3f59 (diff)
parentf8c88c671b33c14c27c04c430e897d8bb0e5cda7 (diff)
Merge "Use context from SystemUiDialog to fix button style." into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt23
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt10
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt14
5 files changed, 23 insertions, 41 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
index 18d2f306c247..b0707db0d02d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java
@@ -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;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt
index 9d5370354fe8..a8d9e781228b 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegate.kt
@@ -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)
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt
index 163df6d7f750..fd624d2f1ba1 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModel.kt
@@ -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
@@ -77,19 +76,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(
@@ -212,7 +211,7 @@ constructor(
}
}
- private suspend fun createBluetoothTileDialog(context: Context): BluetoothTileDialogDelegate {
+ private suspend fun createBluetoothTileDialog(): BluetoothTileDialogDelegate {
val cachedContentHeight =
withContext(backgroundDispatcher) {
sharedPreferences.getInt(
@@ -222,7 +221,6 @@ constructor(
}
return bluetoothDialogDelegateFactory.create(
- context,
UiProperties.build(
bluetoothStateInteractor.isBluetoothEnabled,
isAutoOnToggleFeatureAvailable()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt
index 8ecb95334bc4..17b612714fe2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogDelegateTest.kt
@@ -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()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt
index adea362b2ef4..c8a2aa64ffa2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/bluetooth/BluetoothTileDialogViewModelTest.kt
@@ -143,7 +143,6 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
whenever(
mBluetoothTileDialogDelegateDelegateFactory.create(
any(),
- any(),
anyInt(),
ArgumentMatchers.anyBoolean(),
any(),
@@ -152,6 +151,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)
@@ -164,7 +164,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())
}
@@ -173,7 +173,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())
}
@@ -183,7 +183,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())
@@ -194,7 +194,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
@Test
fun testShowDialog_fetchDeviceItem() {
testScope.runTest {
- bluetoothTileDialogViewModel.showDialog(context, null)
+ bluetoothTileDialogViewModel.showDialog(null)
verify(deviceItemInteractor).deviceItemUpdate
}
@@ -203,7 +203,7 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
@Test
fun testShowDialog_withBluetoothStateValue() {
testScope.runTest {
- bluetoothTileDialogViewModel.showDialog(context, null)
+ bluetoothTileDialogViewModel.showDialog(null)
verify(bluetoothStateInteractor).bluetoothStateUpdate
}
@@ -213,7 +213,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)