1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-24 03:46:00 -06:00

Add mark as read button enable logic (#534)

This commit is contained in:
Dominik Korsa 2019-10-06 21:25:24 +02:00 committed by Rafał Borcz
parent 93750829d7
commit 1de747fa35
4 changed files with 22 additions and 0 deletions

View File

@ -33,6 +33,8 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
@Inject @Inject
lateinit var gradeDetailsAdapter: FlexibleAdapter<AbstractFlexibleItem<*>> lateinit var gradeDetailsAdapter: FlexibleAdapter<AbstractFlexibleItem<*>>
private var gradeDetailsMenu: Menu? = null
companion object { companion object {
fun newInstance() = GradeDetailsFragment() fun newInstance() = GradeDetailsFragment()
} }
@ -69,6 +71,8 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.action_menu_grade_details, menu) inflater.inflate(R.menu.action_menu_grade_details, menu)
gradeDetailsMenu = menu
presenter.updateMarkAsDoneButton()
} }
override fun initView() { override fun initView() {
@ -165,6 +169,10 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
(parentFragment as? GradeFragment)?.onChildRefresh() (parentFragment as? GradeFragment)?.onChildRefresh()
} }
override fun enableMarkAsDoneButton(enable: Boolean) {
gradeDetailsMenu?.findItem(R.id.gradeDetailsMenuRead)?.isEnabled = enable
}
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
presenter.onDetachView() presenter.onDetachView()

View File

@ -1,5 +1,6 @@
package io.github.wulkanowy.ui.modules.grade.details package io.github.wulkanowy.ui.modules.grade.details
import android.widget.Toast
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.data.db.entities.Grade
import io.github.wulkanowy.data.repositories.grade.GradeRepository import io.github.wulkanowy.data.repositories.grade.GradeRepository
@ -26,6 +27,8 @@ class GradeDetailsPresenter @Inject constructor(
private val analytics: FirebaseAnalyticsHelper private val analytics: FirebaseAnalyticsHelper
) : BasePresenter<GradeDetailsView>(errorHandler, studentRepository, schedulers) { ) : BasePresenter<GradeDetailsView>(errorHandler, studentRepository, schedulers) {
private var newGradesAmount: Int = 0
private var currentSemesterId = 0 private var currentSemesterId = 0
override fun onAttachView(view: GradeDetailsView) { override fun onAttachView(view: GradeDetailsView) {
@ -52,6 +55,8 @@ class GradeDetailsPresenter @Inject constructor(
updateItem(header) updateItem(header)
} }
} }
newGradesAmount--
updateMarkAsDoneButton()
updateGrade(item.grade) updateGrade(item.grade)
} }
} }
@ -106,6 +111,10 @@ class GradeDetailsPresenter @Inject constructor(
disposable.clear() disposable.clear()
} }
fun updateMarkAsDoneButton() {
view?.enableMarkAsDoneButton(newGradesAmount > 0)
}
private fun loadData(semesterId: Int, forceRefresh: Boolean) { private fun loadData(semesterId: Int, forceRefresh: Boolean) {
Timber.i("Loading grade details data started") Timber.i("Loading grade details data started")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
@ -131,6 +140,8 @@ class GradeDetailsPresenter @Inject constructor(
} }
.subscribe({ .subscribe({
Timber.i("Loading grade details result: Success") Timber.i("Loading grade details result: Success")
newGradesAmount = it.sumBy { gradeDetailsHeader -> gradeDetailsHeader.newGrades }
updateMarkAsDoneButton()
view?.run { view?.run {
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
showContent(it.isNotEmpty()) showContent(it.isNotEmpty())

View File

@ -46,6 +46,8 @@ interface GradeDetailsView : BaseView {
fun notifyParentRefresh() fun notifyParentRefresh()
fun enableMarkAsDoneButton(enable: Boolean)
fun getGradeNumberString(number: Int): String fun getGradeNumberString(number: Int): String
fun getHeaderOfItem(item: AbstractFlexibleItem<*>): IExpandable<*, out IFlexible<*>>? fun getHeaderOfItem(item: AbstractFlexibleItem<*>): IExpandable<*, out IFlexible<*>>?

View File

@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/gradeDetailsMenuRead" android:id="@+id/gradeDetailsMenuRead"
android:enabled="false"
android:orderInCategory="100" android:orderInCategory="100"
android:title="@string/grade_menu_read" android:title="@string/grade_menu_read"
app:iconTint="@color/mtrl_on_surface_emphasis_medium" app:iconTint="@color/mtrl_on_surface_emphasis_medium"