Fix login process after was interrupted (#1505)

This commit is contained in:
Rafał Borcz
2021-09-13 14:36:31 +02:00
committed by GitHub
parent 19c96ee83f
commit 827fb33eeb
6 changed files with 76 additions and 76 deletions

View File

@ -90,10 +90,10 @@ class LoginFormPresenter @Inject constructor(
flowWithResource {
studentRepository.getStudentsScrapper(
email,
password,
host,
symbol
email = email,
password = password,
scrapperBaseUrl = host,
symbol = symbol
)
}.onEach {
when (it.status) {

View File

@ -78,7 +78,9 @@ class LoginStudentSelectPresenter @Inject constructor(
when (it.status) {
Status.LOADING -> Timber.d("Login student select students load started")
Status.SUCCESS -> view?.updateData(studentsWithSemesters.map { studentWithSemesters ->
studentWithSemesters to it.data!!.any { item -> compareStudents(studentWithSemesters.student, item.student) }
studentWithSemesters to it.data!!.any { item ->
compareStudents(studentWithSemesters.student, item.student)
}
})
Status.ERROR -> {
errorHandler.dispatch(it.error!!)
@ -95,35 +97,32 @@ class LoginStudentSelectPresenter @Inject constructor(
}
private fun registerStudents(studentsWithSemesters: List<StudentWithSemesters>) {
flowWithResource {
val savedStudents = studentRepository.saveStudents(studentsWithSemesters)
val firstRegistered = studentsWithSemesters.first().apply { student.id = savedStudents.first() }
studentRepository.switchStudent(firstRegistered)
}.onEach {
when (it.status) {
Status.LOADING -> view?.run {
Timber.i("Registration started")
showProgress(true)
showContent(false)
}
Status.SUCCESS -> {
Timber.i("Registration result: Success")
view?.openMainView()
logRegisterEvent(studentsWithSemesters)
}
Status.ERROR -> {
Timber.i("Registration result: An exception occurred ")
view?.apply {
showProgress(false)
showContent(true)
showContact(true)
flowWithResource { studentRepository.saveStudents(studentsWithSemesters) }
.onEach {
when (it.status) {
Status.LOADING -> view?.run {
Timber.i("Registration started")
showProgress(true)
showContent(false)
}
Status.SUCCESS -> {
Timber.i("Registration result: Success")
view?.openMainView()
logRegisterEvent(studentsWithSemesters)
}
Status.ERROR -> {
Timber.i("Registration result: An exception occurred ")
view?.apply {
showProgress(false)
showContent(true)
showContact(true)
}
lastError = it.error
loginErrorHandler.dispatch(it.error!!)
logRegisterEvent(studentsWithSemesters, it.error)
}
lastError = it.error
loginErrorHandler.dispatch(it.error!!)
logRegisterEvent(studentsWithSemesters, it.error)
}
}
}.launch("register")
}.launch("register")
}
fun onDiscordClick() {
@ -134,7 +133,10 @@ class LoginStudentSelectPresenter @Inject constructor(
view?.openEmail(lastError?.message.ifNullOrBlank { "empty" })
}
private fun logRegisterEvent(studentsWithSemesters: List<StudentWithSemesters>, error: Throwable? = null) {
private fun logRegisterEvent(
studentsWithSemesters: List<StudentWithSemesters>,
error: Throwable? = null
) {
studentsWithSemesters.forEach { student ->
analytics.logEvent(
"registration_student_select",