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

Commit 3f7c4cbe authored by Anton Potapov's avatar Anton Potapov
Browse files

Adds PlatformColor to model Color

PlatformColor allows ViewModel to provide Color that can be either
resolvable color or a specific value without a direct Compose
dependency.

Flag: N/A
Bug: 323538193
Test: N/A
Change-Id: Ie8162d9386e167bdae2b76e8c2a18ddc616fd1ed
parent 61b0f8fa
Loading
Loading
Loading
Loading
+32 −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.systemui.common.ui.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
import com.android.compose.theme.colorAttr

/** Resolves [com.android.systemui.common.shared.model.Color] into [Color] */
@Composable
@ReadOnlyComposable
fun com.android.systemui.common.shared.model.Color.toColor(): Color {
    return when (this) {
        is com.android.systemui.common.shared.model.Color.Attribute -> colorAttr(attribute)
        is com.android.systemui.common.shared.model.Color.Loaded -> Color(color)
    }
}
+31 −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.systemui.common.shared.model

import android.annotation.AttrRes
import android.annotation.ColorInt

/**
 * Models a color that can be either a specific [Color.Loaded] value or a resolvable theme
 * [Color.Attribute]
 */
sealed interface Color {

    data class Loaded(@ColorInt val color: Int) : Color

    data class Attribute(@AttrRes val attribute: Int) : Color
}