Fix selected semester after change account (#1097)

This commit is contained in:
Rafał Borcz 2021-01-27 00:18:56 +01:00 committed by GitHub
parent f37ddfe00f
commit e0b067fadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 11 deletions

View File

@ -33,7 +33,6 @@ class GradeFragment : BaseFragment<FragmentGradeBinding>(R.layout.fragment_grade
private var semesterSwitchMenu: MenuItem? = null
companion object {
private const val SAVED_SEMESTER_KEY = "CURRENT_SEMESTER"
fun newInstance() = GradeFragment()
}
@ -52,7 +51,7 @@ class GradeFragment : BaseFragment<FragmentGradeBinding>(R.layout.fragment_grade
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentGradeBinding.bind(view)
presenter.onAttachView(this, savedInstanceState?.getInt(SAVED_SEMESTER_KEY))
presenter.onAttachView(this)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
@ -161,11 +160,6 @@ class GradeFragment : BaseFragment<FragmentGradeBinding>(R.layout.fragment_grade
(pagerAdapter.getFragmentInstance(index) as? GradeView.GradeChildView)?.onParentChangeSemester()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt(SAVED_SEMESTER_KEY, presenter.selectedIndex)
}
override fun onDestroyView() {
presenter.onDetachView()
super.onDestroyView()

View File

@ -21,8 +21,7 @@ class GradePresenter @Inject constructor(
private val analytics: AnalyticsHelper
) : BasePresenter<GradeView>(errorHandler, studentRepository) {
var selectedIndex = 0
private set
private var selectedIndex = 0
private var schoolYear = 0
@ -32,9 +31,8 @@ class GradePresenter @Inject constructor(
private lateinit var lastError: Throwable
fun onAttachView(view: GradeView, savedIndex: Int?) {
override fun onAttachView(view: GradeView) {
super.onAttachView(view)
selectedIndex = savedIndex ?: 0
view.initView()
Timber.i("Grade view was initialized with $selectedIndex index")
errorHandler.showErrorMessage = ::showErrorViewOnError