forked from github/wulkanowy-mirror
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 {
|
companion object {
|
||||||
private const val SAVED_CHART_TYPE = "CURRENT_TYPE"
|
private const val SAVED_CHART_TYPE = "CURRENT_TYPE"
|
||||||
|
private const val SAVED_SUBJECT_NAME = "SUBJECT_NAME"
|
||||||
|
|
||||||
fun newInstance() = GradeStatisticsFragment()
|
fun newInstance() = GradeStatisticsFragment()
|
||||||
}
|
}
|
||||||
@ -46,8 +47,9 @@ class GradeStatisticsFragment :
|
|||||||
binding = FragmentGradeStatisticsBinding.bind(view)
|
binding = FragmentGradeStatisticsBinding.bind(view)
|
||||||
messageContainer = binding.gradeStatisticsRecycler
|
messageContainer = binding.gradeStatisticsRecycler
|
||||||
presenter.onAttachView(
|
presenter.onAttachView(
|
||||||
this,
|
view = this,
|
||||||
savedInstanceState?.getSerializable(SAVED_CHART_TYPE) as? GradeStatisticsItem.DataType
|
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) {
|
with(binding.gradeStatisticsRecycler) {
|
||||||
layoutManager = LinearLayoutManager(requireContext())
|
layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
statisticsAdapter.currentDataType = presenter.currentType
|
||||||
adapter = statisticsAdapter
|
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) {
|
with(subjectsAdapter) {
|
||||||
clear()
|
clear()
|
||||||
addAll(data)
|
addAll(data)
|
||||||
@ -161,6 +165,7 @@ class GradeStatisticsFragment :
|
|||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
outState.putSerializable(SAVED_CHART_TYPE, presenter.currentType)
|
outState.putSerializable(SAVED_CHART_TYPE, presenter.currentType)
|
||||||
|
outState.putSerializable(SAVED_SUBJECT_NAME, presenter.currentSubjectName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
@ -31,16 +31,22 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
|
|
||||||
private var currentSemesterId = 0
|
private var currentSemesterId = 0
|
||||||
|
|
||||||
private var currentSubjectName: String = "Wszystkie"
|
var currentSubjectName: String = "Wszystkie"
|
||||||
|
private set
|
||||||
|
|
||||||
private lateinit var lastError: Throwable
|
private lateinit var lastError: Throwable
|
||||||
|
|
||||||
var currentType: GradeStatisticsItem.DataType = GradeStatisticsItem.DataType.PARTIAL
|
var currentType: GradeStatisticsItem.DataType = GradeStatisticsItem.DataType.PARTIAL
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun onAttachView(view: GradeStatisticsView, type: GradeStatisticsItem.DataType?) {
|
fun onAttachView(
|
||||||
|
view: GradeStatisticsView,
|
||||||
|
type: GradeStatisticsItem.DataType?,
|
||||||
|
subjectName: String?
|
||||||
|
) {
|
||||||
super.onAttachView(view)
|
super.onAttachView(view)
|
||||||
currentType = type ?: GradeStatisticsItem.DataType.PARTIAL
|
currentType = type ?: GradeStatisticsItem.DataType.PARTIAL
|
||||||
|
currentSubjectName = subjectName ?: currentSubjectName
|
||||||
view.initView()
|
view.initView()
|
||||||
errorHandler.showErrorMessage = ::showErrorViewOnError
|
errorHandler.showErrorMessage = ::showErrorViewOnError
|
||||||
}
|
}
|
||||||
@ -127,12 +133,17 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
when (it.status) {
|
when (it.status) {
|
||||||
Status.LOADING -> Timber.i("Loading grade stats subjects started")
|
Status.LOADING -> Timber.i("Loading grade stats subjects started")
|
||||||
Status.SUCCESS -> {
|
Status.SUCCESS -> {
|
||||||
subjects = it.data!!
|
subjects = requireNotNull(it.data)
|
||||||
|
|
||||||
Timber.i("Loading grade stats subjects result: Success")
|
Timber.i("Loading grade stats subjects result: Success")
|
||||||
|
|
||||||
view?.run {
|
view?.run {
|
||||||
view?.updateSubjects(ArrayList(it.data.map { subject -> subject.name }))
|
|
||||||
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
||||||
|
updateSubjects(
|
||||||
|
data = it.data.map { subject -> subject.name },
|
||||||
|
selectedIndex = it.data.indexOfFirst { subject ->
|
||||||
|
subject.name == currentSubjectName
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Status.ERROR -> {
|
Status.ERROR -> {
|
||||||
@ -151,9 +162,11 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
Timber.i("Loading grade stats data started")
|
Timber.i("Loading grade stats data started")
|
||||||
|
|
||||||
currentSubjectName =
|
|
||||||
if (preferencesRepository.showAllSubjectsOnStatisticsList) "Wszystkie" else subjectName
|
|
||||||
currentType = type
|
currentType = type
|
||||||
|
currentSubjectName = when {
|
||||||
|
preferencesRepository.showAllSubjectsOnStatisticsList -> "Wszystkie"
|
||||||
|
else -> subjectName
|
||||||
|
}
|
||||||
|
|
||||||
flowWithResourceIn {
|
flowWithResourceIn {
|
||||||
val student = studentRepository.getCurrentStudent()
|
val student = studentRepository.getCurrentStudent()
|
||||||
@ -200,9 +213,9 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
showRefresh(true)
|
showRefresh(true)
|
||||||
showProgress(false)
|
showProgress(false)
|
||||||
updateData(
|
updateData(
|
||||||
if (isNoContent) emptyList() else it.data!!,
|
newItems = if (isNoContent) emptyList() else it.data!!,
|
||||||
preferencesRepository.gradeColorTheme,
|
newTheme = preferencesRepository.gradeColorTheme,
|
||||||
preferencesRepository.showAllSubjectsOnStatisticsList
|
showAllSubjectsOnStatisticsList = preferencesRepository.showAllSubjectsOnStatisticsList,
|
||||||
)
|
)
|
||||||
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
||||||
}
|
}
|
||||||
@ -215,9 +228,9 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
showEmpty(isNoContent)
|
showEmpty(isNoContent)
|
||||||
showErrorView(false)
|
showErrorView(false)
|
||||||
updateData(
|
updateData(
|
||||||
if (isNoContent) emptyList() else it.data,
|
newItems = if (isNoContent) emptyList() else it.data,
|
||||||
preferencesRepository.gradeColorTheme,
|
newTheme = preferencesRepository.gradeColorTheme,
|
||||||
preferencesRepository.showAllSubjectsOnStatisticsList
|
showAllSubjectsOnStatisticsList = preferencesRepository.showAllSubjectsOnStatisticsList,
|
||||||
)
|
)
|
||||||
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
showSubjects(!preferencesRepository.showAllSubjectsOnStatisticsList)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ interface GradeStatisticsView : BaseView {
|
|||||||
|
|
||||||
fun initView()
|
fun initView()
|
||||||
|
|
||||||
fun updateSubjects(data: ArrayList<String>)
|
fun updateSubjects(data: List<String>, selectedIndex: Int)
|
||||||
|
|
||||||
fun updateData(
|
fun updateData(
|
||||||
newItems: List<GradeStatisticsItem>,
|
newItems: List<GradeStatisticsItem>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user