diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/AttendanceRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/AttendanceRepository.kt index bbf627de0..2d817d8a4 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/AttendanceRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/AttendanceRepository.kt @@ -88,9 +88,12 @@ class AttendanceRepository @Inject constructor( return attendanceDb.updateAll(timetable) } + @JvmName("excuseForAbsenceLessons") suspend fun excuseForAbsence( - student: Student, semester: Semester, - absenceList: List, reason: String? = null + student: Student, + semester: Semester, + absenceList: List, + reason: String? = null ) { val items = absenceList.map { attendance -> Absent( @@ -102,4 +105,22 @@ class AttendanceRepository @Inject constructor( .switchSemester(semester) .excuseForAbsence(items, reason) } + + @JvmName("excuseForAbsenceDays") + suspend fun excuseForAbsence( + student: Student, + semester: Semester, + days: List, + reason: String? = null + ) { + val items = days.map { day -> + Absent( + date = LocalDateTime.of(day, LocalTime.of(0, 0)), + timeId = null, + ) + } + sdk.init(student) + .switchSemester(semester) + .excuseForAbsence(items, reason) + } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt index 6e842b4d7..c8e0a33f4 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt @@ -2,8 +2,14 @@ package io.github.wulkanowy.ui.modules.attendance import android.content.DialogInterface.BUTTON_POSITIVE import android.os.Bundle -import android.view.* -import android.view.View.* +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem +import android.view.View +import android.view.View.GONE +import android.view.View.INVISIBLE +import android.view.View.VISIBLE import androidx.appcompat.view.ActionMode import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager @@ -123,6 +129,7 @@ class AttendanceFragment : BaseFragment(R.layout.frag attendanceNextButton.setOnClickListener { presenter.onNextDay() } attendanceExcuseButton.setOnClickListener { presenter.onExcuseButtonClick() } + attendanceExcuseDayButton.setOnClickListener { presenter.onExcuseDayButtonClick() } attendanceNavContainer.elevation = requireContext().dpToPx(3f) } @@ -215,6 +222,10 @@ class AttendanceFragment : BaseFragment(R.layout.frag binding.attendanceExcuseButton.isVisible = show } + override fun showExcuseDayButton(show: Boolean) { + binding.attendanceExcuseDayButton.isVisible = show + } + override fun showAttendanceDialog(lesson: Attendance) { (activity as? MainActivity)?.showDialogFragment(AttendanceDialog.newInstance(lesson)) } @@ -257,11 +268,18 @@ class AttendanceFragment : BaseFragment(R.layout.frag actionMode = (activity as MainActivity?)?.startSupportActionMode(actionModeCallback) } - override fun startSendMessageIntent(date: LocalDate, numbers: String, reason: String) { - val reasonFullText = getString( - R.string.attendance_excuse_formula, + override fun startSendMessageIntent(date: LocalDate, lessons: String, reason: String) { + val reasonFullText = if (lessons.isEmpty()) { + getString( + R.string.attendance_excuse_day_formula, + date, + if (reason.isNotBlank()) " ${getString(R.string.attendance_excuse_reason)} " else "", + reason.ifBlank { "" } + ) + } else getString( + R.string.attendance_excuse_lessons_formula, date, - numbers, + lessons, if (reason.isNotBlank()) " ${getString(R.string.attendance_excuse_reason)} " else "", reason.ifBlank { "" } ) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt index 82fe69cb7..cd75f5c2c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt @@ -38,6 +38,7 @@ class AttendancePresenter @Inject constructor( private lateinit var lastError: Throwable private val attendanceToExcuseList = mutableListOf() + private var isWholeDayExcusable = false private var isVulcanExcusedFunctionEnabled = false @@ -129,6 +130,14 @@ class AttendancePresenter @Inject constructor( fun onExcuseButtonClick() { view?.startActionMode() + + if (isWholeDayExcusable) { + view?.showExcuseDayButton(true) + } + } + + fun onExcuseDayButtonClick() { + view?.showExcuseDialog() } fun onExcuseCheckboxSelect(attendanceItem: Attendance, checked: Boolean) { @@ -152,7 +161,7 @@ class AttendancePresenter @Inject constructor( fun onExcuseDialogSubmit(reason: String) { view?.finishActionMode() - if (attendanceToExcuseList.isEmpty()) return + if (attendanceToExcuseList.isEmpty() && !isWholeDayExcusable) return if (isVulcanExcusedFunctionEnabled) { excuseAbsence( @@ -163,8 +172,8 @@ class AttendancePresenter @Inject constructor( val attendanceToExcuseNumbers = attendanceToExcuseList.map { it.number } view?.startSendMessageIntent( - date = attendanceToExcuseList[0].date, - numbers = attendanceToExcuseNumbers.joinToString(", "), + date = currentDate ?: attendanceToExcuseList[0].date, + lessons = attendanceToExcuseNumbers.joinToString(", "), reason = reason ) } @@ -174,6 +183,7 @@ class AttendancePresenter @Inject constructor( view?.apply { showExcuseCheckboxes(true) showExcuseButton(false) + showExcuseDayButton(false) enableSwipe(false) showDayNavigation(false) } @@ -185,6 +195,7 @@ class AttendancePresenter @Inject constructor( view?.apply { showExcuseCheckboxes(false) showExcuseButton(true) + showExcuseDayButton(false) enableSwipe(true) showDayNavigation(true) } @@ -217,7 +228,10 @@ class AttendancePresenter @Inject constructor( } .logResourceStatus("load attendance") .onResourceLoading { - view?.showExcuseButton(false) + view?.apply { + showExcuseButton(false) + showExcuseDayButton(false) + } } .mapResourceData { if (prefRepository.isShowPresent) { @@ -240,15 +254,16 @@ class AttendancePresenter @Inject constructor( } } .onResourceIntermediate { view?.showRefresh(true) } - .onResourceSuccess { - isVulcanExcusedFunctionEnabled = it.any { item -> item.excusable } - val anyExcusables = it.any { it.isExcusableOrNotExcused } + .onResourceSuccess { items -> + isVulcanExcusedFunctionEnabled = items.any { item -> item.excusable } + isWholeDayExcusable = items.all { it.isExcusableOrNotExcused } + val anyExcusables = items.any { it.isExcusableOrNotExcused } view?.showExcuseButton(anyExcusables && (isParent || isVulcanExcusedFunctionEnabled)) analytics.logEvent( "load_data", "type" to "attendance", - "items" to it.size + "items" to items.size ) } .onResourceNotLoading { @@ -301,7 +316,19 @@ class AttendancePresenter @Inject constructor( resourceFlow { val student = studentRepository.getCurrentStudent() val semester = semesterRepository.getCurrentSemester(student) - attendanceRepository.excuseForAbsence(student, semester, toExcuseList, reason) + if (toExcuseList.isEmpty()) { + attendanceRepository.excuseForAbsence( + student = student, + semester = semester, + days = listOfNotNull(currentDate), + reason = reason + ) + } else attendanceRepository.excuseForAbsence( + student = student, + semester = semester, + absenceList = toExcuseList, + reason = reason + ) }.onEach { when (it) { is Resource.Loading -> view?.run { @@ -309,6 +336,7 @@ class AttendancePresenter @Inject constructor( showProgress(true) showContent(false) showExcuseButton(false) + showExcuseDayButton(false) } is Resource.Success -> { @@ -317,6 +345,7 @@ class AttendancePresenter @Inject constructor( attendanceToExcuseList.clear() view?.run { showExcuseButton(false) + showExcuseDayButton(false) showMessage(excuseSuccessString) showContent(true) showProgress(false) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt index 2629c217e..5af491e74 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt @@ -48,6 +48,8 @@ interface AttendanceView : BaseView { fun showExcuseButton(show: Boolean) + fun showExcuseDayButton(show: Boolean) + fun showAttendanceDialog(lesson: Attendance) fun showDatePickerDialog(selectedDate: LocalDate) @@ -56,7 +58,7 @@ interface AttendanceView : BaseView { fun openSummaryView() - fun startSendMessageIntent(date: LocalDate, numbers: String, reason: String) + fun startSendMessageIntent(date: LocalDate, lessons: String, reason: String) fun startActionMode() diff --git a/app/src/main/res/layout/fragment_attendance.xml b/app/src/main/res/layout/fragment_attendance.xml index 078daf610..e3dd2ebb6 100644 --- a/app/src/main/res/layout/fragment_attendance.xml +++ b/app/src/main/res/layout/fragment_attendance.xml @@ -69,6 +69,19 @@ app:icon="@drawable/ic_all_done_all" tools:visibility="visible" /> + + Absence excuse request sent successfully! You must select at least one absence! Excuse + Excuse entire day z powodu - Dzień dobry,\nProszę o usprawiedliwienie mojego dziecka w dniu %s z lekcji %s%s%s.\n\nPozdrawiam. + Dzień dobry,\nProszę o usprawiedliwienie mojego dziecka w dniu %s z lekcji %s%s%s.\n\nPozdrawiam. + Dzień dobry,\nProszę o usprawiedliwienie mojego dziecka w dniu %s%s%s.\n\nPozdrawiam. New attendance New attendance