1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-26 04:54:41 -06:00

Fix nullable student guardians (#1128)

This commit is contained in:
Rafał Borcz 2021-02-06 16:19:50 +01:00 committed by GitHub
parent 87facd2663
commit 23411a608f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 2231 additions and 33 deletions

View File

@ -142,7 +142,7 @@ ext {
}
dependencies {
implementation "io.github.wulkanowy:sdk:0.25.0"
implementation "io.github.wulkanowy:sdk:31fa6d26"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'

File diff suppressed because it is too large Load Diff

View File

@ -84,6 +84,7 @@ import io.github.wulkanowy.data.db.migrations.Migration3
import io.github.wulkanowy.data.db.migrations.Migration30
import io.github.wulkanowy.data.db.migrations.Migration31
import io.github.wulkanowy.data.db.migrations.Migration32
import io.github.wulkanowy.data.db.migrations.Migration33
import io.github.wulkanowy.data.db.migrations.Migration4
import io.github.wulkanowy.data.db.migrations.Migration5
import io.github.wulkanowy.data.db.migrations.Migration6
@ -129,7 +130,7 @@ import javax.inject.Singleton
abstract class AppDatabase : RoomDatabase() {
companion object {
const val VERSION_SCHEMA = 32
const val VERSION_SCHEMA = 33
fun getMigrations(sharedPrefProvider: SharedPrefProvider): Array<Migration> {
return arrayOf(
@ -163,7 +164,8 @@ abstract class AppDatabase : RoomDatabase() {
Migration29(),
Migration30(),
Migration31(),
Migration32()
Migration32(),
Migration33()
)
}

View File

@ -59,10 +59,10 @@ data class StudentInfo(
val email: String,
@Embedded(prefix = "first_guardian_")
val firstGuardian: StudentGuardian,
val firstGuardian: StudentGuardian?,
@Embedded(prefix = "second_guardian_")
val secondGuardian: StudentGuardian
val secondGuardian: StudentGuardian?
) : Serializable {

View File

@ -0,0 +1,45 @@
package io.github.wulkanowy.data.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
class Migration33 : Migration(32, 33) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("DROP TABLE IF EXISTS StudentInfo")
database.execSQL(
"""CREATE TABLE IF NOT EXISTS StudentInfo (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
student_id INTEGER NOT NULL,
full_name TEXT NOT NULL,
first_name TEXT NOT NULL,
second_name TEXT NOT NULL,
surname TEXT NOT NULL,
birth_date INTEGER NOT NULL,
birth_place TEXT NOT NULL,
gender TEXT NOT NULL,
has_polish_citizenship INTEGER NOT NULL,
family_name TEXT NOT NULL,
parents_names TEXT NOT NULL,
address TEXT NOT NULL,
registered_address TEXT NOT NULL,
correspondence_address TEXT NOT NULL,
phone_number TEXT NOT NULL,
cell_phone_number TEXT NOT NULL,
email TEXT NOT NULL,
first_guardian_full_name TEXT,
first_guardian_kinship TEXT,
first_guardian_address TEXT,
first_guardian_phones TEXT,
first_guardian_email TEXT,
second_guardian_full_name TEXT,
second_guardian_kinship TEXT,
second_guardian_address TEXT,
second_guardian_phones TEXT,
second_guardian_email TEXT)
"""
)
}
}

View File

@ -25,8 +25,8 @@ fun SdkStudentInfo.mapToEntity(semester: Semester) = StudentInfo(
phoneNumber = phoneNumber,
cellPhoneNumber = phoneNumber,
email = email,
firstGuardian = guardians[0].mapToEntity(),
secondGuardian = guardians[1].mapToEntity()
firstGuardian = guardianFirst?.mapToEntity(),
secondGuardian = guardianSecond?.mapToEntity()
)
fun SdkStudentGuardian.mapToEntity() = StudentGuardian(

View File

@ -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
}

View File

@ -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!!)
}
}

View File

@ -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)

View File

@ -36,7 +36,7 @@
android:padding="10dp"
android:visibility="gone"
tools:ignore="UseCompoundDrawables"
tools:visibility="gone">
tools:visibility="visible">
<ImageView
android:layout_width="100dp"

View File

@ -393,7 +393,7 @@
<!--Student info-->
<string name="student_info_empty">No info about student</string>
<string name="student_info_empty">No info about student or student family</string>
<string name="student_info_first_name">Name</string>
<string name="student_info_second_name">Second name</string>
<string name="student_info_gender">Gender</string>