Move excuse whole day button to action bar

This commit is contained in:
Mikołaj Pich 2024-02-29 23:48:44 +01:00
parent f8c9122686
commit 28c234a8fd
6 changed files with 18 additions and 32 deletions

View File

@ -69,6 +69,8 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
val inflater = mode.menuInflater val inflater = mode.menuInflater
inflater.inflate(R.menu.context_menu_attendance, menu) inflater.inflate(R.menu.context_menu_attendance, menu)
menu.findItem(R.id.excuseMenuDaySubmit).setVisible(presenter.isWholeDayExcusable)
return true return true
} }
@ -84,6 +86,7 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
override fun onActionItemClicked(mode: ActionMode, menu: MenuItem): Boolean { override fun onActionItemClicked(mode: ActionMode, menu: MenuItem): Boolean {
return when (menu.itemId) { return when (menu.itemId) {
R.id.excuseMenuDaySubmit -> presenter.onExcuseDayButtonClick()
R.id.excuseMenuSubmit -> presenter.onExcuseSubmitButtonClick() R.id.excuseMenuSubmit -> presenter.onExcuseSubmitButtonClick()
else -> false else -> false
} }
@ -129,7 +132,6 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
attendanceNextButton.setOnClickListener { presenter.onNextDay() } attendanceNextButton.setOnClickListener { presenter.onNextDay() }
attendanceExcuseButton.setOnClickListener { presenter.onExcuseButtonClick() } attendanceExcuseButton.setOnClickListener { presenter.onExcuseButtonClick() }
attendanceExcuseDayButton.setOnClickListener { presenter.onExcuseDayButtonClick() }
attendanceNavContainer.elevation = requireContext().dpToPx(3f) attendanceNavContainer.elevation = requireContext().dpToPx(3f)
} }
@ -222,10 +224,6 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
binding.attendanceExcuseButton.isVisible = show binding.attendanceExcuseButton.isVisible = show
} }
override fun showExcuseDayButton(show: Boolean) {
binding.attendanceExcuseDayButton.isVisible = show
}
override fun showAttendanceDialog(lesson: Attendance) { override fun showAttendanceDialog(lesson: Attendance) {
(activity as? MainActivity)?.showDialogFragment(AttendanceDialog.newInstance(lesson)) (activity as? MainActivity)?.showDialogFragment(AttendanceDialog.newInstance(lesson))
} }

View File

