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

Commit 1020e713 authored by Haijie Hong's avatar Haijie Hong
Browse files

Fix two-panel issue in tablet

Keep the logic same as BlockingPrefWithSliceController.

BUG: 343317785
Test: atest BluetoothDeviceDetailsViewModelTest
Flag: com.android.settings.flags.enable_bluetooth_device_details_polish
Change-Id: I77e62479def433869ae5e93987ec7069cc61173a
parent 8be12edf
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -16,6 +16,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.DeviceSettingIcon
import com.android.settingslib.bluetooth.devicesettings.shared.model.ToggleModel
@@ -31,7 +32,7 @@ sealed interface DeviceSettingPreferenceModel {
        val title: String,
        val summary: String? = null,
        val icon: DeviceSettingIcon? = null,
        val onClick: (() -> Unit)? = null,
        val intent: Intent? = null,
    ) : DeviceSettingPreferenceModel

    /** Models a switch preference. */
@@ -42,7 +43,7 @@ sealed interface DeviceSettingPreferenceModel {
        val icon: DeviceSettingIcon? = null,
        val checked: Boolean,
        val onCheckedChange: ((Boolean) -> Unit),
        val onPrimaryClick: (() -> Unit)? = null,
        val intent: Intent? = null,
    ) : DeviceSettingPreferenceModel

    /** Models a multi-toggle preference. */
@@ -71,6 +72,6 @@ sealed interface DeviceSettingPreferenceModel {
    data class HelpPreference(
        @DeviceSettingId override val id: Int,
        val icon: DeviceSettingIcon,
        val onClick: (() -> Unit),
        val intent: Intent,
    ) : DeviceSettingPreferenceModel
}
+11 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.bluetooth.ui.view

import android.bluetooth.BluetoothAdapter
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.os.Bundle
import androidx.compose.animation.AnimatedVisibility
@@ -101,13 +102,13 @@ class DeviceDetailsFragmentFormatterImpl(
) : DeviceDetailsFragmentFormatter {
    private val repository =
        featureFactory.bluetoothFeatureProvider.getDeviceSettingRepository(
            context,
            fragment.requireActivity().application,
            bluetoothAdapter,
            fragment.lifecycleScope,
        )
    private val spatialAudioInteractor =
        featureFactory.bluetoothFeatureProvider.getSpatialAudioInteractor(
            context,
            fragment.requireActivity().application,
            context.getSystemService(AudioManager::class.java),
            fragment.lifecycleScope,
        )
@@ -312,10 +313,10 @@ class DeviceDetailsFragmentFormatterImpl(
                        return { deviceSettingIcon(model.icon) }
                    }
            }
        if (model.onPrimaryClick != null) {
        if (model.intent != null) {
            TwoTargetSwitchPreference(
                switchPrefModel,
                primaryOnClick = model.onPrimaryClick::invoke,
                primaryOnClick = { startActivity(model.intent) },
            )
        } else {
            SwitchPreference(switchPrefModel)
@@ -329,7 +330,7 @@ class DeviceDetailsFragmentFormatterImpl(
                override val title = model.title
                override val summary = { model.summary ?: "" }
                override val onClick = {
                    model.onClick?.invoke()
                    model.intent?.let { startActivity(it) }
                    Unit
                }
                override val icon: (@Composable () -> Unit)?
@@ -376,6 +377,11 @@ 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 getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}"

    companion object {
+5 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth.ui.view
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.Intent
import android.graphics.PorterDuff
import android.os.Bundle
import android.view.Menu
@@ -73,7 +74,10 @@ class DeviceDetailsMoreSettingsFragment : DashboardFragment() {

    override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
        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 super.onOptionsItemSelected(menuItem)
+3 −3
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ class BluetoothDeviceDetailsViewModel(
                                DeviceSettingStateModel.ActionSwitchPreferenceState(newState)
                            )
                        },
                        onPrimaryClick = { intent?.let { application.startActivity(it) } },
                        intent = intent,
                    )
                } else {
                    DeviceSettingPreferenceModel.PlainPreference(
@@ -109,7 +109,7 @@ class BluetoothDeviceDetailsViewModel(
                        title = title,
                        summary = summary,
                        icon = icon,
                        onClick = { intent?.let { application.startActivity(it) } },
                        intent = intent,
                    )
                }
            }
@@ -119,7 +119,7 @@ class BluetoothDeviceDetailsViewModel(
                DeviceSettingPreferenceModel.HelpPreference(
                    id = id,
                    icon = DeviceSettingIcon.ResourceIcon(R.drawable.ic_help),
                    onClick = { application.startActivity(intent) },
                    intent = intent,
                )
            is DeviceSettingModel.MultiTogglePreference ->
                DeviceSettingPreferenceModel.MultiTogglePreference(
+1 −3
Original line number Diff line number Diff line
@@ -178,11 +178,9 @@ class DeviceDetailsFragmentFormatterTest {
            }.launchIn(testScope.backgroundScope)
            delay(100)
            runCurrent()
            helpPreference!!.onClick()
            ShadowLooper.idleMainLooper()

            val shadowActivity = Shadows.shadowOf(fragmentActivity)
            assertThat(shadowActivity.nextStartedActivity).isSameInstanceAs(intent)
            assertThat(helpPreference?.intent).isSameInstanceAs(intent)
        }
    }