Merge "Fix two-panel issue in tablet" into main
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth.ui.model
|
package com.android.settings.bluetooth.ui.model
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
|
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
|
||||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingIcon
|
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingIcon
|
||||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.ToggleModel
|
import com.android.settingslib.bluetooth.devicesettings.shared.model.ToggleModel
|
||||||
@@ -31,7 +32,7 @@ sealed interface DeviceSettingPreferenceModel {
|
|||||||
val title: String,
|
val title: String,
|
||||||
val summary: String? = null,
|
val summary: String? = null,
|
||||||
val icon: DeviceSettingIcon? = null,
|
val icon: DeviceSettingIcon? = null,
|
||||||
val onClick: (() -> Unit)? = null,
|
val intent: Intent? = null,
|
||||||
) : DeviceSettingPreferenceModel
|
) : DeviceSettingPreferenceModel
|
||||||
|
|
||||||
/** Models a switch preference. */
|
/** Models a switch preference. */
|
||||||
@@ -42,7 +43,7 @@ sealed interface DeviceSettingPreferenceModel {
|
|||||||
val icon: DeviceSettingIcon? = null,
|
val icon: DeviceSettingIcon? = null,
|
||||||
val checked: Boolean,
|
val checked: Boolean,
|
||||||
val onCheckedChange: ((Boolean) -> Unit),
|
val onCheckedChange: ((Boolean) -> Unit),
|
||||||
val onPrimaryClick: (() -> Unit)? = null,
|
val intent: Intent? = null,
|
||||||
) : DeviceSettingPreferenceModel
|
) : DeviceSettingPreferenceModel
|
||||||
|
|
||||||
/** Models a multi-toggle preference. */
|
/** Models a multi-toggle preference. */
|
||||||
@@ -71,6 +72,6 @@ sealed interface DeviceSettingPreferenceModel {
|
|||||||
data class HelpPreference(
|
data class HelpPreference(
|
||||||
@DeviceSettingId override val id: Int,
|
@DeviceSettingId override val id: Int,
|
||||||
val icon: DeviceSettingIcon,
|
val icon: DeviceSettingIcon,
|
||||||
val onClick: (() -> Unit),
|
val intent: Intent,
|
||||||
) : DeviceSettingPreferenceModel
|
) : DeviceSettingPreferenceModel
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.bluetooth.ui.view
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter
|
import android.bluetooth.BluetoothAdapter
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
@@ -101,13 +102,13 @@ class DeviceDetailsFragmentFormatterImpl(
|
|||||||
) : DeviceDetailsFragmentFormatter {
|
) : DeviceDetailsFragmentFormatter {
|
||||||
private val repository =
|
private val repository =
|
||||||
featureFactory.bluetoothFeatureProvider.getDeviceSettingRepository(
|
featureFactory.bluetoothFeatureProvider.getDeviceSettingRepository(
|
||||||
context,
|
fragment.requireActivity().application,
|
||||||
bluetoothAdapter,
|
bluetoothAdapter,
|
||||||
fragment.lifecycleScope,
|
fragment.lifecycleScope,
|
||||||
)
|
)
|
||||||
private val spatialAudioInteractor =
|
private val spatialAudioInteractor =
|
||||||
featureFactory.bluetoothFeatureProvider.getSpatialAudioInteractor(
|
featureFactory.bluetoothFeatureProvider.getSpatialAudioInteractor(
|
||||||
context,
|
fragment.requireActivity().application,
|
||||||
context.getSystemService(AudioManager::class.java),
|
context.getSystemService(AudioManager::class.java),
|
||||||
fragment.lifecycleScope,
|
fragment.lifecycleScope,
|
||||||
)
|
)
|
||||||
@@ -312,10 +313,10 @@ class DeviceDetailsFragmentFormatterImpl(
|
|||||||
return { deviceSettingIcon(model.icon) }
|
return { deviceSettingIcon(model.icon) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (model.onPrimaryClick != null) {
|
if (model.intent != null) {
|
||||||
TwoTargetSwitchPreference(
|
TwoTargetSwitchPreference(
|
||||||
switchPrefModel,
|
switchPrefModel,
|
||||||
primaryOnClick = model.onPrimaryClick::invoke,
|
primaryOnClick = { startActivity(model.intent) },
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
SwitchPreference(switchPrefModel)
|
SwitchPreference(switchPrefModel)
|
||||||
@@ -329,7 +330,7 @@ class DeviceDetailsFragmentFormatterImpl(
|
|||||||
override val title = model.title
|
override val title = model.title
|
||||||
override val summary = { model.summary ?: "" }
|
override val summary = { model.summary ?: "" }
|
||||||
override val onClick = {
|
override val onClick = {
|
||||||
model.onClick?.invoke()
|
model.intent?.let { startActivity(it) }
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
override val icon: (@Composable () -> Unit)?
|
override val icon: (@Composable () -> Unit)?
|
||||||
@@ -376,6 +377,11 @@ class DeviceDetailsFragmentFormatterImpl(
|
|||||||
icon?.let { Icon(it, modifier = Modifier.size(SettingsDimension.itemIconSize)) }
|
icon?.let { Icon(it, modifier = Modifier.size(SettingsDimension.itemIconSize)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun startActivity(intent: Intent) {
|
||||||
|
intent.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}"
|
private fun getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}"
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth.ui.view
|
|||||||
import android.bluetooth.BluetoothDevice
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.BluetoothManager
|
import android.bluetooth.BluetoothManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
@@ -73,7 +74,10 @@ class DeviceDetailsMoreSettingsFragment : DashboardFragment() {
|
|||||||
|
|
||||||
override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
|
override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
|
||||||
if (menuItem.itemId == MENU_HELP_ITEM_ID) {
|
if (menuItem.itemId == MENU_HELP_ITEM_ID) {
|
||||||
helpItem.value?.let { it.onClick() }
|
helpItem.value?.intent?.let {
|
||||||
|
it.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
requireContext().startActivity(it)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(menuItem)
|
return super.onOptionsItemSelected(menuItem)
|
||||||
|
@@ -101,7 +101,7 @@ class BluetoothDeviceDetailsViewModel(
|
|||||||
DeviceSettingStateModel.ActionSwitchPreferenceState(newState)
|
DeviceSettingStateModel.ActionSwitchPreferenceState(newState)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onPrimaryClick = { intent?.let { application.startActivity(it) } },
|
intent = intent,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
DeviceSettingPreferenceModel.PlainPreference(
|
DeviceSettingPreferenceModel.PlainPreference(
|
||||||
@@ -109,7 +109,7 @@ class BluetoothDeviceDetailsViewModel(
|
|||||||
title = title,
|
title = title,
|
||||||
summary = summary,
|
summary = summary,
|
||||||
icon = icon,
|
icon = icon,
|
||||||
onClick = { intent?.let { application.startActivity(it) } },
|
intent = intent,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ class BluetoothDeviceDetailsViewModel(
|
|||||||
DeviceSettingPreferenceModel.HelpPreference(
|
DeviceSettingPreferenceModel.HelpPreference(
|
||||||
id = id,
|
id = id,
|
||||||
icon = DeviceSettingIcon.ResourceIcon(R.drawable.ic_help),
|
icon = DeviceSettingIcon.ResourceIcon(R.drawable.ic_help),
|
||||||
onClick = { application.startActivity(intent) },
|
intent = intent,
|
||||||
)
|
)
|
||||||
is DeviceSettingModel.MultiTogglePreference ->
|
is DeviceSettingModel.MultiTogglePreference ->
|
||||||
DeviceSettingPreferenceModel.MultiTogglePreference(
|
DeviceSettingPreferenceModel.MultiTogglePreference(
|
||||||
|
@@ -178,11 +178,9 @@ class DeviceDetailsFragmentFormatterTest {
|
|||||||
}.launchIn(testScope.backgroundScope)
|
}.launchIn(testScope.backgroundScope)
|
||||||
delay(100)
|
delay(100)
|
||||||
runCurrent()
|
runCurrent()
|
||||||
helpPreference!!.onClick()
|
|
||||||
ShadowLooper.idleMainLooper()
|
ShadowLooper.idleMainLooper()
|
||||||
|
|
||||||
val shadowActivity = Shadows.shadowOf(fragmentActivity)
|
assertThat(helpPreference?.intent).isSameInstanceAs(intent)
|
||||||
assertThat(shadowActivity.nextStartedActivity).isSameInstanceAs(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user