Fix flicker of "App data usage"

Use placeholder to hold the place.

Fix: 323466366
Test: manual - on Mobile Settings
Test: unit test
Change-Id: I3c4d9ff6538a79500318869f01f4b88b55bd9475
This commit is contained in:
Chaohui Wang
2024-03-07 15:20:01 +08:00
parent c038d58bef
commit 74fe516e09
2 changed files with 4 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ import com.android.settings.datausage.DataUsageUtils
import com.android.settings.datausage.lib.DataUsageLib
import com.android.settings.datausage.lib.NetworkCycleDataRepository
import com.android.settings.datausage.lib.NetworkStatsRepository.Companion.AllTimeRange
import com.android.settingslib.spaprivileged.framework.compose.getPlaceholder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -63,6 +64,7 @@ class DataUsagePreferenceController(context: Context, key: String) :
}
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
preference.summary = mContext.getPlaceholder()
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
update()
@@ -113,7 +115,6 @@ class DataUsagePreferenceController(context: Context, key: String) :
}
val allTimeUsage = repository.queryUsage(AllTimeRange)
if (allTimeUsage.usage > 0) return allTimeUsage.getDataUsedString(mContext) to true
return null to false
return allTimeUsage.getDataUsedString(mContext) to (allTimeUsage.usage > 0)
}
}

View File

@@ -120,7 +120,7 @@ class DataUsagePreferenceControllerTest {
on { loadFirstCycle() } doReturn usageData
}
controller.onViewCreated(TestLifecycleOwner())
waitUntil { preference.summary != null }
waitUntil { !preference.summary.isNullOrBlank() }
controller.handlePreferenceTreeClick(preference)