Use DataUsageFormatter to format app data usage
Use the new unitsContentDescription from Formatter.formatBytes() Fix: 318780411 Test: manual - on AppDataUsage Test: unit test Change-Id: I55079c83db2e46a48f49f746f2371825ec0bb029
This commit is contained in:
@@ -23,11 +23,12 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.android.settings.R
|
||||
import com.android.settings.datausage.lib.DataUsageFormatter
|
||||
import com.android.settings.datausage.lib.NetworkUsageDetailsData
|
||||
import com.android.settings.spa.preference.ComposePreferenceController
|
||||
import com.android.settingslib.spa.widget.preference.Preference
|
||||
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
||||
import com.android.settingslib.spaprivileged.framework.compose.placeholder
|
||||
import com.android.settingslib.spaprivileged.framework.compose.getPlaceholder
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@@ -35,17 +36,20 @@ class AppDataUsageSummaryController(context: Context, preferenceKey: String) :
|
||||
ComposePreferenceController(context, preferenceKey) {
|
||||
|
||||
private val dataFlow = MutableStateFlow(NetworkUsageDetailsData.AllZero)
|
||||
private val dataUsageFormatter = DataUsageFormatter(context)
|
||||
private val emptyDataUsage =
|
||||
DataUsageFormatter.FormattedDataUsage(context.getPlaceholder(), context.getPlaceholder())
|
||||
|
||||
private val totalUsageFlow = dataFlow.map {
|
||||
DataUsageUtils.formatDataUsage(mContext, it.totalUsage).toString()
|
||||
dataUsageFormatter.formatDataUsage(it.totalUsage)
|
||||
}
|
||||
|
||||
private val foregroundUsageFlow = dataFlow.map {
|
||||
DataUsageUtils.formatDataUsage(mContext, it.foregroundUsage).toString()
|
||||
dataUsageFormatter.formatDataUsage(it.foregroundUsage)
|
||||
}
|
||||
|
||||
private val backgroundUsageFlow = dataFlow.map {
|
||||
DataUsageUtils.formatDataUsage(mContext, it.backgroundUsage).toString()
|
||||
dataUsageFormatter.formatDataUsage(it.backgroundUsage)
|
||||
}
|
||||
|
||||
override fun getAvailabilityStatus() = AVAILABLE
|
||||
@@ -57,20 +61,23 @@ class AppDataUsageSummaryController(context: Context, preferenceKey: String) :
|
||||
@Composable
|
||||
override fun Content() {
|
||||
Column {
|
||||
val totalUsage by totalUsageFlow.collectAsStateWithLifecycle(placeholder())
|
||||
val foregroundUsage by foregroundUsageFlow.collectAsStateWithLifecycle(placeholder())
|
||||
val backgroundUsage by backgroundUsageFlow.collectAsStateWithLifecycle(placeholder())
|
||||
val totalUsage by totalUsageFlow.collectAsStateWithLifecycle(emptyDataUsage)
|
||||
val foregroundUsage by foregroundUsageFlow.collectAsStateWithLifecycle(emptyDataUsage)
|
||||
val backgroundUsage by backgroundUsageFlow.collectAsStateWithLifecycle(emptyDataUsage)
|
||||
Preference(object : PreferenceModel {
|
||||
override val title = stringResource(R.string.total_size_label)
|
||||
override val summary = { totalUsage }
|
||||
override val summary = { totalUsage.displayText }
|
||||
override val summaryContentDescription = { totalUsage.contentDescription }
|
||||
})
|
||||
Preference(object : PreferenceModel {
|
||||
override val title = stringResource(R.string.data_usage_label_foreground)
|
||||
override val summary = { foregroundUsage }
|
||||
override val summary = { foregroundUsage.displayText }
|
||||
override val summaryContentDescription = { foregroundUsage.contentDescription }
|
||||
})
|
||||
Preference(object : PreferenceModel {
|
||||
override val title = stringResource(R.string.data_usage_label_background)
|
||||
override val summary = { backgroundUsage }
|
||||
override val summary = { backgroundUsage.displayText }
|
||||
override val summaryContentDescription = { backgroundUsage.contentDescription }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user