Make strings in grade class stats translatable (#1092)

This commit is contained in:
Mikołaj Pich 2021-01-24 17:20:26 +01:00 committed by GitHub
parent 2b6386c522
commit a70ccbb0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 22 deletions

View File

@ -138,7 +138,7 @@ ext {
}
dependencies {
implementation "io.github.wulkanowy:sdk:0.24.1"
implementation "io.github.wulkanowy:sdk:a722e777"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'

View File

@ -78,18 +78,18 @@ class GradeStatisticsAdapter @Inject constructor() :
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is PartialViewHolder -> bindPartialChart(holder, items[position].partial!!)
is SemesterViewHolder -> bindSemesterChart(holder, items[position].semester!!)
is PointsViewHolder -> bindBarChart(holder, items[position].points!!)
is PartialViewHolder -> bindPartialChart(holder.binding, items[position].partial!!)
is SemesterViewHolder -> bindSemesterChart(holder.binding, items[position].semester!!)
is PointsViewHolder -> bindBarChart(holder.binding, items[position].points!!)
}
}
private fun bindPartialChart(holder: PartialViewHolder, partials: GradePartialStatistics) {
bindPieChart(holder.binding, partials.subject, partials.classAverage, partials.classAmounts)
private fun bindPartialChart(binding: ItemGradeStatisticsPieBinding, partials: GradePartialStatistics) {
bindPieChart(binding, partials.subject, partials.classAverage, partials.classAmounts)
}
private fun bindSemesterChart(holder: SemesterViewHolder, semester: GradeSemesterStatistics) {
bindPieChart(holder.binding, semester.subject, semester.average, semester.amounts)
private fun bindSemesterChart(binding: ItemGradeStatisticsPieBinding, semester: GradeSemesterStatistics) {
bindPieChart(binding, semester.subject, semester.average, semester.amounts)
}
private fun bindPieChart(binding: ItemGradeStatisticsPieBinding, subject: String, average: String, amounts: List<Int>) {
@ -103,9 +103,12 @@ class GradeStatisticsAdapter @Inject constructor() :
else -> materialGradeColors
}
val dataset = PieDataSet(amounts.mapIndexed { grade, amount ->
PieEntry(amount.toFloat(), (grade + 1).toString())
}.reversed().filterNot { it.value == 0f }, "Legenda")
val dataset = PieDataSet(
amounts.mapIndexed { grade, amount ->
PieEntry(amount.toFloat(), (grade + 1).toString())
}.reversed().filterNot { it.value == 0f },
binding.root.context.getString(R.string.grade_statistics_legend)
)
with(dataset) {
valueTextSize = 12f
@ -138,11 +141,13 @@ class GradeStatisticsAdapter @Inject constructor() :
})
}
val numberOfGradesString = amounts.fold(0) { acc, it -> acc + it }
.let { resources.getQuantityString(R.plurals.grade_number_item, it, it) }
val averageString = binding.root.context.getString(R.string.grade_statistics_average, average)
minAngleForSlices = 25f
description.isEnabled = false
centerText = amounts.fold(0) { acc, it -> acc + it }
.let { resources.getQuantityString(R.plurals.grade_number_item, it, it) } +
("\n\nŚrednia: $average").takeIf { average.isNotBlank() }.orEmpty()
centerText = numberOfGradesString + ("\n\n" + averageString).takeIf { average.isNotBlank() }.orEmpty()
setHoleColor(context.getThemeAttrColor(android.R.attr.windowBackground))
setCenterTextColor(context.getThemeAttrColor(android.R.attr.textColorPrimary))
@ -150,8 +155,8 @@ class GradeStatisticsAdapter @Inject constructor() :
}
}
private fun bindBarChart(holder: PointsViewHolder, points: GradePointsStatistics) {
with(holder.binding.gradeStatisticsBarTitle) {
private fun bindBarChart(binding: ItemGradeStatisticsBarBinding, points: GradePointsStatistics) {
with(binding.gradeStatisticsBarTitle) {
text = points.subject
visibility = if (items.size == 1) GONE else VISIBLE
}
@ -159,18 +164,18 @@ class GradeStatisticsAdapter @Inject constructor() :
val dataset = BarDataSet(listOf(
BarEntry(1f, points.others.toFloat()),
BarEntry(2f, points.student.toFloat())
), "Legenda")
), binding.root.context.getString(R.string.grade_statistics_legend))
with(dataset) {
valueTextSize = 12f
valueTextColor = holder.binding.root.context.getThemeAttrColor(android.R.attr.textColorPrimary)
valueTextColor = binding.root.context.getThemeAttrColor(android.R.attr.textColorPrimary)
valueFormatter = object : ValueFormatter() {
override fun getBarLabel(barEntry: BarEntry) = "${barEntry.y}%"
}
colors = gradePointsColors
}
with(holder.binding.gradeStatisticsBar) {
with(binding.gradeStatisticsBar) {
setTouchEnabled(false)
if (items.size == 1) animateXY(1000, 1000)
data = BarData(dataset).apply {
@ -179,12 +184,12 @@ class GradeStatisticsAdapter @Inject constructor() :
}
legend.setCustom(listOf(
LegendEntry().apply {
label = "Średnia klasy"
label = binding.root.context.getString(R.string.grade_statistics_average_class)
formColor = gradePointsColors[0]
form = Legend.LegendForm.SQUARE
},
LegendEntry().apply {
label = "Uczeń"
label = binding.root.context.getString(R.string.grade_statistics_average_student)
formColor = gradePointsColors[1]
form = Legend.LegendForm.SQUARE
}
@ -193,7 +198,7 @@ class GradeStatisticsAdapter @Inject constructor() :
description.isEnabled = false
holder.binding.root.context.getThemeAttrColor(android.R.attr.textColorPrimary).let {
binding.root.context.getThemeAttrColor(android.R.attr.textColorPrimary).let {
axisLeft.textColor = it
axisRight.textColor = it
}

View File

@ -172,6 +172,7 @@ class GradeStatisticsPresenter @Inject constructor(
showErrorView(false)
enableSwipe(true)
showRefresh(true)
showProgress(false)
updateData(it.data!!, preferencesRepository.gradeColorTheme, preferencesRepository.showAllSubjectsOnStatisticsList)
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
}

View File

@ -105,6 +105,10 @@
<string name="grade_statistics_partial">Partial</string>
<string name="grade_statistics_semester">Semester</string>
<string name="grade_statistics_points">Points</string>
<string name="grade_statistics_legend">Legend</string>
<string name="grade_statistics_average">Average: %1$s</string>
<string name="grade_statistics_average_class">Class</string>
<string name="grade_statistics_average_student">Student</string>
<plurals name="grade_number_item">
<item quantity="one">%d grade</item>
<item quantity="other">%d grades</item>