From 28c234a8fdae60d21f212b23100bbc0502b01c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Thu, 29 Feb 2024 23:48:44 +0100 Subject: [PATCH] Move excuse whole day button to action bar --- .../ui/modules/attendance/AttendanceFragment.kt | 8 +++----- .../modules/attendance/AttendancePresenter.kt | 17 +++++------------ .../ui/modules/attendance/AttendanceView.kt | 2 -- .../wulkanowy/utils/AttendanceExtension.kt | 3 +++ app/src/main/res/layout/fragment_attendance.xml | 13 ------------- .../main/res/menu/context_menu_attendance.xml | 7 +++++++ 6 files changed, 18 insertions(+), 32 deletions(-) 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 c8e0a33f4..9b45352bd 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 @@ -69,6 +69,8 @@ class AttendanceFragment : BaseFragment(R.layout.frag override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { val inflater = mode.menuInflater inflater.inflate(R.menu.context_menu_attendance, menu) + menu.findItem(R.id.excuseMenuDaySubmit).setVisible(presenter.isWholeDayExcusable) + return true } @@ -84,6 +86,7 @@ class AttendanceFragment : BaseFragment(R.layout.frag override fun onActionItemClicked(mode: ActionMode, menu: MenuItem): Boolean { return when (menu.itemId) { + R.id.excuseMenuDaySubmit -> presenter.onExcuseDayButtonClick() R.id.excuseMenuSubmit -> presenter.onExcuseSubmitButtonClick() else -> false } @@ -129,7 +132,6 @@ class AttendanceFragment : BaseFragment(R.layout.frag attendanceNextButton.setOnClickListener { presenter.onNextDay() } attendanceExcuseButton.setOnClickListener { presenter.onExcuseButtonClick() } - attendanceExcuseDayButton.setOnClickListener { presenter.onExcuseDayButtonClick() } attendanceNavContainer.elevation = requireContext().dpToPx(3f) } @@ -222,10 +224,6 @@ 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)) } 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 cd75f5c2c..6b001e1d7 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,7 +38,7 @@ class AttendancePresenter @Inject constructor( private lateinit var lastError: Throwable private val attendanceToExcuseList = mutableListOf() - private var isWholeDayExcusable = false + var isWholeDayExcusable = false private var isVulcanExcusedFunctionEnabled = false @@ -130,14 +130,12 @@ class AttendancePresenter @Inject constructor( fun onExcuseButtonClick() { view?.startActionMode() - - if (isWholeDayExcusable) { - view?.showExcuseDayButton(true) - } } - fun onExcuseDayButtonClick() { + fun onExcuseDayButtonClick(): Boolean { view?.showExcuseDialog() + + return true } fun onExcuseCheckboxSelect(attendanceItem: Attendance, checked: Boolean) { @@ -183,7 +181,6 @@ class AttendancePresenter @Inject constructor( view?.apply { showExcuseCheckboxes(true) showExcuseButton(false) - showExcuseDayButton(false) enableSwipe(false) showDayNavigation(false) } @@ -195,7 +192,6 @@ class AttendancePresenter @Inject constructor( view?.apply { showExcuseCheckboxes(false) showExcuseButton(true) - showExcuseDayButton(false) enableSwipe(true) showDayNavigation(true) } @@ -230,7 +226,6 @@ class AttendancePresenter @Inject constructor( .onResourceLoading { view?.apply { showExcuseButton(false) - showExcuseDayButton(false) } } .mapResourceData { @@ -256,7 +251,7 @@ class AttendancePresenter @Inject constructor( .onResourceIntermediate { view?.showRefresh(true) } .onResourceSuccess { items -> isVulcanExcusedFunctionEnabled = items.any { item -> item.excusable } - isWholeDayExcusable = items.all { it.isExcusableOrNotExcused } + isWholeDayExcusable = items.all { it.isAbsenceExcusable } val anyExcusables = items.any { it.isExcusableOrNotExcused } view?.showExcuseButton(anyExcusables && (isParent || isVulcanExcusedFunctionEnabled)) @@ -336,7 +331,6 @@ class AttendancePresenter @Inject constructor( showProgress(true) showContent(false) showExcuseButton(false) - showExcuseDayButton(false) } is Resource.Success -> { @@ -345,7 +339,6 @@ 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 5af491e74..8cfaf1591 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,8 +48,6 @@ interface AttendanceView : BaseView { fun showExcuseButton(show: Boolean) - fun showExcuseDayButton(show: Boolean) - fun showAttendanceDialog(lesson: Attendance) fun showDatePickerDialog(selectedDate: LocalDate) diff --git a/app/src/main/java/io/github/wulkanowy/utils/AttendanceExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/AttendanceExtension.kt index 397c95953..19d0929db 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/AttendanceExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/AttendanceExtension.kt @@ -19,6 +19,9 @@ private inline val AttendanceSummary.allAbsences: Double inline val Attendance.isExcusableOrNotExcused: Boolean get() = (excusable || ((absence || lateness) && !excused)) && excuseStatus == null +inline val Attendance.isAbsenceExcusable: Boolean + get() = (excusable && absence && !excused) && excuseStatus == null + fun AttendanceSummary.calculatePercentage() = calculatePercentage(allPresences, allAbsences) fun List.calculatePercentage(): Double { diff --git a/app/src/main/res/layout/fragment_attendance.xml b/app/src/main/res/layout/fragment_attendance.xml index e3dd2ebb6..078daf610 100644 --- a/app/src/main/res/layout/fragment_attendance.xml +++ b/app/src/main/res/layout/fragment_attendance.xml @@ -69,19 +69,6 @@ app:icon="@drawable/ic_all_done_all" tools:visibility="visible" /> - - + +