Disable the async preference when it is loading

Bug: 244122804
Test: manual - build gallery
Change-Id: I1918f3e172b039ae3688a43c148ae53706e186a8
This commit is contained in:
Zekan Qian
2022-10-28 10:38:50 +08:00
parent 9d93ab7ada
commit b57175416e
2 changed files with 6 additions and 8 deletions

View File

@@ -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()

View File

@@ -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() }