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

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

Merge "Add device details more settings page" into main

parents 76d91c98 d5160a80
Loading
Loading
Loading
Loading
+134 −0
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.settingslib.bluetooth.devicesettings;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

/** A data class representing a footer preference. */
public class DeviceSettingFooterPreference extends DeviceSettingPreference implements Parcelable {

    private final String mFooterText;
    private final Bundle mExtras;

    DeviceSettingFooterPreference(
            @NonNull String footerText,
            Bundle extras) {
        super(DeviceSettingType.DEVICE_SETTING_TYPE_MULTI_TOGGLE);
        mFooterText = footerText;
        mExtras = extras;
    }

    /** Read a {@link DeviceSettingFooterPreference} from {@link Parcel}. */
    @NonNull
    public static DeviceSettingFooterPreference readFromParcel(@NonNull Parcel in) {
        String footerText = in.readString();
        Bundle extras = in.readBundle(Bundle.class.getClassLoader());
        return new DeviceSettingFooterPreference(footerText, extras);
    }

    public static final Creator<DeviceSettingFooterPreference> CREATOR =
            new Creator<>() {
                @Override
                @NonNull
                public DeviceSettingFooterPreference createFromParcel(@NonNull Parcel in) {
                    in.readInt();
                    return readFromParcel(in);
                }

                @Override
                @NonNull
                public DeviceSettingFooterPreference[] newArray(int size) {
                    return new DeviceSettingFooterPreference[size];
                }
            };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(mFooterText);
        dest.writeBundle(mExtras);
    }

    /** Builder class for {@link DeviceSettingFooterPreference}. */
    public static final class Builder {
        private String mFooterText = "";
        private Bundle mExtras = Bundle.EMPTY;

        /**
         * Sets the footer text of the preference.
         *
         * @param footerText The footer text of the preference.
         * @return Returns the Builder object.
         */
        @NonNull
        public DeviceSettingFooterPreference.Builder setFooterText(@NonNull String footerText) {
            mFooterText = footerText;
            return this;
        }

        /**
         * Sets the extras bundle.
         *
         * @return Returns the Builder object.
         */
        @NonNull
        public DeviceSettingFooterPreference.Builder setExtras(@NonNull Bundle extras) {
            mExtras = extras;
            return this;
        }

        /**
         * Builds the {@link DeviceSettingFooterPreference} object.
         *
         * @return Returns the built {@link DeviceSettingFooterPreference} object.
         */
        @NonNull
        public DeviceSettingFooterPreference build() {
            return new DeviceSettingFooterPreference(
                    mFooterText, mExtras);
        }
    }

    /**
     * Gets the footer text of the preference.
     *
     * @return The footer text.
     */
    @NonNull
    public String getFooterText() {
        return mFooterText;
    }

    /**
     * Gets the extras Bundle.
     *
     * @return Returns a Bundle object.
     */
    @NonNull
    public Bundle getExtras() {
        return mExtras;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ public abstract class DeviceSettingPreference {
                return ActionSwitchPreference.readFromParcel(in);
            case DeviceSettingType.DEVICE_SETTING_TYPE_MULTI_TOGGLE:
                return MultiTogglePreference.readFromParcel(in);
            case DeviceSettingType.DEVICE_SETTING_TYPE_FOOTER:
                return DeviceSettingFooterPreference.readFromParcel(in);
            default:
                return UNKNOWN;
        }
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import java.lang.annotation.RetentionPolicy;
            DeviceSettingType.DEVICE_SETTING_TYPE_UNKNOWN,
            DeviceSettingType.DEVICE_SETTING_TYPE_ACTION_SWITCH,
            DeviceSettingType.DEVICE_SETTING_TYPE_MULTI_TOGGLE,
            DeviceSettingType.DEVICE_SETTING_TYPE_FOOTER,
        },
        open = true)
public @interface DeviceSettingType {
@@ -38,4 +39,7 @@ public @interface DeviceSettingType {

    /** Device setting type is multi-toggle preference. */
    int DEVICE_SETTING_TYPE_MULTI_TOGGLE = 2;

    /** Device setting type is footer preference. */
    int DEVICE_SETTING_TYPE_FOOTER = 3;
}
+0 −3
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.os.Parcelable
data class DeviceSettingsConfig(
    val mainContentItems: List<DeviceSettingItem>,
    val moreSettingsItems: List<DeviceSettingItem>,
    val moreSettingsFooter: String,
    val extras: Bundle = Bundle.EMPTY,
) : Parcelable {

@@ -41,7 +40,6 @@ data class DeviceSettingsConfig(
        parcel.run {
            writeTypedList(mainContentItems)
            writeTypedList(moreSettingsItems)
            writeString(moreSettingsFooter)
            writeBundle(extras)
        }
    }
@@ -61,7 +59,6 @@ data class DeviceSettingsConfig(
                                arrayListOf<DeviceSettingItem>().also {
                                    readTypedList(it, DeviceSettingItem.CREATOR)
                                },
                            moreSettingsFooter = readString()!!,
                            extras = readBundle((Bundle::class.java.classLoader))!!,
                        )
                    }
+5 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.settingslib.bluetooth.devicesettings.DeviceSetting
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingItem
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfig
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingFooterPreference
import com.android.settingslib.bluetooth.devicesettings.MultiTogglePreference
import com.android.settingslib.bluetooth.devicesettings.ToggleInfo
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingConfigItemModel
@@ -96,8 +97,7 @@ class DeviceSettingRepositoryImpl(
    private fun DeviceSettingsConfig.toModel(): DeviceSettingConfigModel =
        DeviceSettingConfigModel(
            mainItems = mainContentItems.map { it.toModel() },
            moreSettingsItems = moreSettingsItems.map { it.toModel() },
            moreSettingsPageFooter = moreSettingsFooter)
            moreSettingsItems = moreSettingsItems.map { it.toModel() })

    private fun DeviceSettingItem.toModel(): DeviceSettingConfigItemModel {
        return if (!TextUtils.isEmpty(preferenceKey)) {
@@ -151,6 +151,9 @@ class DeviceSettingRepositoryImpl(
                        }
                    },
                )
            is DeviceSettingFooterPreference -> DeviceSettingModel.FooterPreference(
                cachedDevice = cachedDevice,
                id = settingId, footerText = pref.footerText)
            else -> DeviceSettingModel.Unknown(cachedDevice, settingId)
        }

Loading