mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 18:22:45 +01:00
Fix semester switch when student have only one semester (#1215)
This commit is contained in:
parent
94506aca52
commit
8644ce32d5
@ -150,7 +150,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "io.github.wulkanowy:sdk:1.1.0"
|
implementation "io.github.wulkanowy:sdk:b2c274e"
|
||||||
|
|
||||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import android.view.View.VISIBLE
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.databinding.FragmentGradeBinding
|
import io.github.wulkanowy.databinding.FragmentGradeBinding
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment
|
import io.github.wulkanowy.ui.base.BaseFragment
|
||||||
import io.github.wulkanowy.ui.base.BaseFragmentPagerAdapter
|
import io.github.wulkanowy.ui.base.BaseFragmentPagerAdapter
|
||||||
@ -121,11 +122,9 @@ class GradeFragment : BaseFragment<FragmentGradeBinding>(R.layout.fragment_grade
|
|||||||
semesterSwitchMenu?.isVisible = show
|
semesterSwitchMenu?.isVisible = show
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showSemesterDialog(selectedIndex: Int) {
|
override fun showSemesterDialog(selectedIndex: Int, semesters: List<Semester>) {
|
||||||
val choices = arrayOf(
|
val choices = semesters.map { getString(R.string.grade_semester, it.semesterName) }
|
||||||
getString(R.string.grade_semester, 1),
|
.toTypedArray()
|
||||||
getString(R.string.grade_semester, 2)
|
|
||||||
)
|
|
||||||
|
|
||||||
AlertDialog.Builder(requireContext())
|
AlertDialog.Builder(requireContext())
|
||||||
.setSingleChoiceItems(choices, selectedIndex) { dialog, which ->
|
.setSingleChoiceItems(choices, selectedIndex) { dialog, which ->
|
||||||
|
@ -49,7 +49,9 @@ class GradePresenter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onSemesterSwitch(): Boolean {
|
fun onSemesterSwitch(): Boolean {
|
||||||
if (semesters.isNotEmpty()) view?.showSemesterDialog(selectedIndex - 1)
|
if (semesters.isNotEmpty()) {
|
||||||
|
view?.showSemesterDialog(selectedIndex - 1, semesters.slice(0..1))
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,11 +139,17 @@ class GradePresenter @Inject constructor(
|
|||||||
|
|
||||||
private fun loadChild(index: Int, forceRefresh: Boolean = false) {
|
private fun loadChild(index: Int, forceRefresh: Boolean = false) {
|
||||||
Timber.d("Load grade tab child. Selected semester: $selectedIndex, semesters: ${semesters.joinToString { it.semesterName.toString() }}")
|
Timber.d("Load grade tab child. Selected semester: $selectedIndex, semesters: ${semesters.joinToString { it.semesterName.toString() }}")
|
||||||
semesters.first { it.semesterName == selectedIndex }.semesterId.also {
|
|
||||||
if (forceRefresh || loadedSemesterId[index] != it) {
|
val newSelectedSemesterId = try {
|
||||||
Timber.i("Load grade child view index: $index")
|
semesters.first { it.semesterName == selectedIndex }.semesterId
|
||||||
view?.notifyChildLoadData(index, it, forceRefresh)
|
} catch (e: NoSuchElementException) {
|
||||||
}
|
Timber.e(e, "Selected semester no exists")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forceRefresh || loadedSemesterId[index] != newSelectedSemesterId) {
|
||||||
|
Timber.i("Load grade child view index: $index")
|
||||||
|
view?.notifyChildLoadData(index, newSelectedSemesterId, forceRefresh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.ui.modules.grade
|
package io.github.wulkanowy.ui.modules.grade
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.ui.base.BaseView
|
import io.github.wulkanowy.ui.base.BaseView
|
||||||
|
|
||||||
interface GradeView : BaseView {
|
interface GradeView : BaseView {
|
||||||
@ -18,7 +19,7 @@ interface GradeView : BaseView {
|
|||||||
|
|
||||||
fun showSemesterSwitch(show: Boolean)
|
fun showSemesterSwitch(show: Boolean)
|
||||||
|
|
||||||
fun showSemesterDialog(selectedIndex: Int)
|
fun showSemesterDialog(selectedIndex: Int, semesters: List<Semester>)
|
||||||
|
|
||||||
fun setCurrentSemesterName(semester: Int, schoolYear: Int)
|
fun setCurrentSemesterName(semester: Int, schoolYear: Int)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user