forked from github/wulkanowy-mirror
Fix nullable student guardians (#1128)
This commit is contained in:
@ -15,6 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.StudentGuardian
|
||||
import io.github.wulkanowy.data.db.entities.StudentInfo
|
||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||
import io.github.wulkanowy.data.enums.Gender
|
||||
@ -75,7 +76,11 @@ class StudentInfoFragment :
|
||||
with(binding) {
|
||||
studentInfoSwipe.setOnRefreshListener(presenter::onSwipeRefresh)
|
||||
studentInfoSwipe.setColorSchemeColors(requireContext().getThemeAttrColor(R.attr.colorPrimary))
|
||||
studentInfoSwipe.setProgressBackgroundColorSchemeColor(requireContext().getThemeAttrColor(R.attr.colorSwipeRefresh))
|
||||
studentInfoSwipe.setProgressBackgroundColorSchemeColor(
|
||||
requireContext().getThemeAttrColor(
|
||||
R.attr.colorSwipeRefresh
|
||||
)
|
||||
)
|
||||
studentInfoErrorRetry.setOnClickListener { presenter.onRetry() }
|
||||
studentInfoErrorDetails.setOnClickListener { presenter.onDetailsClick() }
|
||||
}
|
||||
@ -135,11 +140,14 @@ class StudentInfoFragment :
|
||||
@SuppressLint("DefaultLocale")
|
||||
override fun showFamilyTypeData(studentInfo: StudentInfo) {
|
||||
updateData(
|
||||
listOf(
|
||||
studentInfo.firstGuardian.kinship.capitalize() to studentInfo.firstGuardian.fullName,
|
||||
studentInfo.secondGuardian.kinship.capitalize() to studentInfo.secondGuardian.fullName
|
||||
).map {
|
||||
if (it.second.isBlank()) it.copy(second = getString(R.string.all_no_data)) else it
|
||||
listOfNotNull(
|
||||
studentInfo.firstGuardian?.let { it.kinship.capitalize() to it.fullName },
|
||||
studentInfo.secondGuardian?.let { it.kinship.capitalize() to it.fullName },
|
||||
).map { (title, value) ->
|
||||
val updatedValue = value.ifBlank { getString(R.string.all_no_data) }
|
||||
val updatedTitle = title.ifBlank { getString(R.string.all_no_data) }
|
||||
|
||||
updatedTitle to updatedValue
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -156,28 +164,28 @@ class StudentInfoFragment :
|
||||
)
|
||||
}
|
||||
|
||||
override fun showFirstGuardianTypeData(studentInfo: StudentInfo) {
|
||||
override fun showFirstGuardianTypeData(studentGuardian: StudentGuardian) {
|
||||
updateData(
|
||||
listOf(
|
||||
getString(R.string.student_info_full_name) to studentInfo.firstGuardian.fullName,
|
||||
getString(R.string.student_info_kinship) to studentInfo.firstGuardian.kinship,
|
||||
getString(R.string.student_info_guardian_address) to studentInfo.firstGuardian.address,
|
||||
getString(R.string.student_info_phones) to studentInfo.firstGuardian.phones,
|
||||
getString(R.string.student_info_email) to studentInfo.firstGuardian.email
|
||||
getString(R.string.student_info_full_name) to studentGuardian.fullName,
|
||||
getString(R.string.student_info_kinship) to studentGuardian.kinship,
|
||||
getString(R.string.student_info_guardian_address) to studentGuardian.address,
|
||||
getString(R.string.student_info_phones) to studentGuardian.phones,
|
||||
getString(R.string.student_info_email) to studentGuardian.email
|
||||
).map {
|
||||
if (it.second.isBlank()) it.copy(second = getString(R.string.all_no_data)) else it
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun showSecondGuardianTypeData(studentInfo: StudentInfo) {
|
||||
override fun showSecondGuardianTypeData(studentGuardian: StudentGuardian) {
|
||||
updateData(
|
||||
listOf(
|
||||
getString(R.string.student_info_full_name) to studentInfo.secondGuardian.fullName,
|
||||
getString(R.string.student_info_kinship) to studentInfo.secondGuardian.kinship,
|
||||
getString(R.string.student_info_guardian_address) to studentInfo.secondGuardian.address,
|
||||
getString(R.string.student_info_phones) to studentInfo.secondGuardian.phones,
|
||||
getString(R.string.student_info_email) to studentInfo.secondGuardian.email
|
||||
getString(R.string.student_info_full_name) to studentGuardian.fullName,
|
||||
getString(R.string.student_info_kinship) to studentGuardian.kinship,
|
||||
getString(R.string.student_info_guardian_address) to studentGuardian.address,
|
||||
getString(R.string.student_info_phones) to studentGuardian.phones,
|
||||
getString(R.string.student_info_email) to studentGuardian.email
|
||||
).map {
|
||||
if (it.second.isBlank()) it.copy(second = getString(R.string.all_no_data)) else it
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class StudentInfoPresenter @Inject constructor(
|
||||
when (it.status) {
|
||||
Status.LOADING -> Timber.i("Loading student info $infoType started")
|
||||
Status.SUCCESS -> {
|
||||
if (it.data != null) {
|
||||
if (it.data != null && !(infoType == StudentInfoView.Type.FAMILY && it.data.firstGuardian == null && it.data.secondGuardian == null)) {
|
||||
Timber.i("Loading student info $infoType result: Success")
|
||||
showCorrectData(it.data)
|
||||
view?.run {
|
||||
@ -94,7 +94,7 @@ class StudentInfoPresenter @Inject constructor(
|
||||
}
|
||||
analytics.logEvent("load_item", "type" to "student_info")
|
||||
} else {
|
||||
Timber.i("Loading student info $infoType result: No school info found")
|
||||
Timber.i("Loading student info $infoType result: No student or family info found")
|
||||
view?.run {
|
||||
showContent(!isViewEmpty)
|
||||
showEmpty(isViewEmpty)
|
||||
@ -122,8 +122,8 @@ class StudentInfoPresenter @Inject constructor(
|
||||
StudentInfoView.Type.CONTACT -> view?.showContactTypeData(studentInfo)
|
||||
StudentInfoView.Type.ADDRESS -> view?.showAddressTypeData(studentInfo)
|
||||
StudentInfoView.Type.FAMILY -> view?.showFamilyTypeData(studentInfo)
|
||||
StudentInfoView.Type.SECOND_GUARDIAN -> view?.showSecondGuardianTypeData(studentInfo)
|
||||
StudentInfoView.Type.FIRST_GUARDIAN -> view?.showFirstGuardianTypeData(studentInfo)
|
||||
StudentInfoView.Type.SECOND_GUARDIAN -> view?.showSecondGuardianTypeData(studentInfo.secondGuardian!!)
|
||||
StudentInfoView.Type.FIRST_GUARDIAN -> view?.showFirstGuardianTypeData(studentInfo.firstGuardian!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.wulkanowy.ui.modules.studentinfo
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.StudentGuardian
|
||||
import io.github.wulkanowy.data.db.entities.StudentInfo
|
||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||
import io.github.wulkanowy.ui.base.BaseView
|
||||
@ -24,9 +25,9 @@ interface StudentInfoView : BaseView {
|
||||
|
||||
fun showFamilyTypeData(studentInfo: StudentInfo)
|
||||
|
||||
fun showFirstGuardianTypeData(studentInfo: StudentInfo)
|
||||
fun showFirstGuardianTypeData(studentGuardian: StudentGuardian)
|
||||
|
||||
fun showSecondGuardianTypeData(studentInfo: StudentInfo)
|
||||
fun showSecondGuardianTypeData(studentGuardian: StudentGuardian)
|
||||
|
||||
fun openStudentInfoView(infoType: Type, studentWithSemesters: StudentWithSemesters)
|
||||
|
||||
|
Reference in New Issue
Block a user