mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 02:56:45 -06: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 {
|
||||
implementation "io.github.wulkanowy:sdk:1.1.0"
|
||||
implementation "io.github.wulkanowy:sdk:b2c274e"
|
||||
|
||||
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 dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.databinding.FragmentGradeBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.base.BaseFragmentPagerAdapter
|
||||
@ -121,11 +122,9 @@ class GradeFragment : BaseFragment<FragmentGradeBinding>(R.layout.fragment_grade
|
||||
semesterSwitchMenu?.isVisible = show
|
||||
}
|
||||
|
||||
override fun showSemesterDialog(selectedIndex: Int) {
|
||||
val choices = arrayOf(
|
||||
getString(R.string.grade_semester, 1),
|
||||
getString(R.string.grade_semester, 2)
|
||||
)
|
||||
override fun showSemesterDialog(selectedIndex: Int, semesters: List<Semester>) {
|
||||
val choices = semesters.map { getString(R.string.grade_semester, it.semesterName) }
|
||||
.toTypedArray()
|
||||
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setSingleChoiceItems(choices, selectedIndex) { dialog, which ->
|
||||
|
@ -49,7 +49,9 @@ class GradePresenter @Inject constructor(
|
||||
}
|
||||
|
||||
fun onSemesterSwitch(): Boolean {
|
||||
if (semesters.isNotEmpty()) view?.showSemesterDialog(selectedIndex - 1)
|
||||
if (semesters.isNotEmpty()) {
|
||||
view?.showSemesterDialog(selectedIndex - 1, semesters.slice(0..1))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -137,11 +139,17 @@ class GradePresenter @Inject constructor(
|
||||
|
||||
private fun loadChild(index: Int, forceRefresh: Boolean = false) {
|
||||
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) {
|
||||
Timber.i("Load grade child view index: $index")
|
||||
view?.notifyChildLoadData(index, it, forceRefresh)
|
||||
}
|
||||
|
||||
val newSelectedSemesterId = try {
|
||||
semesters.first { it.semesterName == selectedIndex }.semesterId
|
||||
} 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
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.ui.base.BaseView
|
||||
|
||||
interface GradeView : BaseView {
|
||||
@ -18,7 +19,7 @@ interface GradeView : BaseView {
|
||||
|
||||
fun showSemesterSwitch(show: Boolean)
|
||||
|
||||
fun showSemesterDialog(selectedIndex: Int)
|
||||
fun showSemesterDialog(selectedIndex: Int, semesters: List<Semester>)
|
||||
|
||||
fun setCurrentSemesterName(semester: Int, schoolYear: Int)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user