From 1de747fa35a6705b2704d9e04a62c39009a799ed Mon Sep 17 00:00:00 2001 From: Dominik Korsa Date: Sun, 6 Oct 2019 21:25:24 +0200 Subject: [PATCH] Add mark as read button enable logic (#534) --- .../ui/modules/grade/details/GradeDetailsFragment.kt | 8 ++++++++ .../ui/modules/grade/details/GradeDetailsPresenter.kt | 11 +++++++++++ .../ui/modules/grade/details/GradeDetailsView.kt | 2 ++ app/src/main/res/menu/action_menu_grade_details.xml | 1 + 4 files changed, 22 insertions(+) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt index d50fd0575..8993760d6 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt @@ -33,6 +33,8 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh @Inject lateinit var gradeDetailsAdapter: FlexibleAdapter> + private var gradeDetailsMenu: Menu? = null + companion object { fun newInstance() = GradeDetailsFragment() } @@ -69,6 +71,8 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.action_menu_grade_details, menu) + gradeDetailsMenu = menu + presenter.updateMarkAsDoneButton() } override fun initView() { @@ -165,6 +169,10 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh (parentFragment as? GradeFragment)?.onChildRefresh() } + override fun enableMarkAsDoneButton(enable: Boolean) { + gradeDetailsMenu?.findItem(R.id.gradeDetailsMenuRead)?.isEnabled = enable + } + override fun onDestroyView() { super.onDestroyView() presenter.onDetachView() diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt index 29911a541..96b556864 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt @@ -1,5 +1,6 @@ package io.github.wulkanowy.ui.modules.grade.details +import android.widget.Toast import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.data.repositories.grade.GradeRepository @@ -26,6 +27,8 @@ class GradeDetailsPresenter @Inject constructor( private val analytics: FirebaseAnalyticsHelper ) : BasePresenter(errorHandler, studentRepository, schedulers) { + private var newGradesAmount: Int = 0 + private var currentSemesterId = 0 override fun onAttachView(view: GradeDetailsView) { @@ -52,6 +55,8 @@ class GradeDetailsPresenter @Inject constructor( updateItem(header) } } + newGradesAmount-- + updateMarkAsDoneButton() updateGrade(item.grade) } } @@ -106,6 +111,10 @@ class GradeDetailsPresenter @Inject constructor( disposable.clear() } + fun updateMarkAsDoneButton() { + view?.enableMarkAsDoneButton(newGradesAmount > 0) + } + private fun loadData(semesterId: Int, forceRefresh: Boolean) { Timber.i("Loading grade details data started") disposable.add(studentRepository.getCurrentStudent() @@ -131,6 +140,8 @@ class GradeDetailsPresenter @Inject constructor( } .subscribe({ Timber.i("Loading grade details result: Success") + newGradesAmount = it.sumBy { gradeDetailsHeader -> gradeDetailsHeader.newGrades } + updateMarkAsDoneButton() view?.run { showEmpty(it.isEmpty()) showContent(it.isNotEmpty()) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsView.kt index 88b83bda9..fb806351c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsView.kt @@ -46,6 +46,8 @@ interface GradeDetailsView : BaseView { fun notifyParentRefresh() + fun enableMarkAsDoneButton(enable: Boolean) + fun getGradeNumberString(number: Int): String fun getHeaderOfItem(item: AbstractFlexibleItem<*>): IExpandable<*, out IFlexible<*>>? diff --git a/app/src/main/res/menu/action_menu_grade_details.xml b/app/src/main/res/menu/action_menu_grade_details.xml index 6f8a1aea5..fbd28eece 100644 --- a/app/src/main/res/menu/action_menu_grade_details.xml +++ b/app/src/main/res/menu/action_menu_grade_details.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto">