Add total attendance summary (#672)

This commit is contained in:
Dominik Korsa 2020-02-02 16:40:00 +01:00 committed by GitHub
parent 731afbb00c
commit c3a6842027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 1 deletions

View File

@ -36,6 +36,8 @@ class AttendanceSummaryFragment : BaseFragment(), AttendanceSummaryView, MainVie
fun newInstance() = AttendanceSummaryFragment() fun newInstance() = AttendanceSummaryFragment()
} }
override val totalString get() = getString(R.string.attendance_summary_total)
override val titleStringId get() = R.string.attendance_title override val titleStringId get() = R.string.attendance_title
override val isViewEmpty get() = attendanceSummaryAdapter.isEmpty override val isViewEmpty get() = attendanceSummaryAdapter.isEmpty

View File

@ -144,8 +144,22 @@ class AttendanceSummaryPresenter @Inject constructor(
) )
} }
private fun createAttendanceSummaryTotalItem(attendanceSummary: List<AttendanceSummary>): AttendanceSummaryItem {
return AttendanceSummaryItem(
month = view?.totalString.orEmpty(),
percentage = formatPercentage(attendanceSummary.calculatePercentage()),
present = attendanceSummary.sumBy { it.presence }.toString(),
absence = attendanceSummary.sumBy { it.absence }.toString(),
excusedAbsence = attendanceSummary.sumBy { it.absenceExcused }.toString(),
schoolAbsence = attendanceSummary.sumBy { it.absenceForSchoolReasons }.toString(),
exemption = attendanceSummary.sumBy { it.exemption }.toString(),
lateness = attendanceSummary.sumBy { it.lateness }.toString(),
excusedLateness = attendanceSummary.sumBy { it.latenessExcused }.toString()
)
}
private fun createAttendanceSummaryItems(attendanceSummary: List<AttendanceSummary>): List<AttendanceSummaryItem> { private fun createAttendanceSummaryItems(attendanceSummary: List<AttendanceSummary>): List<AttendanceSummaryItem> {
return attendanceSummary.sortedByDescending { it.id }.map { return listOf(createAttendanceSummaryTotalItem(attendanceSummary)) + attendanceSummary.sortedByDescending { it.id }.map {
AttendanceSummaryItem( AttendanceSummaryItem(
month = it.month.getFormattedName(), month = it.month.getFormattedName(),
percentage = formatPercentage(it.calculatePercentage()), percentage = formatPercentage(it.calculatePercentage()),

View File

@ -4,6 +4,8 @@ import io.github.wulkanowy.ui.base.BaseView
interface AttendanceSummaryView : BaseView { interface AttendanceSummaryView : BaseView {
val totalString: String
val isViewEmpty: Boolean val isViewEmpty: Boolean
fun initView() fun initView()

View File

@ -151,6 +151,7 @@
<!--Attendance summary--> <!--Attendance summary-->
<string name="attendance_summary_final">Frekwencja</string> <string name="attendance_summary_final">Frekwencja</string>
<string name="attendance_summary_total">Razem</string>
<!--Exam--> <!--Exam-->

View File

@ -146,6 +146,7 @@
<!--Attendance summary--> <!--Attendance summary-->
<string name="attendance_summary_final">Посещаемость</string> <string name="attendance_summary_final">Посещаемость</string>
<string name="attendance_summary_total">вместе</string>
<!--Exam--> <!--Exam-->

View File

@ -145,6 +145,7 @@
<!--Attendance summary--> <!--Attendance summary-->
<string name="attendance_summary_final">Attendance</string> <string name="attendance_summary_final">Attendance</string>
<string name="attendance_summary_total">Total</string>
<!--Exam--> <!--Exam-->