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

Commit 04df6535 authored by Kelly Zhang's avatar Kelly Zhang Committed by Android (Google) Code Review
Browse files

Merge "Introduce an EntryData interface to manage entry, page and highlight...

Merge "Introduce an EntryData interface to manage entry, page and highlight info. Based on CompositionLocal version of EntryData, we pass the info to UI implementations for pages."
parents 81f938b3 4124f2f5
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.settingslib.spa.framework.common
import android.os.Bundle
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidedValue
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
@@ -28,6 +31,16 @@ import com.android.settingslib.spa.framework.compose.LocalNavController
const val INJECT_ENTRY_NAME = "INJECT"
const val ROOT_ENTRY_NAME = "ROOT"

interface EntryData {
    val pageId: String
    val entryId: String
    val isHighlighted: Boolean
        get() = false
}

val LocalEntryDataProvider =
    compositionLocalOf<EntryData> { error("LocalEntryDataProvider: No Default Value!") }

/**
 * Defines data of a Settings entry.
 */
@@ -121,10 +134,25 @@ data class SettingsEntry(
            // TODO: Add highlight entry logic
            Toast.makeText(context, "entry $id highlighted", Toast.LENGTH_SHORT).show()
        }

        CompositionLocalProvider(provideLocalEntryData()) {
            uiLayoutImpl(fullArgument(runtimeArguments))
        }
    }

    @Composable
    fun provideLocalEntryData(): ProvidedValue<EntryData> {
        val controller = LocalNavController.current
        return LocalEntryDataProvider provides remember {
            object : EntryData {
                override val pageId = containerPage().id
                override val entryId = id
                override val isHighlighted = controller.highlightEntryId == id
            }
        }
    }
}

/**
 * The helper to build a Settings Entry instance.
 */