1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 02:29:08 -05:00

Fix preview of second student guardian when first guardian is null (#1473)

This commit is contained in:
Mikołaj Pich 2021-09-05 03:15:40 +02:00 committed by GitHub
parent 45d1727dbe
commit 3b9451184c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 57 deletions

View File

@ -13,7 +13,7 @@ class StudentInfoAdapter @Inject constructor() :
var items = listOf<StudentInfoItem>()
var onItemClickListener: (position: Int) -> Unit = {}
var onItemClickListener: (StudentInfoView.Type?) -> Unit = {}
var onItemLongClickListener: (text: String) -> Unit = {}
@ -32,7 +32,7 @@ class StudentInfoAdapter @Inject constructor() :
studentInfoItemArrow.visibility = if (item.showArrow) VISIBLE else GONE
with(root) {
setOnClickListener { onItemClickListener(position) }
setOnClickListener { onItemClickListener(item.viewType) }
setOnLongClickListener {
onItemLongClickListener(studentInfoItemSubtitle.text.toString())
true

View File

@ -1,6 +1,5 @@
package io.github.wulkanowy.ui.modules.studentinfo
import android.annotation.SuppressLint
import android.content.ClipData
import android.content.ClipboardManager
import android.os.Bundle
@ -130,9 +129,9 @@ class StudentInfoFragment :
getString(R.string.student_info_parents_name) to studentInfo.parentsNames
).map {
StudentInfoItem(
it.first,
it.second.ifBlank { getString(R.string.all_no_data) },
false,
title = it.first,
subtitle = it.second.ifBlank { getString(R.string.all_no_data) },
showArrow = false,
)
}
)
@ -146,25 +145,33 @@ class StudentInfoFragment :
getString(R.string.student_info_email) to studentInfo.email
).map {
StudentInfoItem(
it.first,
it.second.ifBlank { getString(R.string.all_no_data) },
false,
title = it.first,
subtitle = it.second.ifBlank { getString(R.string.all_no_data) },
showArrow = false,
)
}
)
}
@SuppressLint("DefaultLocale")
@OptIn(ExperimentalStdlibApi::class)
override fun showFamilyTypeData(studentInfo: StudentInfo) {
val items = buildList {
add(studentInfo.firstGuardian?.let {
Triple(it.kinship.capitalise(), it.fullName, StudentInfoView.Type.FIRST_GUARDIAN)
})
add(studentInfo.secondGuardian?.let {
Triple(it.kinship.capitalise(), it.fullName, StudentInfoView.Type.SECOND_GUARDIAN)
})
}.filterNotNull()
updateData(
listOfNotNull(
studentInfo.firstGuardian?.let { it.kinship.capitalise() to it.fullName },
studentInfo.secondGuardian?.let { it.kinship.capitalise() to it.fullName },
).map { (title, value) ->
items.map { (title, value, type) ->
StudentInfoItem(
title.ifBlank { getString(R.string.all_no_data) },
value.ifBlank { getString(R.string.all_no_data) },
true,
title = title.ifBlank { getString(R.string.all_no_data) },
subtitle = value.ifBlank { getString(R.string.all_no_data) },
showArrow = true,
viewType = type,
)
}
)
@ -178,15 +185,15 @@ class StudentInfoFragment :
getString(R.string.student_info_correspondence_address) to studentInfo.correspondenceAddress
).map {
StudentInfoItem(
it.first,
it.second.ifBlank { getString(R.string.all_no_data) },
false,
title = it.first,
subtitle = it.second.ifBlank { getString(R.string.all_no_data) },
showArrow = false,
)
}
)
}
override fun showFirstGuardianTypeData(studentGuardian: StudentGuardian) {
override fun showGuardianTypeData(studentGuardian: StudentGuardian) {
updateData(
listOf(
getString(R.string.student_info_full_name) to studentGuardian.fullName,
@ -196,27 +203,9 @@ class StudentInfoFragment :
getString(R.string.student_info_email) to studentGuardian.email
).map {
StudentInfoItem(
it.first,
it.second.ifBlank { getString(R.string.all_no_data) },
false,
)
}
)
}
override fun showSecondGuardianTypeData(studentGuardian: StudentGuardian) {
updateData(
listOf(
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 {
StudentInfoItem(
it.first,
it.second.ifBlank { getString(R.string.all_no_data) },
false,
title = it.first,
subtitle = it.second.ifBlank { getString(R.string.all_no_data) },
showArrow = false,
)
}
)

View File

@ -3,5 +3,6 @@ package io.github.wulkanowy.ui.modules.studentinfo
data class StudentInfoItem(
val title: String,
val subtitle: String,
val showArrow: Boolean
val showArrow: Boolean,
val viewType: StudentInfoView.Type? = null,
)

View File

@ -58,13 +58,12 @@ class StudentInfoPresenter @Inject constructor(
view?.showErrorDetailsDialog(lastError)
}
fun onItemSelected(position: Int) {
if (infoType != StudentInfoView.Type.FAMILY) return
fun onItemSelected(viewType: StudentInfoView.Type?) {
viewType ?: return
view?.openStudentInfoView(
if (position == 0) StudentInfoView.Type.FIRST_GUARDIAN
else StudentInfoView.Type.SECOND_GUARDIAN,
studentWithSemesters
studentWithSemesters = studentWithSemesters,
infoType = viewType,
)
}
@ -76,15 +75,19 @@ class StudentInfoPresenter @Inject constructor(
flowWithResourceIn {
val semester = studentWithSemesters.semesters.getCurrentOrLast()
studentInfoRepository.getStudentInfo(
studentWithSemesters.student,
semester,
forceRefresh
student = studentWithSemesters.student,
semester = semester,
forceRefresh = forceRefresh
)
}.onEach {
when (it.status) {
Status.LOADING -> Timber.i("Loading student info $infoType started")
Status.SUCCESS -> {
if (it.data != null && !(infoType == StudentInfoView.Type.FAMILY && it.data.firstGuardian == null && it.data.secondGuardian == null)) {
val isFamily = infoType == StudentInfoView.Type.FAMILY
val isFirstGuardianEmpty = it.data?.firstGuardian == null
val isSecondGuardianEmpty = it.data?.secondGuardian == null
if (it.data != null && !(isFamily && isFirstGuardianEmpty && isSecondGuardianEmpty)) {
Timber.i("Loading student info $infoType result: Success")
showCorrectData(it.data)
view?.run {
@ -122,8 +125,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.secondGuardian!!)
StudentInfoView.Type.FIRST_GUARDIAN -> view?.showFirstGuardianTypeData(studentInfo.firstGuardian!!)
StudentInfoView.Type.SECOND_GUARDIAN -> view?.showGuardianTypeData(studentInfo.secondGuardian!!)
StudentInfoView.Type.FIRST_GUARDIAN -> view?.showGuardianTypeData(studentInfo.firstGuardian!!)
}
}

View File

@ -25,9 +25,7 @@ interface StudentInfoView : BaseView {
fun showFamilyTypeData(studentInfo: StudentInfo)
fun showFirstGuardianTypeData(studentGuardian: StudentGuardian)
fun showSecondGuardianTypeData(studentGuardian: StudentGuardian)
fun showGuardianTypeData(studentGuardian: StudentGuardian)
fun openStudentInfoView(infoType: Type, studentWithSemesters: StudentWithSemesters)