make device setting be able to use both Intent and PendingIntent
BUG: 343317785 Test: local tested Flag: com.android.settings.flags.enable_bluetooth_device_details_polish Change-Id: I0c370d64bda1479778b55dc97e136ff73223f5d3
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.settings.bluetooth.ui.model
|
||||
|
||||
import android.content.Intent
|
||||
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
|
||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingActionModel
|
||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingIcon
|
||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.ToggleModel
|
||||
|
||||
@@ -32,7 +33,7 @@ sealed interface DeviceSettingPreferenceModel {
|
||||
val title: String,
|
||||
val summary: String? = null,
|
||||
val icon: DeviceSettingIcon? = null,
|
||||
val intent: Intent? = null,
|
||||
val action: DeviceSettingActionModel? = null,
|
||||
) : DeviceSettingPreferenceModel
|
||||
|
||||
/** Models a switch preference. */
|
||||
@@ -43,7 +44,7 @@ sealed interface DeviceSettingPreferenceModel {
|
||||
val icon: DeviceSettingIcon? = null,
|
||||
val checked: Boolean,
|
||||
val onCheckedChange: ((Boolean) -> Unit),
|
||||
val intent: Intent? = null,
|
||||
val action: DeviceSettingActionModel? = null,
|
||||
) : DeviceSettingPreferenceModel
|
||||
|
||||
/** Models a multi-toggle preference. */
|
||||
|
@@ -55,6 +55,7 @@ import com.android.settings.core.SubSettingLauncher
|
||||
import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
|
||||
import com.android.settings.spa.preference.ComposePreference
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice
|
||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingActionModel
|
||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingConfigItemModel
|
||||
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingIcon
|
||||
import com.android.settingslib.spa.framework.theme.SettingsDimension
|
||||
@@ -313,10 +314,10 @@ class DeviceDetailsFragmentFormatterImpl(
|
||||
return { deviceSettingIcon(model.icon) }
|
||||
}
|
||||
}
|
||||
if (model.intent != null) {
|
||||
if (model.action != null) {
|
||||
TwoTargetSwitchPreference(
|
||||
switchPrefModel,
|
||||
primaryOnClick = { startActivity(model.intent) },
|
||||
primaryOnClick = { triggerAction(model.action) },
|
||||
)
|
||||
} else {
|
||||
SwitchPreference(switchPrefModel)
|
||||
@@ -330,7 +331,7 @@ class DeviceDetailsFragmentFormatterImpl(
|
||||
override val title = model.title
|
||||
override val summary = { model.summary ?: "" }
|
||||
override val onClick = {
|
||||
model.intent?.let { startActivity(it) }
|
||||
model.action?.let { triggerAction(it) }
|
||||
Unit
|
||||
}
|
||||
override val icon: (@Composable () -> Unit)?
|
||||
@@ -382,9 +383,16 @@ class DeviceDetailsFragmentFormatterImpl(
|
||||
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 triggerAction(action: DeviceSettingActionModel) {
|
||||
when (action) {
|
||||
is DeviceSettingActionModel.IntentAction -> {
|
||||
action.intent.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(action.intent)
|
||||
}
|
||||
is DeviceSettingActionModel.PendingIntentAction -> {
|
||||
action.pendingIntent.send()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}"
|
||||
|
@@ -101,7 +101,7 @@ class BluetoothDeviceDetailsViewModel(
|
||||
DeviceSettingStateModel.ActionSwitchPreferenceState(newState)
|
||||
)
|
||||
},
|
||||
intent = intent,
|
||||
action = action,
|
||||
)
|
||||
} else {
|
||||
DeviceSettingPreferenceModel.PlainPreference(
|
||||
@@ -109,7 +109,7 @@ class BluetoothDeviceDetailsViewModel(
|
||||
title = title,
|
||||
summary = summary,
|
||||
icon = icon,
|
||||
intent = intent,
|
||||
action = action,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user