Add captions for averages from how many items have been counted
MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryAdapter.kt
app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryAdapter.kt
@@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
+import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.GradeSummary
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.databinding.ItemGradeSummaryBinding
@@ -35,8 +36,12 @@ class GradeSummaryAdapter @Inject constructor(
val inflater = LayoutInflater.from(parent.context)
return when (viewType) {
- ViewType.HEADER.id -> HeaderViewHolder(ScrollableHeaderGradeSummaryBinding.inflate(inflater, parent, false))
- ViewType.ITEM.id -> ItemViewHolder(ItemGradeSummaryBinding.inflate(inflater, parent, false))
+ ViewType.HEADER.id -> HeaderViewHolder(
+ ScrollableHeaderGradeSummaryBinding.inflate(inflater, parent, false)
+ )
+ ViewType.ITEM.id -> ItemViewHolder(
+ ItemGradeSummaryBinding.inflate(inflater, parent, false)
+ )
else -> throw IllegalStateException()
}
}
@@ -51,13 +56,27 @@ class GradeSummaryAdapter @Inject constructor(
private fun bindHeaderViewHolder(binding: ScrollableHeaderGradeSummaryBinding) {
if (items.isEmpty()) return
- with(binding) {
- gradeSummaryScrollableHeaderFinal.text = formatAverage(items.calcAverage(preferencesRepository.gradePlusModifier, preferencesRepository.gradeMinusModifier))
- gradeSummaryScrollableHeaderCalculated.text = formatAverage(items
- .filter { value -> value.average != 0.0 }
+ val context = binding.root.context
+ val finalItemsCount = items.count { it.finalGrade.matches("[0-6][+-]?".toRegex()) }
+ val calculatedItemsCount = items.count { value -> value.average != 0.0 }
+ val finalAverage = items.calcAverage(
+ preferencesRepository.gradePlusModifier,
+ preferencesRepository.gradeMinusModifier
+ )
+ val calculatedAverage = items.filter { value -> value.average != 0.0 }
.map { values -> values.average }
.reversed() // fix average precision
.average()
+
+ with(binding) {
+ gradeSummaryScrollableHeaderFinal.text = formatAverage(finalAverage)
+ gradeSummaryScrollableHeaderCalculated.text = formatAverage(calculatedAverage)
+ gradeSummaryScrollableHeaderFinalSubjectCount.text =
+ context.getString(R.string.grade_summary_from_subjects, finalItemsCount, items.size)
+ gradeSummaryScrollableHeaderCalculatedSubjectCount.text = context.getString(
+ R.string.grade_summary_from_subjects,
+ calculatedItemsCount,
+ items.size
)
}
}
@@ -71,7 +90,8 @@ class GradeSummaryAdapter @Inject constructor(
gradeSummaryItemPredicted.text = "${item.predictedGrade} ${item.proposedPoints}".trim()
gradeSummaryItemFinal.text = "${item.finalGrade} ${item.finalPoints}".trim()
- gradeSummaryItemPointsContainer.visibility = if (item.pointsSum.isBlank()) View.GONE else View.VISIBLE
+ gradeSummaryItemPointsContainer.visibility =
+ if (item.pointsSum.isBlank()) View.GONE else View.VISIBLE
}
}

MODIFY
app/src/main/res/layout/scrollable_header_grade_summary.xml
app/src/main/res/layout/scrollable_header_grade_summary.xml
android:layout_height="wrap_content"
android:gravity="center"
android:minLines="2"
+ android:textStyle="bold"
android:text="@string/grade_summary_calculated_average"
android:textSize="16sp" />
android:gravity="center_horizontal"
android:textSize="21sp"
tools:text="6,00" />
+
+ <TextView
+ android:id="@+id/gradeSummaryScrollableHeaderCalculatedSubjectCount"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dp"
+ android:gravity="center_horizontal"
+ android:textSize="13sp"
+ tools:text="from 8 subjects" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:gravity="center"
android:minLines="2"
+ android:textStyle="bold"
android:text="@string/grade_summary_final_average"
android:textSize="16sp" />
android:gravity="center_horizontal"
android:textSize="21sp"
tools:text="6,00" />
+
+ <TextView
+ android:id="@+id/gradeSummaryScrollableHeaderFinalSubjectCount"
+ android:layout_width="match_parent"
+ android:layout_marginTop="5dp"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
+ android:textSize="13sp"
+ tools:text="from 5 subjects" />
</LinearLayout>
</LinearLayout>

MODIFY
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
<string name="grade_summary_predicted_grade">Predicted grade</string>
<string name="grade_summary_calculated_average">Calculated average</string>
<string name="grade_summary_final_average">Final average</string>
+ <string name="grade_summary_from_subjects">From %d of %d subjects</string>
<string name="grade_menu_summary">Summary</string>
<string name="grade_menu_statistics">Class</string>
<string name="grade_menu_read">Mark as read</string>

Add captions for averages from how many items have been counted (#1437)