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

Commit 7c95857c authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge "Minor fix - added RTL support, use `sharedFlow` instead of `stateFlow`...

Merge "Minor fix - added RTL support, use `sharedFlow` instead of `stateFlow` for device items, switch pair new device to the bottom per UX request." into main
parents 928570f9 abb96c7a
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@

    <ImageView
        android:id="@+id/bluetooth_device_icon"
        android:contentDescription="@string/accessibility_bluetooth_device_icon"
        android:layout_width="24dp"
        android:layout_height="24dp"
        app:layout_constraintStart_toStartOf="parent"
@@ -39,8 +38,12 @@
        android:layout_width="0dp"
        android:id="@+id/bluetooth_device_name"
        style="@style/BluetoothTileDialog.DeviceName"
        android:textDirection="locale"
        android:textAlignment="gravity"
        android:paddingStart="20dp"
        android:paddingTop="10dp"
        android:maxLines="1"
        android:ellipsize="end"
        app:layout_constraintWidth_percent="0.7"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@+id/bluetooth_device_icon"
@@ -55,6 +58,8 @@
        style="@style/BluetoothTileDialog.DeviceSummary"
        android:paddingStart="20dp"
        android:paddingBottom="10dp"
        android:maxLines="1"
        android:ellipsize="end"
        app:layout_constraintWidth_percent="0.7"
        app:layout_constraintTop_toBottomOf="@+id/bluetooth_device_name"
        app:layout_constraintStart_toEndOf="@+id/bluetooth_device_icon"
@@ -66,6 +71,7 @@
        android:id="@+id/gear_icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:contentDescription="@string/accessibility_bluetooth_device_settings_gear"
        app:layout_constraintStart_toEndOf="@+id/bluetooth_device_name"
        app:layout_constraintEnd_toEndOf="@+id/gear_icon_image"
        app:layout_constraintTop_toTopOf="parent"
+51 −42
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="24dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/quick_settings_bluetooth_label"
@@ -58,9 +59,12 @@
        style="@style/BluetoothTileDialog.Device"
        android:layout_width="0dp"
        android:layout_height="64dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:layout_marginTop="4dp"
        android:text="@string/turn_on_bluetooth"
        android:clickable="false"
        android:textAppearance="@style/TextAppearance.Dialog.Body.Message"
        android:textSize="16sp"
        app:layout_constraintEnd_toStartOf="@+id/bluetooth_toggle"
@@ -84,53 +88,17 @@
        app:layout_constraintStart_toEndOf="@+id/bluetooth_toggle_title"
        app:layout_constraintTop_toBottomOf="@id/bluetooth_tile_dialog_subtitle" />

    <androidx.constraintlayout.widget.Group
        android:id="@+id/pair_new_device_layout_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:constraint_referenced_ids="ic_add,pair_new_device_text" />

    <ImageView
        android:id="@+id/ic_add"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_marginStart="36dp"
        android:gravity="center_vertical"
        android:importantForAccessibility="no"
        android:src="@drawable/ic_add"
        app:layout_constraintBottom_toTopOf="@id/device_list"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@id/pair_new_device_text"
        app:layout_constraintTop_toBottomOf="@id/bluetooth_toggle_title"
        android:tint="?android:attr/textColorPrimary" />

    <TextView
        android:id="@+id/pair_new_device_text"
        style="@style/BluetoothTileDialog.Device"
        android:layout_width="0dp"
        android:layout_height="@dimen/bluetooth_dialog_device_height"
        android:gravity="center_vertical"
        android:layout_marginStart="0dp"
        android:paddingStart="20dp"
        android:text="@string/pair_new_bluetooth_devices"
        android:textSize="14sp"
        android:textAppearance="@style/TextAppearance.Dialog.Title"
        app:layout_constraintBottom_toTopOf="@id/device_list"
        app:layout_constraintStart_toEndOf="@+id/ic_add"
        app:layout_constraintTop_toBottomOf="@id/bluetooth_toggle_title"
        app:layout_constraintEnd_toEndOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/device_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:nestedScrollingEnabled="false"
        android:overScrollMode="never"
        android:scrollbars="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/pair_new_device_text"
        app:layout_constraintTop_toBottomOf="@id/bluetooth_toggle"
        app:layout_constraintBottom_toTopOf="@+id/see_all_text" />

    <androidx.constraintlayout.widget.Group
@@ -148,7 +116,7 @@
        android:importantForAccessibility="no"
        android:gravity="center_vertical"
        android:src="@drawable/ic_arrow_forward"
        app:layout_constraintBottom_toTopOf="@+id/done_button"
        app:layout_constraintBottom_toTopOf="@+id/pair_new_device_text"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@id/see_all_text"
        app:layout_constraintTop_toBottomOf="@id/device_list" />
