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

Commit 3818328c authored by Chaohui Wang's avatar Chaohui Wang
Browse files

[Spa] Clean up LiveData

This change removes the usage of and dependency on `LiveData` from the
SPA library.

Here's a breakdown of the changes:

*   **`LiveDataExt.kt` deleted:** This file contained a single
    Composable extension function, `observeAsCallback`, which wrapped
    `LiveData.observeAsState` to provide the `LiveData`'s value as a
    lambda. This utility is no longer needed.
*   **`build.gradle.kts` and `Android.bp` updated:** With the removal of
    the `LiveData` utility, the dependencies on
    `androidx.compose.runtime:runtime-livedata` and
    `androidx.lifecycle:lifecycle-livedata-ktx` are no longer required.
    They have been removed from both the Gradle and Soong build files to
    clean up the project's dependencies.

In essence, this is a refactoring that simplifies the library by
removing an unused feature and its associated dependencies, likely
favoring other reactive data holders like `StateFlow` for Jetpack
Compose integration.

Fix: 321163306
Flag: EXEMPT clean up
Test: m SpaLib
Change-Id: I4c1c892bb01c116284b589c1faf9959b7bfcf0b2
parent d68d2f86
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@ android_library {
        "androidx.compose.material3_material3",
        "androidx.compose.material_material-icons-extended",
        "androidx.compose.runtime_runtime",
        "androidx.compose.runtime_runtime-livedata",
        "androidx.compose.ui_ui-tooling-preview",
        "androidx.lifecycle_lifecycle-livedata-ktx",
        "androidx.lifecycle_lifecycle-runtime-compose",
        "androidx.navigation_navigation-compose",
        "androidx.window_window",
+0 −2
Original line number Diff line number Diff line
@@ -57,10 +57,8 @@ dependencies {
    api("androidx.appcompat:appcompat:1.7.0")
    api("androidx.compose.material3:material3:1.4.0-alpha15")
    api("androidx.compose.material:material-icons-extended:1.7.8")
    api("androidx.compose.runtime:runtime-livedata:$jetpackComposeVersion")
    api("androidx.compose.ui:ui-tooling-preview:$jetpackComposeVersion")
    api("androidx.graphics:graphics-shapes-android:1.0.1")
    api("androidx.lifecycle:lifecycle-livedata-ktx")
    api("androidx.lifecycle:lifecycle-runtime-compose")
    api("androidx.navigation:navigation-compose:2.9.0")
    api("androidx.window:window:1.5.0-alpha02")
+0 −34
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.spa.livedata

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.lifecycle.LiveData

/**
 * Starts observing this LiveData and represents its values via State and Callback.
 *
 * Every time there would be new value posted into the LiveData the returned State will be updated
 * causing recomposition of every Callback usage.
 */
@Composable
fun <T> LiveData<T>.observeAsCallback(): () -> T? {
    val isAllowed by observeAsState()
    return { isAllowed }
}