Skip to content

Commit

Permalink
Avoid error caused by unknown attendance type
Browse files Browse the repository at this point in the history
  • Loading branch information
kyori19 committed Jan 17, 2021
1 parent 88f902c commit eb25111
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ class AttendancesAdapter(
setImageResource(
when (item.status) {
Attendance.AttendanceStatus.PRESENT -> R.drawable.ic_check
Attendance.AttendanceStatus.ABSENT -> R.drawable.ic_cancel
Attendance.AttendanceStatus.LATE -> R.drawable.ic_time
Attendance.AttendanceStatus.ABSENT -> R.drawable.ic_none
else -> R.drawable.ic_cancel
}
)
contentDescription = context.getString(
when (item.status) {
Attendance.AttendanceStatus.PRESENT -> R.string.hint_icon_present
Attendance.AttendanceStatus.LATE -> R.string.hint_icon_late
Attendance.AttendanceStatus.ABSENT -> R.string.hint_icon_absent
else -> R.string.hint_icon_unknown
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ data class Attendance(
val status: AttendanceStatus
) : Serializable {
enum class AttendanceStatus(private val texts: Set<String>) {
UNKNOWN(setOf()),
PRESENT(setOf("出席", "Present")),
ABSENT(setOf("欠席"));
LATE(setOf("遅刻", "Late")),
ABSENT(setOf("欠席", "Absent")),
;

companion object {
fun String.toAttendanceStatus(): AttendanceStatus {
return values().first { this in it.texts }
return values().firstOrNull { this in it.texts } ?: UNKNOWN
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@
<string name="dialog_title_send_attendance_success">送信完了</string>
<string name="text_attendance_already_sent">この講義の出席は既に送信済みです。</string>
<string name="text_attendance_error">エラーが発見されました。</string>
<string name="hint_icon_late">遅刻</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<string name="hint_icon_waiting_for_answer">Waiting for answer</string>

<string name="hint_icon_absent">Absent</string>
<string name="hint_icon_late">Late</string>
<string name="hint_icon_present">Present</string>

<string name="hint_icon_not_taken">Not taken</string>
Expand Down

0 comments on commit eb25111

Please sign in to comment.