mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-22 10:46:32 -06:00
Fix state restoring in GradeStatistics (#1667)
Co-authored-by: Mikołaj Pich <m.pich@outlook.com>
This commit is contained in:
parent
094df212b4
commit
e26860ea5a
@ -33,6 +33,7 @@ class GradeStatisticsFragment :
|
||||
|
||||
companion object {
|
||||
private const val SAVED_CHART_TYPE = "CURRENT_TYPE"
|
||||
private const val SAVED_SUBJECT_NAME = "SUBJECT_NAME"
|
||||
|
||||
fun newInstance() = GradeStatisticsFragment()
|
||||
}
|
||||
@ -46,8 +47,9 @@ class GradeStatisticsFragment :
|
||||
binding = FragmentGradeStatisticsBinding.bind(view)
|
||||
messageContainer = binding.gradeStatisticsRecycler
|
||||
presenter.onAttachView(
|
||||
this,
|
||||
savedInstanceState?.getSerializable(SAVED_CHART_TYPE) as? GradeStatisticsItem.DataType
|
||||
view = this,
|
||||
type = savedInstanceState?.getSerializable(SAVED_CHART_TYPE) as? GradeStatisticsItem.DataType,
|
||||
subjectName = savedInstanceState?.getSerializable(SAVED_SUBJECT_NAME) as? String,
|
||||
)
|
||||
}
|
||||
|
||||
@ -56,6 +58,7 @@ class GradeStatisticsFragment :
|
||||
|
||||
with(binding.gradeStatisticsRecycler) {
|
||||
layoutManager = LinearLayoutManager(requireContext())
|
||||
statisticsAdapter.currentDataType = presenter.currentType
|
||||
adapter = statisticsAdapter
|
||||
}
|
||||
|
||||
@ -81,7 +84,8 @@ class GradeStatisticsFragment :
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateSubjects(data: ArrayList<String>) {
|
||||
override fun updateSubjects(data: List<String>, selectedIndex: Int) {
|
||||
binding.gradeStatisticsSubjects.setSelection(selectedIndex)
|
||||
with(subjectsAdapter) {
|
||||
clear()
|
||||
addAll(data)
|
||||
@ -161,6 +165,7 @@ class GradeStatisticsFragment :
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putSerializable(SAVED_CHART_TYPE, presenter.currentType)
|
||||
outState.putSerializable(SAVED_SUBJECT_NAME, presenter.currentSubjectName)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -31,16 +31,22 @@ class GradeStatisticsPresenter @Inject constructor(
|
||||
|
||||
private var currentSemesterId = 0
|
||||
|
||||
private var currentSubjectName: String = "Wszystkie"
|
||||
var currentSubjectName: String = "Wszystkie"
|
||||
private set
|
||||
|
||||
private lateinit var lastError: Throwable
|
||||
|
||||
var currentType: GradeStatisticsItem.DataType = GradeStatisticsItem.DataType.PARTIAL
|
||||
private set
|
||||
|
||||
fun onAttachView(view: GradeStatisticsView, type: GradeStatisticsItem.DataType?) {
|
||||
fun onAttachView(
|
||||
view: GradeStatisticsView,
|
||||
type: GradeStatisticsItem.DataType?,
|
||||
subjectName: String?
|
||||
) {
|
||||
super.onAttachView(view)
|
||||
currentType = type ?: GradeStatisticsItem.DataType.PARTIAL
|
||||
currentSubjectName = subjectName ?: currentSubjectName
|
||||
view.initView()
|
||||
errorHandler.showErrorMessage = ::showErrorViewOnError
|
||||
}
|
||||
@ -127,12 +133,17 @@ class GradeStatisticsPresenter @Inject constructor(
|
||||
when (it.status) {
|
||||
Status.LOADING -> Timber.i("Loading grade stats subjects started")
|
||||
Status.SUCCESS -> {
|
||||
subjects = it.data!!
|
||||
|
||||
subjects = requireNotNull(it.data)
|
||||
Timber.i("Loading grade stats subjects result: Success")
|
||||
|
||||
view?.run {
|
||||
view?.updateSubjects(ArrayList(it.data.map { subject -> subject.name }))
|
||||
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
||||
updateSubjects(
|
||||
data = it.data.map { subject -> subject.name },
|
||||
selectedIndex = it.data.indexOfFirst { subject ->
|
||||
subject.name == currentSubjectName
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Status.ERROR -> {
|
||||
@ -151,9 +162,11 @@ class GradeStatisticsPresenter @Inject constructor(
|
||||
) {
|
||||
Timber.i("Loading grade stats data started")
|
||||
|
||||
currentSubjectName =
|
||||
if (preferencesRepository.showAllSubjectsOnStatisticsList) "Wszystkie" else subjectName
|
||||
currentType = type
|
||||
currentSubjectName = when {
|
||||
preferencesRepository.showAllSubjectsOnStatisticsList -> "Wszystkie"
|
||||
else -> subjectName
|
||||
}
|
||||
|
||||
flowWithResourceIn {
|
||||
val student = studentRepository.getCurrentStudent()
|
||||
@ -200,9 +213,9 @@ class GradeStatisticsPresenter @Inject constructor(
|
||||
showRefresh(true)
|
||||
showProgress(false)
|
||||
updateData(
|
||||
if (isNoContent) emptyList() else it.data!!,
|
||||
preferencesRepository.gradeColorTheme,
|
||||
preferencesRepository.showAllSubjectsOnStatisticsList
|
||||
newItems = if (isNoContent) emptyList() else it.data!!,
|
||||
newTheme = preferencesRepository.gradeColorTheme,
|
||||
showAllSubjectsOnStatisticsList = preferencesRepository.showAllSubjectsOnStatisticsList,
|
||||
)
|
||||
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
||||
}
|
||||
@ -215,9 +228,9 @@ class GradeStatisticsPresenter @Inject constructor(
|
||||
showEmpty(isNoContent)
|
||||
showErrorView(false)
|
||||
updateData(
|
||||
if (isNoContent) emptyList() else it.data,
|
||||
preferencesRepository.gradeColorTheme,
|
||||
preferencesRepository.showAllSubjectsOnStatisticsList
|
||||
newItems = if (isNoContent) emptyList() else it.data,
|
||||
newTheme = preferencesRepository.gradeColorTheme,
|
||||
showAllSubjectsOnStatisticsList = preferencesRepository.showAllSubjectsOnStatisticsList,
|
||||
)
|
||||
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ interface GradeStatisticsView : BaseView {
|
||||
|
||||
fun initView()
|
||||
|
||||
fun updateSubjects(data: ArrayList<String>)
|
||||
fun updateSubjects(data: List<String>, selectedIndex: Int)
|
||||
|
||||
fun updateData(
|
||||
newItems: List<GradeStatisticsItem>,
|
||||
|
Loading…
Reference in New Issue
Block a user