forked from github/wulkanowy-mirror
Add mark as read to grade menu (#194)
This commit is contained in:
parent
f96d0ebed9
commit
6fd70a0194
@ -2,6 +2,9 @@ package io.github.wulkanowy.ui.modules.grade.details
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.GONE
|
import android.view.View.GONE
|
||||||
import android.view.View.INVISIBLE
|
import android.view.View.INVISIBLE
|
||||||
@ -45,6 +48,11 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
|
|||||||
override val isViewEmpty
|
override val isViewEmpty
|
||||||
get() = gradeDetailsAdapter.isEmpty
|
get() = gradeDetailsAdapter.isEmpty
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setHasOptionsMenu(true)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_grade_details, container, false)
|
return inflater.inflate(R.layout.fragment_grade_details, container, false)
|
||||||
}
|
}
|
||||||
@ -55,6 +63,10 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
|
|||||||
presenter.onAttachView(this)
|
presenter.onAttachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||||
|
inflater?.inflate(R.menu.action_menu_grade_details, menu)
|
||||||
|
}
|
||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
gradeDetailsAdapter.run {
|
gradeDetailsAdapter.run {
|
||||||
isAutoCollapseOnExpand = true
|
isAutoCollapseOnExpand = true
|
||||||
@ -69,6 +81,11 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
|
|||||||
gradeDetailsSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
gradeDetailsSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||||
|
return if (item?.itemId == R.id.gradeDetailsMenuRead) presenter.onMarkAsReadSelected()
|
||||||
|
else false
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateData(data: List<GradeDetailsHeader>) {
|
override fun updateData(data: List<GradeDetailsHeader>) {
|
||||||
gradeDetailsAdapter.updateDataSet(data, true)
|
gradeDetailsAdapter.updateDataSet(data, true)
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,74 @@ class GradeDetailsPresenter @Inject constructor(
|
|||||||
private val preferencesRepository: PreferencesRepository
|
private val preferencesRepository: PreferencesRepository
|
||||||
) : BasePresenter<GradeDetailsView>(errorHandler) {
|
) : BasePresenter<GradeDetailsView>(errorHandler) {
|
||||||
|
|
||||||
|
private var currentSemesterId = 0
|
||||||
|
|
||||||
override fun onAttachView(view: GradeDetailsView) {
|
override fun onAttachView(view: GradeDetailsView) {
|
||||||
super.onAttachView(view)
|
super.onAttachView(view)
|
||||||
view.initView()
|
view.initView()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onParentViewLoadData(semesterId: Int, forceRefresh: Boolean) {
|
fun onParentViewLoadData(semesterId: Int, forceRefresh: Boolean) {
|
||||||
|
currentSemesterId = semesterId
|
||||||
|
loadData(semesterId, forceRefresh)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onGradeItemSelected(item: AbstractFlexibleItem<*>?) {
|
||||||
|
if (item is GradeDetailsItem) {
|
||||||
|
view?.apply {
|
||||||
|
showGradeDialog(item.grade)
|
||||||
|
if (!item.grade.isRead) {
|
||||||
|
item.grade.isRead = true
|
||||||
|
updateItem(item)
|
||||||
|
getHeaderOfItem(item)?.let { header ->
|
||||||
|
if (header is GradeDetailsHeader) {
|
||||||
|
header.newGrades--
|
||||||
|
updateItem(header)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateGrade(item.grade)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onMarkAsReadSelected(): Boolean {
|
||||||
|
disposable.add(studentRepository.getCurrentStudent()
|
||||||
|
.flatMap { semesterRepository.getSemesters(it) }
|
||||||
|
.flatMap { gradeRepository.getNewGrades(it.first { item -> item.semesterId == currentSemesterId }) }
|
||||||
|
.map { it.map { grade -> grade.apply { isRead = true } } }
|
||||||
|
.flatMapCompletable { gradeRepository.updateGrades(it) }
|
||||||
|
.subscribeOn(schedulers.backgroundThread)
|
||||||
|
.observeOn(schedulers.mainThread)
|
||||||
|
.subscribe({ loadData(currentSemesterId, false) }, { errorHandler.dispatch(it) }))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onSwipeRefresh() {
|
||||||
|
view?.notifyParentRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onParentViewReselected() {
|
||||||
|
view?.run {
|
||||||
|
if (!isViewEmpty) {
|
||||||
|
if (preferencesRepository.isGradeExpandable) collapseAllItems()
|
||||||
|
scrollToStart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onParentViewChangeSemester() {
|
||||||
|
view?.run {
|
||||||
|
showProgress(true)
|
||||||
|
showRefresh(false)
|
||||||
|
showContent(false)
|
||||||
|
showEmpty(false)
|
||||||
|
clearView()
|
||||||
|
}
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadData(semesterId: Int, forceRefresh: Boolean) {
|
||||||
disposable.add(studentRepository.getCurrentStudent()
|
disposable.add(studentRepository.getCurrentStudent()
|
||||||
.flatMap { semesterRepository.getSemesters(it) }
|
.flatMap { semesterRepository.getSemesters(it) }
|
||||||
.flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) }
|
.flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) }
|
||||||
@ -58,49 +120,6 @@ class GradeDetailsPresenter @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onGradeItemSelected(item: AbstractFlexibleItem<*>?) {
|
|
||||||
if (item is GradeDetailsItem) {
|
|
||||||
view?.apply {
|
|
||||||
showGradeDialog(item.grade)
|
|
||||||
if (!item.grade.isRead) {
|
|
||||||
item.grade.isRead = true
|
|
||||||
updateItem(item)
|
|
||||||
getHeaderOfItem(item)?.let { header ->
|
|
||||||
if (header is GradeDetailsHeader) {
|
|
||||||
header.newGrades--
|
|
||||||
updateItem(header)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateGrade(item.grade)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onSwipeRefresh() {
|
|
||||||
view?.notifyParentRefresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onParentViewReselected() {
|
|
||||||
view?.run {
|
|
||||||
if (!isViewEmpty) {
|
|
||||||
if (preferencesRepository.isGradeExpandable) collapseAllItems()
|
|
||||||
scrollToStart()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onParentViewChangeSemester() {
|
|
||||||
view?.run {
|
|
||||||
showProgress(true)
|
|
||||||
showRefresh(false)
|
|
||||||
showContent(false)
|
|
||||||
showEmpty(false)
|
|
||||||
clearView()
|
|
||||||
}
|
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createGradeItems(items: Map<String, List<Grade>>): List<GradeDetailsHeader> {
|
private fun createGradeItems(items: Map<String, List<Grade>>): List<GradeDetailsHeader> {
|
||||||
return items.map {
|
return items.map {
|
||||||
it.value.calcAverage().let { average ->
|
it.value.calcAverage().let { average ->
|
||||||
|
9
app/src/main/res/menu/action_menu_grade_details.xml
Normal file
9
app/src/main/res/menu/action_menu_grade_details.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/gradeDetailsMenuRead"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="@string/grade_menu_read"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
@ -59,6 +59,7 @@
|
|||||||
<string name="grade_summary_calculated_average">Obliczona średnia</string>
|
<string name="grade_summary_calculated_average">Obliczona średnia</string>
|
||||||
<string name="grade_summary_final_average">Końcowa średnia</string>
|
<string name="grade_summary_final_average">Końcowa średnia</string>
|
||||||
<string name="grade_menu_summary">Podsumowanie</string>
|
<string name="grade_menu_summary">Podsumowanie</string>
|
||||||
|
<string name="grade_menu_read">Oznacz jako przeczytane</string>
|
||||||
<plurals name="grade_number_item">
|
<plurals name="grade_number_item">
|
||||||
<item quantity="one">%d ocena</item>
|
<item quantity="one">%d ocena</item>
|
||||||
<item quantity="few">%d oceny</item>
|
<item quantity="few">%d oceny</item>
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
<string name="grade_summary_calculated_average">Calculated average</string>
|
<string name="grade_summary_calculated_average">Calculated average</string>
|
||||||
<string name="grade_summary_final_average">Final average</string>
|
<string name="grade_summary_final_average">Final average</string>
|
||||||
<string name="grade_menu_summary">Summary</string>
|
<string name="grade_menu_summary">Summary</string>
|
||||||
|
<string name="grade_menu_read">Mark as read</string>
|
||||||
<plurals name="grade_number_item">
|
<plurals name="grade_number_item">
|
||||||
<item quantity="one">%d grade</item>
|
<item quantity="one">%d grade</item>
|
||||||
<item quantity="other">%d grades</item>
|
<item quantity="other">%d grades</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user