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

Commit 2b47ca16 authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Reimplement device details UI without ComposePreference" into main

parents 173dceca 02bd6458
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2025 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <solid
                android:color="@color/settingslib_materialColorSecondaryContainer" />
            <corners
                android:radius="28dp" />
        </shape>
    </item>
</ripple>
+73 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2025 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="?android:attr/selectableItemBackground">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginHorizontal="16dp"
        android:background="@drawable/device_details_spotlight_preference_background" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?android:attr/listPreferredItemHeight"
        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
        android:gravity="center_vertical">

        <ImageView
            android:id="@+android:id/icon"
            android:layout_width="24dip"
            android:layout_height="24dip"
            android:layout_gravity="center"
            android:scaleType="center"
            android:importantForAccessibility="no" />

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp"
            android:layout_marginEnd="6dp"
            android:layout_marginTop="6dp"
            android:layout_marginBottom="6dp"
            android:layout_weight="1">

            <TextView android:id="@+android:id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:ellipsize="marquee"
                android:fadingEdge="horizontal" />

            <TextView android:id="@+android:id/summary"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@android:id/title"
                android:layout_alignStart="@android:id/title"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="?android:attr/textColorSecondary"
                android:maxLines="4" />
        </RelativeLayout>
    </LinearLayout>
</FrameLayout>
+0 −28
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.bluetooth.ui.layout

import kotlinx.coroutines.flow.Flow

/** Represent the layout of device settings. */
data class DeviceSettingLayout(val rows: List<DeviceSettingLayoutRow>)

/** Represent a row in the layout. */
data class DeviceSettingLayoutRow(val columns: Flow<List<DeviceSettingLayoutColumn>>)

/** Represent a column in a row. */
data class DeviceSettingLayoutColumn(val settingId: Int, val highlighted: Boolean)
+247 −241

File changed.

Preview size limit exceeded, changes collapsed.

+0 −43
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.android.settings.R
import com.android.settings.bluetooth.ui.layout.DeviceSettingLayout
import com.android.settings.bluetooth.ui.layout.DeviceSettingLayoutColumn
import com.android.settings.bluetooth.ui.layout.DeviceSettingLayoutRow
import com.android.settings.bluetooth.ui.model.DeviceSettingPreferenceModel
import com.android.settings.bluetooth.ui.model.FragmentTypeModel
import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
@@ -39,11 +36,8 @@ import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

class BluetoothDeviceDetailsViewModel(
    private val application: Application,
@@ -141,43 +135,6 @@ class BluetoothDeviceDetailsViewModel(
        }
    }

    suspend fun getLayout(fragment: FragmentTypeModel): DeviceSettingLayout? {
        val configItems = getItems(fragment) ?: return null
        val idToDeviceSetting =
            configItems
                .filterIsInstance<DeviceSettingConfigItemModel.AppProvidedItem>()
                .associateBy({ it.settingId }, { getDeviceSetting(cachedDevice, it.settingId) })

        val configDeviceSetting =
            configItems.map { idToDeviceSetting[it.settingId] ?: flowOf(null) }
        val positionToSettingIds =
            combine(configDeviceSetting) { settings ->
                    val positionMapping = mutableMapOf<Int, List<DeviceSettingLayoutColumn>>()
                    for (i in settings.indices) {
                        val configItem = configItems[i]
                        val setting = settings[i]
                        val isXmlPreference = configItem is DeviceSettingConfigItemModel.BuiltinItem
                        if (!isXmlPreference && setting == null) {
                            continue
                        }
                        positionMapping[i] =
                            listOf(
                                DeviceSettingLayoutColumn(
                                    configItem.settingId,
                                    configItem.highlighted,
                                )
                            )
                    }
                    positionMapping
                }
                .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), initialValue = mapOf())
        return DeviceSettingLayout(
            configItems.indices.map { idx ->
                DeviceSettingLayoutRow(positionToSettingIds.map { it[idx] ?: emptyList() })
            }
        )
    }

    class Factory(
        private val application: Application,
        private val bluetoothAdapter: BluetoothAdapter,
Loading