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

Commit dc8ac313 authored by Luna Zhang's avatar Luna Zhang
Browse files

Update bluetooth details view to use dynamic title and subtitle

Flag: com.android.systemui.qs_tile_detailed_view
Test: BluetoothDetailsContentViewModelTest
Change-Id: Ideaa6e8204a4eacf0f7ae9b2242bb73fd49d61d4
parent bfe52e84
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ constructor(
    private lateinit var contentView: View
    private lateinit var doneButton: Button
    private lateinit var bluetoothToggle: Switch
    private lateinit var titleTextView: TextView
    private lateinit var subtitleTextView: TextView
    private lateinit var seeAllButton: View
    private lateinit var pairNewDeviceButton: View
@@ -163,6 +164,7 @@ constructor(

        doneButton = contentView.requireViewById(R.id.done_button)
        bluetoothToggle = contentView.requireViewById(R.id.bluetooth_toggle)
        titleTextView = contentView.requireViewById(R.id.bluetooth_tile_dialog_title)
        subtitleTextView = contentView.requireViewById(R.id.bluetooth_tile_dialog_subtitle)
        seeAllButton = contentView.requireViewById(R.id.see_all_button)
        pairNewDeviceButton = contentView.requireViewById(R.id.pair_new_device_button)
@@ -182,7 +184,15 @@ constructor(
        setupRecyclerView()
        setupDoneButton()

        if (isInDialog) {
            subtitleTextView.text = contentView.context.getString(initialUiProperties.subTitleResId)
        } else {
            // If rendering with tile details view, the title and subtitle will be added in the
            // `TileDetails`
            titleTextView.visibility = GONE
            subtitleTextView.visibility = GONE
        }

        seeAllButton.setOnClickListener { onSeeAllClicked(it) }
        pairNewDeviceButton.setOnClickListener { onPairNewDeviceClicked(it) }
        audioSharingButton.apply {
@@ -332,7 +342,9 @@ constructor(
            setEnabled(true)
            alpha = ENABLED_ALPHA
        }
        if (isInDialog) {
            subtitleTextView.text = contentView.context.getString(uiProperties.subTitleResId)
        }
        autoOnToggleLayout.visibility = uiProperties.autoOnToggleVisibility
    }

+14 −2
Original line number Diff line number Diff line
@@ -24,6 +24,9 @@ import android.view.View.VISIBLE
import android.view.ViewGroup
import androidx.annotation.DimenRes
import androidx.annotation.StringRes
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.internal.jank.InteractionJankMonitor
import com.android.settingslib.volume.domain.interactor.AudioModeInteractor
@@ -88,6 +91,12 @@ constructor(
    private val bluetoothDetailsContentManagerFactory: BluetoothDetailsContentManager.Factory,
) {

    var title by mutableStateOf("")
        private set

    var subTitle by mutableStateOf("")
        private set

    lateinit var contentManager: BluetoothDetailsContentManager
    private var job: Job? = null

@@ -183,6 +192,8 @@ constructor(
                deviceItemInteractor.updateDeviceItems(context, DeviceFetchTrigger.FIRST_LOAD)
            }

            title = context.getString(R.string.quick_settings_bluetooth_label)

            // deviceItemUpdate is emitted when device item list is done fetching, update UI and
            // stop the progress bar.
            combine(deviceItemInteractor.deviceItemUpdate, deviceItemInteractor.showSeeAllUpdate) {
@@ -257,8 +268,9 @@ constructor(
            // the device item list.
            bluetoothStateInteractor.bluetoothStateUpdate
                .onEach {
                    detailsUIState.bluetoothState.value =
                        BluetoothState(it, UiProperties.build(it, isAutoOnToggleFeatureAvailable()))
                    val uiProperties = UiProperties.build(it, isAutoOnToggleFeatureAvailable())
                    subTitle = context.getString(uiProperties.subTitleResId)
                    detailsUIState.bluetoothState.value = BluetoothState(it, uiProperties)
                    updateDeviceItemJob?.cancel()
                    updateDeviceItemJob = launch {
                        deviceItemInteractor.updateDeviceItems(
+4 −4
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ class BluetoothDetailsViewModel(
        onSettingsClick()
    }

    // TODO: b/378513956 Update the placeholder text
    override val title = "Bluetooth"
    override val title: String
        get() = detailsContentViewModel.title

    // TODO: b/378513956 Update the placeholder text
    override val subTitle = "Tap to connect or disconnect a device"
    override val subTitle: String
        get() = detailsContentViewModel.subTitle
}
+14 −0
Original line number Diff line number Diff line
@@ -312,4 +312,18 @@ class BluetoothDetailsContentViewModelTest : SysuiTestCase() {
            assertThat(actual).isFalse()
        }
    }

    @Test
    fun testUpdateTitleAndSubtitle() {
        testScope.runTest {
            assertThat(bluetoothDetailsContentViewModel.title).isEqualTo("")
            assertThat(bluetoothDetailsContentViewModel.subTitle).isEqualTo("")

            bluetoothDetailsContentViewModel.showDialog(expandable)
            runCurrent()

            assertThat(bluetoothDetailsContentViewModel.title).isEqualTo("Bluetooth")
            assertThat(bluetoothDetailsContentViewModel.subTitle).isEqualTo("Bluetooth is off")
        }
    }
}