mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-24 01:16:05 -06:00
Add mark as read button enable logic (#534)
This commit is contained in:
parent
93750829d7
commit
1de747fa35
@ -33,6 +33,8 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
|
||||
@Inject
|
||||
lateinit var gradeDetailsAdapter: FlexibleAdapter<AbstractFlexibleItem<*>>
|
||||
|
||||
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()
|
||||
|
@ -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<GradeDetailsView>(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())
|
||||
|
@ -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<*>>?
|
||||
|
@ -3,6 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/gradeDetailsMenuRead"
|
||||
android:enabled="false"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/grade_menu_read"
|
||||
app:iconTint="@color/mtrl_on_surface_emphasis_medium"
|
||||
|
Loading…
Reference in New Issue
Block a user