@ -38,7 +38,7 @@ class AttendancePresenter @Inject constructor(
private lateinit var lastError: Throwable private lateinit var lastError: Throwable
private val attendanceToExcuseList = mutableListOf<Attendance>() private val attendanceToExcuseList = mutableListOf<Attendance>()
private var isWholeDayExcusable = false var isWholeDayExcusable = false
private var isVulcanExcusedFunctionEnabled = false private var isVulcanExcusedFunctionEnabled = false
@ -130,14 +130,12 @@ class AttendancePresenter @Inject constructor(
fun onExcuseButtonClick() { fun onExcuseButtonClick() {
view?.startActionMode() view?.startActionMode()
if (isWholeDayExcusable) {
view?.showExcuseDayButton(true)
}
} }
fun onExcuseDayButtonClick() { fun onExcuseDayButtonClick(): Boolean {
view?.showExcuseDialog() view?.showExcuseDialog()
return true
} }
fun onExcuseCheckboxSelect(attendanceItem: Attendance, checked: Boolean) { fun onExcuseCheckboxSelect(attendanceItem: Attendance, checked: Boolean) {
@ -183,7 +181,6 @@ class AttendancePresenter @Inject constructor(
view?.apply { view?.apply {
showExcuseCheckboxes(true) showExcuseCheckboxes(true)
showExcuseButton(false) showExcuseButton(false)
showExcuseDayButton(false)
enableSwipe(false) enableSwipe(false)
showDayNavigation(false) showDayNavigation(false)
} }
@ -195,7 +192,6 @@ class AttendancePresenter @Inject constructor(
view?.apply { view?.apply {
showExcuseCheckboxes(false) showExcuseCheckboxes(false)
showExcuseButton(true) showExcuseButton(true)
showExcuseDayButton(false)
enableSwipe(true) enableSwipe(true)
showDayNavigation(true) showDayNavigation(true)
} }
@ -230,7 +226,6 @@ class AttendancePresenter @Inject constructor(
.onResourceLoading { .onResourceLoading {
view?.apply { view?.apply {
showExcuseButton(false) showExcuseButton(false)
showExcuseDayButton(false)
} }
} }
.mapResourceData { .mapResourceData {
@ -256,7 +251,7 @@ class AttendancePresenter @Inject constructor(
.onResourceIntermediate { view?.showRefresh(true) } .onResourceIntermediate { view?.showRefresh(true) }
.onResourceSuccess { items -> .onResourceSuccess { items ->
isVulcanExcusedFunctionEnabled = items.any { item -> item.excusable } isVulcanExcusedFunctionEnabled = items.any { item -> item.excusable }
isWholeDayExcusable = items.all { it.isExcusableOrNotExcused } isWholeDayExcusable = items.all { it.isAbsenceExcusable }
val anyExcusables = items.any { it.isExcusableOrNotExcused } val anyExcusables = items.any { it.isExcusableOrNotExcused }
view?.showExcuseButton(anyExcusables && (isParent || isVulcanExcusedFunctionEnabled)) view?.showExcuseButton(anyExcusables && (isParent || isVulcanExcusedFunctionEnabled))
@ -336,7 +331,6 @@ class AttendancePresenter @Inject constructor(
showProgress(true) showProgress(true)
showContent(false) showContent(false)
showExcuseButton(false) showExcuseButton(false)
showExcuseDayButton(false)
} }
is Resource.Success -> { is Resource.Success -> {
@ -345,7 +339,6 @@ class AttendancePresenter @Inject constructor(
attendanceToExcuseList.clear() attendanceToExcuseList.clear()
view?.run { view?.run {
showExcuseButton(false) showExcuseButton(false)
showExcuseDayButton(false)
showMessage(excuseSuccessString) showMessage(excuseSuccessString)
showContent(true) showContent(true)
showProgress(false) showProgress(false)

View File

@ -48,8 +48,6 @@ interface AttendanceView : BaseView {
fun showExcuseButton(show: Boolean) fun showExcuseButton(show: Boolean)
fun showExcuseDayButton(show: Boolean)
fun showAttendanceDialog(lesson: Attendance) fun showAttendanceDialog(lesson: Attendance)
fun showDatePickerDialog(selectedDate: LocalDate) fun showDatePickerDialog(selectedDate: LocalDate)

View File

@ -19,6 +19,9 @@ private inline val AttendanceSummary.allAbsences: Double
inline val Attendance.isExcusableOrNotExcused: Boolean inline val Attendance.isExcusableOrNotExcused: Boolean
get() = (excusable || ((absence || lateness) && !excused)) && excuseStatus == null 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 AttendanceSummary.calculatePercentage() = calculatePercentage(allPresences, allAbsences)
fun List<AttendanceSummary>.calculatePercentage(): Double { fun List<AttendanceSummary>.calculatePercentage(): Double {

View File

@ -69,19 +69,6 @@
app:icon="@drawable/ic_all_done_all" app:icon="@drawable/ic_all_done_all"
tools:visibility="visible" /> tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/attendanceExcuseDayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:clickable="true"
android:focusable="true"
android:text="@string/attendance_excuse_day_title"
android:visibility="gone"
app:icon="@drawable/ic_all_done_all"
tools:visibility="visible" />
<LinearLayout <LinearLayout
android:id="@+id/attendanceError" android:id="@+id/attendanceError"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -2,6 +2,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/excuseMenuDaySubmit"
android:icon="@drawable/ic_all_done_all"
android:title="@string/attendance_excuse_day_title"
app:iconTint="@color/material_on_surface_emphasis_medium"
app:showAsAction="always" />
<item <item
android:id="@+id/excuseMenuSubmit" android:id="@+id/excuseMenuSubmit"
android:icon="@drawable/ic_all_done" android:icon="@drawable/ic_all_done"