@@ -157,18 +125,59 @@
        android:id="@+id/see_all_text"
        style="@style/BluetoothTileDialog.Device"
        android:layout_width="0dp"
        android:layout_height="@dimen/bluetooth_dialog_device_height"
        android:layout_height="64dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:layout_marginStart="0dp"
        android:paddingStart="20dp"
        android:text="@string/see_all_bluetooth_devices"
        android:textSize="14sp"
        android:textAppearance="@style/TextAppearance.Dialog.Title"
        app:layout_constraintBottom_toTopOf="@+id/done_button"
        app:layout_constraintBottom_toTopOf="@+id/pair_new_device_text"
        app:layout_constraintStart_toEndOf="@+id/ic_arrow"
        app:layout_constraintTop_toBottomOf="@id/device_list"
        app:layout_constraintEnd_toEndOf="parent" />

    <androidx.constraintlayout.widget.Group
        android:id="@+id/pair_new_device_layout_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:constraint_referenced_ids="ic_add,pair_new_device_text" />

    <ImageView
        android:id="@+id/ic_add"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_marginStart="36dp"
        android:gravity="center_vertical"
        android:importantForAccessibility="no"
        android:src="@drawable/ic_add"
        app:layout_constraintBottom_toTopOf="@id/done_button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@id/pair_new_device_text"
        app:layout_constraintTop_toBottomOf="@id/see_all_text"
        android:tint="?android:attr/textColorPrimary" />

    <TextView
        android:id="@+id/pair_new_device_text"
        style="@style/BluetoothTileDialog.Device"
        android:layout_width="0dp"
        android:layout_height="64dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:layout_marginStart="0dp"
        android:paddingStart="20dp"
        android:text="@string/pair_new_bluetooth_devices"
        android:textSize="14sp"
        android:textAppearance="@style/TextAppearance.Dialog.Title"
        app:layout_constraintBottom_toTopOf="@id/done_button"
        app:layout_constraintStart_toEndOf="@+id/ic_add"
        app:layout_constraintTop_toBottomOf="@id/see_all_text"
        app:layout_constraintEnd_toEndOf="parent" />

    <Button
        android:id="@+id/done_button"
        style="@style/Widget.Dialog.Button"
@@ -184,5 +193,5 @@
        android:text="@string/inline_done_button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/see_all_text" />
        app:layout_constraintTop_toBottomOf="@id/pair_new_device_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
 No newline at end of file
+6 −5
Original line number Diff line number Diff line
@@ -102,9 +102,10 @@ constructor(
        showSeeAll: Boolean,
        showPairNewDevice: Boolean
    ) {
        deviceItemAdapter.refreshDeviceItemList(deviceItem) {
            seeAllViewGroup.visibility = if (showSeeAll) VISIBLE else GONE
            pairNewDeviceViewGroup.visibility = if (showPairNewDevice) VISIBLE else GONE
        deviceItemAdapter.refreshDeviceItemList(deviceItem)
        }
    }

    internal fun onBluetoothStateUpdated(isEnabled: Boolean, subtitleResId: Int) {
@@ -173,8 +174,8 @@ constructor(

        internal fun getItem(position: Int) = asyncListDiffer.currentList[position]

        internal fun refreshDeviceItemList(updated: List<DeviceItem>) {
            asyncListDiffer.submitList(updated)
        internal fun refreshDeviceItemList(updated: List<DeviceItem>, callback: () -> Unit) {
            asyncListDiffer.submitList(updated, callback)
        }

        internal inner class DeviceItemViewHolder(view: View) : RecyclerView.ViewHolder(view) {
+0 −1
Original line number Diff line number Diff line
@@ -113,7 +113,6 @@ constructor(
                    .launchIn(this)

                deviceItemInteractor.deviceItemUpdate
                    .filterNotNull()
                    .onEach {
                        dialog!!.onDeviceItemUpdated(
                            it.take(MAX_DEVICE_ITEM_ENTRY),
+8 −9
Original line number Diff line number Diff line
@@ -34,10 +34,10 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.withContext

@@ -55,10 +55,10 @@ constructor(
    @Background private val backgroundDispatcher: CoroutineDispatcher,
) {

    private val mutableDeviceItemUpdate: MutableStateFlow<List<DeviceItem>?> =
        MutableStateFlow(null)
    private val mutableDeviceItemUpdate: MutableSharedFlow<List<DeviceItem>> =
        MutableSharedFlow(extraBufferCapacity = 1)
    internal val deviceItemUpdate
        get() = mutableDeviceItemUpdate.asStateFlow()
        get() = mutableDeviceItemUpdate.asSharedFlow()

    internal val deviceItemUpdateRequest: SharedFlow<Unit> =
        conflatedCallbackFlow {
@@ -119,16 +119,15 @@ constructor(

    internal suspend fun updateDeviceItems(context: Context) {
        withContext(backgroundDispatcher) {
            val mostRecentlyConnectedDevices = bluetoothAdapter?.mostRecentlyConnectedDevices

            mutableDeviceItemUpdate.value =
            mutableDeviceItemUpdate.tryEmit(
                bluetoothTileDialogRepository.cachedDevices
                    .mapNotNull { cachedDevice ->
                        deviceItemFactoryList
                            .firstOrNull { it.isFilterMatched(cachedDevice, audioManager) }
                            ?.create(context, cachedDevice)
                    }
                    .sort(displayPriority, mostRecentlyConnectedDevices)
                    .sort(displayPriority, bluetoothAdapter?.mostRecentlyConnectedDevices)
            )
        }
    }

Loading