forked from github/wulkanowy-mirror
Add captions for averages from how many items have been counted (#1437)
This commit is contained in:
parent
02b87c8c6a
commit
1cfabe43a5
@ -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
|
||||
|
||||
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(items.calcAverage(preferencesRepository.gradePlusModifier, preferencesRepository.gradeMinusModifier))
|
||||
gradeSummaryScrollableHeaderCalculated.text = formatAverage(items
|
||||
.filter { value -> value.average != 0.0 }
|
||||
.map { values -> values.average }
|
||||
.reversed() // fix average precision
|
||||
.average()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:minLines="2"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/grade_summary_calculated_average"
|
||||
android:textSize="16sp" />
|
||||
|
||||
@ -30,6 +31,15 @@
|
||||
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
|
||||
@ -43,6 +53,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:minLines="2"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/grade_summary_final_average"
|
||||
android:textSize="16sp" />
|
||||
|
||||
@ -53,5 +64,14 @@
|
||||
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>
|
||||
|
@ -101,6 +101,7 @@
|
||||
<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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user