From a70ccbb0d0828a99512ae032afd46918379ab1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 24 Jan 2021 17:20:26 +0100 Subject: [PATCH] Make strings in grade class stats translatable (#1092) --- app/build.gradle | 2 +- .../statistics/GradeStatisticsAdapter.kt | 47 ++++++++++--------- .../statistics/GradeStatisticsPresenter.kt | 1 + app/src/main/res/values/strings.xml | 4 ++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6ccd6152..12ab69ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt index cbcb444a..0ffb4225 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt @@ -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) { @@ -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 } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt index 37f47869..47ea52d3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt @@ -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) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9d707d09..4364214c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -105,6 +105,10 @@ Partial Semester Points + Legend + Average: %1$s + Class + Student %d grade %d grades