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

Commit 1d0ac9c3 authored by Zekan Qian's avatar Zekan Qian Committed by Android (Google) Code Review
Browse files

Merge "Disable the async preference when it is loading"

parents a0951b0c b5717541
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -127,11 +127,11 @@ object PreferencePageProvider : SettingsPageProvider {
                .setStatusDataFn { EntryStatusData(isDisabled = false) }
                .setUiLayoutFn {
                    val model = PreferencePageModel.create()
                    val asyncSummary = remember { model.getAsyncSummary() }
                    Preference(
                        object : PreferenceModel {
                            override val title = ASYNC_PREFERENCE_TITLE
                            override val summary = asyncSummary
                            override val summary = model.asyncSummary
                            override val enabled = model.asyncEnable
                        }
                    )
                }.build()
+4 −6
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ class PreferencePageModel : PageModel() {

    private val spaLogger = SpaEnvironmentFactory.instance.logger

    private val asyncSummary = mutableStateOf(" ")
    val asyncSummary = mutableStateOf("(loading)")
    val asyncEnable = mutableStateOf(false)

    private val manualUpdater = mutableStateOf(0)

@@ -87,16 +88,13 @@ class PreferencePageModel : PageModel() {
    override fun initialize(arguments: Bundle?) {
        spaLogger.message(TAG, "initialize with args " + arguments.toString())
        viewModelScope.launch(Dispatchers.IO) {
            // Loading your data here.
            delay(2000L)
            asyncSummary.value = ASYNC_PREFERENCE_SUMMARY
            asyncEnable.value = true
        }
    }

    fun getAsyncSummary(): State<String> {
        spaLogger.message(TAG, "getAsyncSummary")
        return asyncSummary
    }

    fun getManualUpdaterSummary(): State<String> {
        spaLogger.message(TAG, "getManualUpdaterSummary")
        return derivedStateOf { manualUpdater.value.toString() }