mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[Grades] Add option to hide improved grades. Make counting average without weight configurable.
This commit is contained in:
parent
630361849c
commit
e282af0e80
@ -26,6 +26,16 @@ class ProfileConfigGrades(private val config: ProfileConfig) {
|
||||
get() { mCountZeroToAvg = mCountZeroToAvg ?: config.values.get("countZeroToAvg", true); return mCountZeroToAvg ?: true }
|
||||
set(value) { config.set("countZeroToAvg", value); mCountZeroToAvg = value }
|
||||
|
||||
private var mHideImproved: Boolean? = null
|
||||
var hideImproved: Boolean
|
||||
get() { mHideImproved = mHideImproved ?: config.values.get("hideImproved", true); return mHideImproved ?: true }
|
||||
set(value) { config.set("hideImproved", value); mHideImproved = value }
|
||||
|
||||
private var mAverageWithoutWeight: Boolean? = null
|
||||
var averageWithoutWeight: Boolean
|
||||
get() { mAverageWithoutWeight = mAverageWithoutWeight ?: config.values.get("averageWithoutWeight", true); return mAverageWithoutWeight ?: true }
|
||||
set(value) { config.set("averageWithoutWeight", value); mAverageWithoutWeight = value }
|
||||
|
||||
private var mPlusValue: Float? = null
|
||||
var plusValue: Float?
|
||||
get() { mPlusValue = mPlusValue ?: config.values.getFloat("plusValue"); return mPlusValue }
|
||||
|
@ -89,6 +89,8 @@ class GradesConfigDialog(
|
||||
}?.isChecked = true
|
||||
|
||||
b.dontCountZeroToAverage.isChecked = !profileConfig.countZeroToAvg
|
||||
b.hideImproved.isChecked = profileConfig.hideImproved
|
||||
b.averageWithoutWeight.isChecked = profileConfig.averageWithoutWeight
|
||||
}
|
||||
|
||||
private fun saveConfig() {
|
||||
@ -125,6 +127,16 @@ class GradesConfigDialog(
|
||||
b.gradeAverageMode2.setOnSelectedListener { profileConfig.yearAverageMode = YEAR_1_AVG_2_SEM }
|
||||
b.gradeAverageMode3.setOnSelectedListener { profileConfig.yearAverageMode = YEAR_1_SEM_2_SEM }
|
||||
|
||||
b.dontCountZeroToAverage.setOnCheckedChangeListener { _, isChecked -> profileConfig.countZeroToAvg = !isChecked }
|
||||
b.dontCountZeroToAverage.onChange { _, isChecked -> profileConfig.countZeroToAvg = !isChecked }
|
||||
b.hideImproved.onChange { _, isChecked -> profileConfig.hideImproved = isChecked }
|
||||
b.averageWithoutWeight.onChange { _, isChecked -> profileConfig.averageWithoutWeight = isChecked }
|
||||
|
||||
b.averageWithoutWeightHelp.onClick {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setTitle(R.string.grades_config_average_without_weight)
|
||||
.setMessage(R.string.grades_config_average_without_weight_message)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,8 @@ class GradesFragment : Fragment(), CoroutineScope {
|
||||
var subject = GradesSubject(subjectId, "")
|
||||
var semester = GradesSemester(0, 1)
|
||||
|
||||
val hideImproved = manager.hideImproved
|
||||
|
||||
// grades returned by the query are ordered
|
||||
// by the subject ID, so it's easier and probably
|
||||
// a bit faster to build all the models
|
||||
@ -152,7 +154,10 @@ class GradesFragment : Fragment(), CoroutineScope {
|
||||
Grade.TYPE_YEAR_PROPOSED -> subject.proposedGrade = grade
|
||||
Grade.TYPE_YEAR_FINAL -> subject.finalGrade = grade
|
||||
else -> {
|
||||
semester.grades += grade
|
||||
if (!hideImproved || grade.parentId ?: -1L == -1L) {
|
||||
// hide improved grades if parent(new grade) ID is not set
|
||||
semester.grades += grade
|
||||
}
|
||||
countGrade(grade, subject.averages)
|
||||
countGrade(grade, semester.averages)
|
||||
}
|
||||
@ -247,8 +252,13 @@ class GradesFragment : Fragment(), CoroutineScope {
|
||||
val weight = manager.getGradeWeight(dontCountGrades, grade)
|
||||
when (grade.type) {
|
||||
Grade.TYPE_NORMAL -> {
|
||||
averages.normalSum += value
|
||||
averages.normalCount ++
|
||||
if (grade.value > 0f) {
|
||||
// count to the arithmetic average
|
||||
// only if value more than 0
|
||||
// to exclude "+", "-", "np" etc.
|
||||
averages.normalSum += value
|
||||
averages.normalCount++
|
||||
}
|
||||
averages.normalWeightedSum += value * weight
|
||||
averages.normalWeightedCount += weight
|
||||
}
|
||||
|
@ -45,6 +45,10 @@ class GradesManager(val app: App) {
|
||||
get() = app.config.forProfile().grades.minusValue
|
||||
val dontCountGrades
|
||||
get() = app.config.forProfile().grades.dontCountGrades
|
||||
val hideImproved
|
||||
get() = app.config.forProfile().grades.hideImproved
|
||||
val averageWithoutWeight
|
||||
get() = app.config.forProfile().grades.averageWithoutWeight
|
||||
|
||||
|
||||
fun getOrderByString() = when (orderBy) {
|
||||
@ -142,7 +146,7 @@ class GradesManager(val app: App) {
|
||||
averages.normalWeightedCount > 0f -> {
|
||||
averages.normalWeightedSum / averages.normalWeightedCount
|
||||
}
|
||||
averages.normalSum > 0f && averages.normalCount > 0f -> {
|
||||
averageWithoutWeight && averages.normalSum > 0f && averages.normalCount > 0f -> {
|
||||
averages.normalSum / averages.normalCount
|
||||
}
|
||||
else -> null
|
||||
|
@ -4,7 +4,8 @@
|
||||
-->
|
||||
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
@ -13,12 +14,21 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/grades_config_title"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@ -28,7 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="0dp"
|
||||
android:text="Własna wartość plusa" />
|
||||
android:text="@string/grades_config_plus_value" />
|
||||
|
||||
<it.sephiroth.android.library.numberpicker.NumberPicker
|
||||
android:id="@+id/customPlusValue"
|
||||
@ -44,7 +54,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@ -54,7 +64,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="0dp"
|
||||
android:text="Własna wartość minusa" />
|
||||
android:text="@string/grades_config_minus_value" />
|
||||
|
||||
<it.sephiroth.android.library.numberpicker.NumberPicker
|
||||
android:id="@+id/customMinusValue"
|
||||
@ -67,9 +77,55 @@
|
||||
app:picker_orientation="horizontal" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:background="@drawable/divider"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dontCountZeroToAverage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="0dp"
|
||||
android:text="@string/settings_register_dont_count_zero_text"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/hideImproved"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="32dp"
|
||||
android:text="@string/grades_config_dont_show_improved"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/averageWithoutWeight"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="32dp"
|
||||
android:text="@string/grades_config_average_without_weight"/>
|
||||
|
||||
<com.mikepenz.iconics.view.IconicsImageView
|
||||
android:id="@+id/averageWithoutWeightHelp"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:scaleType="centerInside"
|
||||
app:iiv_color="?android:textColorSecondary"
|
||||
app:iiv_icon="cmd-help-circle-outline"
|
||||
app:iiv_size="16dp"
|
||||
tools:src="@android:drawable/ic_menu_help" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/menu_grades_sort_mode"/>
|
||||
@ -167,21 +223,6 @@
|
||||
android:minHeight="0dp"
|
||||
android:text="@string/settings_register_avg_mode_3"/>
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/other"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dontCountZeroToAverage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="0dp"
|
||||
android:text="@string/settings_register_dont_count_zero_text"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</layout>
|
||||
|
@ -1249,4 +1249,10 @@
|
||||
<string name="timetable_manual_type_by_subject">Wg. przedmiotu</string>
|
||||
<string name="timetable_manual_type_one_time">Jednorazowo</string>
|
||||
<string name="timetable_manual_type_repeating">Cyklicznie</string>
|
||||
<string name="grades_config_title">Konfiguracja ocen</string>
|
||||
<string name="grades_config_dont_show_improved">Ukrywaj oceny poprawione z listy</string>
|
||||
<string name="grades_config_average_without_weight">Licz średnią jeśli wszystkie wagi to 0</string>
|
||||
<string name="grades_config_average_without_weight_message">Pozwala na liczenie średniej arytmetycznej z przedmiotów, w których wszystkie wystawione oceny mają wagę 0 (nie są liczone do średniej).\n\nJeśli taki przedmiot celowo nie powinien być liczony, odznacz okienko przy tym ustawieniu.</string>
|
||||
<string name="grades_config_minus_value">Własna wartość minusa</string>
|
||||
<string name="grades_config_plus_value">Własna wartość plusa</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user