1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-19 00:26:45 -06:00

Follow current grade scheme in stats chart (#277)

This commit is contained in:
Mikołaj Pich 2019-03-12 17:34:04 +01:00 committed by Rafał Borcz
parent 2621e5680d
commit 35f1fe8d61
7 changed files with 38 additions and 17 deletions

View File

@ -40,7 +40,18 @@ class GradeStatisticsFragment : BaseSessionFragment(), GradeStatisticsView, Grad
override val isViewEmpty
get() = gradeStatisticsChart.isEmpty
private val gradeColors = listOf(
private lateinit var gradeColors: List<Pair<Int, Int>>
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<GradeStatistics>) {
override fun updateData(items: List<GradeStatistics>, 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()
}
}

View File

@ -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<GradeStatisticsView>(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)
}) {

View File

@ -11,7 +11,7 @@ interface GradeStatisticsView : BaseSessionView {
fun updateSubjects(data: ArrayList<String>)
fun updateData(items: List<GradeStatistics>)
fun updateData(items: List<GradeStatistics>, theme: String)
fun showSubjects(show: Boolean)

View File

@ -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
}
}
}

View File

@ -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"

View File

@ -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"

View File

@ -5,7 +5,6 @@
<color name="colorPrimaryLight">#ff6659</color>
<color name="colorBackgroundBottomNav">#f0f0f0</color>
<color name="grade_default">#607d8b</color>
<color name="grade_text">#ffffff</color>
<color name="grade_black">#424242</color>
@ -20,6 +19,7 @@
<color name="grade_material_three">#ffa000</color>
<color name="grade_material_two">#ff5722</color>
<color name="grade_material_one">#d32f2f</color>
<color name="grade_material_default">#607d8b</color>
<color name="grade_vulcan_six">#91b43c</color>
<color name="grade_vulcan_five">#2cbd92</color>
@ -27,6 +27,7 @@
<color name="grade_vulcan_three">#d2ab24</color>
<color name="grade_vulcan_two">#9071b3</color>
<color name="grade_vulcan_one">#d65757</color>
<color name="grade_vulcan_default">#3d5f9c</color>
<color name="bottom_nav_background">#303030</color>
<color name="bottom_nav_background_inverse">#ffffff</color>