From 35f1fe8d61ed22e9a253ee3e41cb2dfedbeb4ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Tue, 12 Mar 2019 17:34:04 +0100 Subject: [PATCH] Follow current grade scheme in stats chart (#277) --- .../statistics/GradeStatisticsFragment.kt | 36 ++++++++++++++----- .../statistics/GradeStatisticsPresenter.kt | 4 ++- .../grade/statistics/GradeStatisticsView.kt | 2 +- .../github/wulkanowy/utils/GradeExtension.kt | 6 ++-- app/src/main/res/layout/dialog_grade.xml | 2 +- .../main/res/layout/item_grade_details.xml | 2 +- app/src/main/res/values/colors.xml | 3 +- 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt index 6e5bc8fae..f27a13c83 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt @@ -40,7 +40,18 @@ class GradeStatisticsFragment : BaseSessionFragment(), GradeStatisticsView, Grad override val isViewEmpty get() = gradeStatisticsChart.isEmpty - private val gradeColors = listOf( + private lateinit var gradeColors: List> + + private val vulcanGradeColors = listOf( + 6 to R.color.grade_vulcan_six, + 5 to R.color.grade_vulcan_five, + 4 to R.color.grade_vulcan_four, + 3 to R.color.grade_vulcan_three, + 2 to R.color.grade_vulcan_two, + 1 to R.color.grade_vulcan_one + ) + + private val materialGradeColors = listOf( 6 to R.color.grade_material_six, 5 to R.color.grade_material_five, 4 to R.color.grade_material_four, @@ -72,13 +83,6 @@ class GradeStatisticsFragment : BaseSessionFragment(), GradeStatisticsView, Grad minAngleForSlices = 25f legend.apply { textColor = context.getThemeAttrColor(android.R.attr.textColorPrimary) - setCustom(gradeLabels.mapIndexed { i, it -> - LegendEntry().apply { - label = it - formColor = ContextCompat.getColor(context, gradeColors[i].second) - form = Legend.LegendForm.SQUARE - } - }) } } @@ -103,7 +107,12 @@ class GradeStatisticsFragment : BaseSessionFragment(), GradeStatisticsView, Grad } } - override fun updateData(items: List) { + override fun updateData(items: List, theme: String) { + gradeColors = when (theme) { + "vulcan" -> vulcanGradeColors + else -> materialGradeColors + } + gradeStatisticsChart.run { data = PieData(PieDataSet(items.map { PieEntry(it.amount.toFloat(), it.grade.toString()) @@ -124,6 +133,15 @@ class GradeStatisticsFragment : BaseSessionFragment(), GradeStatisticsView, Grad centerText = items.fold(0) { acc, it -> acc + it.amount } .let { resources.getQuantityString(R.plurals.grade_number_item, it, it) } } + legend.apply { + setCustom(gradeLabels.mapIndexed { i, it -> + LegendEntry().apply { + label = it + formColor = ContextCompat.getColor(context, gradeColors[i].second) + form = Legend.LegendForm.SQUARE + } + }) + } invalidate() } } 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 1e4e494c2..5111420d2 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 @@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.modules.grade.statistics import io.github.wulkanowy.data.db.entities.Subject import io.github.wulkanowy.data.repositories.gradestatistics.GradeStatisticsRepository +import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.subject.SubjectRepository @@ -18,6 +19,7 @@ class GradeStatisticsPresenter @Inject constructor( private val subjectRepository: SubjectRepository, private val studentRepository: StudentRepository, private val semesterRepository: SemesterRepository, + private val preferencesRepository: PreferencesRepository, private val schedulers: SchedulersProvider, private val analytics: FirebaseAnalyticsHelper ) : BaseSessionPresenter(errorHandler) { @@ -133,7 +135,7 @@ class GradeStatisticsPresenter @Inject constructor( view?.run { showEmpty(it.isEmpty()) showContent(it.isNotEmpty()) - updateData(it) + updateData(it, preferencesRepository.gradeColorTheme) } analytics.logEvent("load_grade_statistics", "items" to it.size, "force_refresh" to forceRefresh) }) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsView.kt index e0649fc4c..dbdde459e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsView.kt @@ -11,7 +11,7 @@ interface GradeStatisticsView : BaseSessionView { fun updateSubjects(data: ArrayList) - fun updateData(items: List) + fun updateData(items: List, theme: String) fun showSubjects(show: Boolean) diff --git a/app/src/main/java/io/github/wulkanowy/utils/GradeExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/GradeExtension.kt index 092e95203..c863b030f 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/GradeExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/GradeExtension.kt @@ -30,7 +30,7 @@ fun Grade.getBackgroundColor(theme: String): Int { "20A4F7" -> R.color.grade_blue "6ECD07" -> R.color.grade_green "B16CF1" -> R.color.grade_purple - else -> R.color.grade_default + else -> R.color.grade_material_default } "material" -> when (value) { 6 -> R.color.grade_material_six @@ -39,7 +39,7 @@ fun Grade.getBackgroundColor(theme: String): Int { 3 -> R.color.grade_material_three 2 -> R.color.grade_material_two 1 -> R.color.grade_material_one - else -> R.color.grade_default + else -> R.color.grade_material_default } else -> when (value) { 6 -> R.color.grade_vulcan_six @@ -48,7 +48,7 @@ fun Grade.getBackgroundColor(theme: String): Int { 3 -> R.color.grade_vulcan_three 2 -> R.color.grade_vulcan_two 1 -> R.color.grade_vulcan_one - else -> R.color.grade_default + else -> R.color.grade_vulcan_default } } } diff --git a/app/src/main/res/layout/dialog_grade.xml b/app/src/main/res/layout/dialog_grade.xml index 18e3a4787..7a670878d 100644 --- a/app/src/main/res/layout/dialog_grade.xml +++ b/app/src/main/res/layout/dialog_grade.xml @@ -25,7 +25,7 @@ android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_gravity="end" - android:background="@color/grade_default" + android:background="@color/grade_material_default" android:gravity="center" android:textColor="@color/grade_text" android:textSize="30sp" diff --git a/app/src/main/res/layout/item_grade_details.xml b/app/src/main/res/layout/item_grade_details.xml index 3230a68ca..36632d04f 100644 --- a/app/src/main/res/layout/item_grade_details.xml +++ b/app/src/main/res/layout/item_grade_details.xml @@ -18,7 +18,7 @@ android:layout_width="45dp" android:layout_height="40dp" android:layout_centerVertical="true" - android:background="@color/grade_default" + android:background="@color/grade_material_default" android:gravity="center" android:maxLength="5" android:textColor="@color/grade_text" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6de571d96..30909ebab 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -5,7 +5,6 @@ #ff6659 #f0f0f0 - #607d8b #ffffff #424242 @@ -20,6 +19,7 @@ #ffa000 #ff5722 #d32f2f + #607d8b #91b43c #2cbd92 @@ -27,6 +27,7 @@ #d2ab24 #9071b3 #d65757 + #3d5f9c #303030 #ffffff