summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.kt21
-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, 22 insertions, 40 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 7ece6e0defc1..9866459d978d 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
@@ -57,7 +56,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,
@@ -68,11 +66,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
@@ -101,7 +96,6 @@ internal constructor(
@AssistedFactory
internal interface Factory {
fun create(
- context: Context,
initialUiProperties: BluetoothTileDialogViewModel.UiProperties,
cachedContentHeight: Int,
bluetoothEnabled: Boolean,
@@ -111,16 +105,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)
}
@@ -200,7 +193,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
}
@@ -278,7 +271,7 @@ internal constructor(
private fun setupRecyclerView(dialog: SystemUIDialog) {
getDeviceListView(dialog).apply {
- layoutManager = LinearLayoutManager(context)
+ layoutManager = LinearLayoutManager(dialog.context)
adapter = deviceItemAdapter
}
}
@@ -333,7 +326,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 04862077969d..e3dbeb4154d1 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
@@ -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(
@@ -206,7 +205,7 @@ constructor(
}
}
- private suspend fun createBluetoothTileDialog(context: Context): BluetoothTileDialogDelegate {
+ private suspend fun createBluetoothTileDialog(): BluetoothTileDialogDelegate {
val cachedContentHeight =
withContext(backgroundDispatcher) {
sharedPreferences.getInt(
@@ -216,7 +215,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 39e2413be40e..d2724ff3fbde 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
@@ -148,7 +148,6 @@ class BluetoothTileDialogViewModelTest : SysuiTestCase() {
whenever(
mBluetoothTileDialogDelegateDelegateFactory.create(
any(),
- any(),
anyInt(),
ArgumentMatchers.anyBoolean(),
any(),
@@ -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)