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

Commit 4124f2f5 authored by Kelly's avatar Kelly
Browse files

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.

Test: Manually test on deivce
Bug: 253536111
Change-Id: I81f4b8b3f3f799bc472ec19d196f56c8b1f756e0
parent a44cf882
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.
 */