1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-23 18:56:11 -06: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 items = listOf<StudentInfoItem>()
var onItemClickListener: (position: Int) -> Unit = {} var onItemClickListener: (StudentInfoView.Type?) -> Unit = {}
var onItemLongClickListener: (text: String) -> Unit = {} var onItemLongClickListener: (text: String) -> Unit = {}
@ -32,7 +32,7 @@ class StudentInfoAdapter @Inject constructor() :
studentInfoItemArrow.visibility = if (item.showArrow) VISIBLE else GONE studentInfoItemArrow.visibility = if (item.showArrow) VISIBLE else GONE
with(root) { with(root) {
setOnClickListener { onItemClickListener(position) } setOnClickListener { onItemClickListener(item.viewType) }
setOnLongClickListener { setOnLongClickListener {
onItemLongClickListener(studentInfoItemSubtitle.text.toString()) onItemLongClickListener(studentInfoItemSubtitle.text.toString())
true true

View File

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

View File

@ -3,5 +3,6 @@ package io.github.wulkanowy.ui.modules.studentinfo
data class StudentInfoItem( data class StudentInfoItem(
val title: String, val title: String,
val subtitle: 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) view?.showErrorDetailsDialog(lastError)
} }
fun onItemSelected(position: Int) { fun onItemSelected(viewType: StudentInfoView.Type?) {
if (infoType != StudentInfoView.Type.FAMILY) return viewType ?: return
view?.openStudentInfoView( view?.openStudentInfoView(
if (position == 0) StudentInfoView.Type.FIRST_GUARDIAN studentWithSemesters = studentWithSemesters,
else StudentInfoView.Type.SECOND_GUARDIAN, infoType = viewType,
studentWithSemesters
) )
} }
@ -76,15 +75,19 @@ class StudentInfoPresenter @Inject constructor(
flowWithResourceIn { flowWithResourceIn {
val semester = studentWithSemesters.semesters.getCurrentOrLast() val semester = studentWithSemesters.semesters.getCurrentOrLast()
studentInfoRepository.getStudentInfo( studentInfoRepository.getStudentInfo(
studentWithSemesters.student, student = studentWithSemesters.student,
semester, semester = semester,
forceRefresh forceRefresh = forceRefresh
) )
}.onEach { }.onEach {
when (it.status) { when (it.status) {
Status.LOADING -> Timber.i("Loading student info $infoType started") Status.LOADING -> Timber.i("Loading student info $infoType started")
Status.SUCCESS -> { 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") Timber.i("Loading student info $infoType result: Success")
showCorrectData(it.data) showCorrectData(it.data)
view?.run { view?.run {
@ -122,8 +125,8 @@ class StudentInfoPresenter @Inject constructor(
StudentInfoView.Type.CONTACT -> view?.showContactTypeData(studentInfo) StudentInfoView.Type.CONTACT -> view?.showContactTypeData(studentInfo)
StudentInfoView.Type.ADDRESS -> view?.showAddressTypeData(studentInfo) StudentInfoView.Type.ADDRESS -> view?.showAddressTypeData(studentInfo)
StudentInfoView.Type.FAMILY -> view?.showFamilyTypeData(studentInfo) StudentInfoView.Type.FAMILY -> view?.showFamilyTypeData(studentInfo)
StudentInfoView.Type.SECOND_GUARDIAN -> view?.showSecondGuardianTypeData(studentInfo.secondGuardian!!) StudentInfoView.Type.SECOND_GUARDIAN -> view?.showGuardianTypeData(studentInfo.secondGuardian!!)
StudentInfoView.Type.FIRST_GUARDIAN -> view?.showFirstGuardianTypeData(studentInfo.firstGuardian!!) StudentInfoView.Type.FIRST_GUARDIAN -> view?.showGuardianTypeData(studentInfo.firstGuardian!!)
} }
} }

View File

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