forked from github/wulkanowy-mirror
Show invalid symbol message when nonexistent symbol entered (#2143)
This commit is contained in:
parent
ef398f7409
commit
ee5ac46493
@ -12,6 +12,7 @@ import io.github.wulkanowy.data.pojos.RegisterUser
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.resourceFlow
|
||||
import io.github.wulkanowy.sdk.scrapper.login.AccountPermissionException
|
||||
import io.github.wulkanowy.sdk.scrapper.login.InvalidSymbolException
|
||||
import io.github.wulkanowy.services.sync.SyncManager
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.modules.login.LoginData
|
||||
@ -158,7 +159,7 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
isNotEmptySymbolsExist: Boolean,
|
||||
) = buildList {
|
||||
val filteredEmptySymbols = emptySymbols.filter {
|
||||
it.error !is AccountPermissionException
|
||||
it.error !is InvalidSymbolException
|
||||
}.ifEmpty { emptySymbols.takeIf { !isNotEmptySymbolsExist }.orEmpty() }
|
||||
|
||||
if (filteredEmptySymbols.isNotEmpty() && isNotEmptySymbolsExist) {
|
||||
@ -281,7 +282,7 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
private fun onEmailClick() {
|
||||
view?.openEmail(lastError?.message.ifNullOrBlank {
|
||||
loginData.baseUrl + "/" + loginData.symbol + "\n" + registerUser.symbols.filterNot {
|
||||
it.error is AccountPermissionException && it.symbol != loginData.symbol
|
||||
(it.error is AccountPermissionException || it.error is InvalidSymbolException) && it.symbol != loginData.symbol
|
||||
}.joinToString(";\n") { symbol ->
|
||||
buildString {
|
||||
append(" -")
|
||||
@ -297,7 +298,9 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} + "\nPozostałe: " + registerUser.symbols.filter {
|
||||
it.error is AccountPermissionException || it.error is InvalidSymbolException
|
||||
}.joinToString(", ") { it.symbol }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,13 @@ class LoginSymbolFragment :
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorSymbolInvalid() {
|
||||
with(binding.loginSymbolNameLayout) {
|
||||
requestFocus()
|
||||
error = getString(R.string.login_invalid_symbol)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorSymbolRequire() {
|
||||
setErrorSymbol(getString(R.string.error_field_required))
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import io.github.wulkanowy.data.pojos.RegisterUser
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.resourceFlow
|
||||
import io.github.wulkanowy.sdk.scrapper.getNormalizedSymbol
|
||||
import io.github.wulkanowy.sdk.scrapper.login.InvalidSymbolException
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.modules.login.LoginData
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
@ -61,11 +62,11 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
email = loginData.login,
|
||||
password = loginData.password,
|
||||
scrapperBaseUrl = loginData.baseUrl,
|
||||
symbol = view?.symbolValue.orEmpty(),
|
||||
symbol = loginData.symbol.orEmpty(),
|
||||
)
|
||||
}.onEach {
|
||||
registerUser = it.dataOrNull
|
||||
when (it) {
|
||||
}.onEach { user ->
|
||||
registerUser = user.dataOrNull
|
||||
when (user) {
|
||||
is Resource.Loading -> view?.run {
|
||||
Timber.i("Login with symbol started")
|
||||
hideSoftKeyboard()
|
||||
@ -73,7 +74,7 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
showContent(false)
|
||||
}
|
||||
is Resource.Success -> {
|
||||
when (it.data.symbols.size) {
|
||||
when (user.data.symbols.size) {
|
||||
0 -> {
|
||||
Timber.i("Login with symbol result: Empty student list")
|
||||
view?.run {
|
||||
@ -82,8 +83,19 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Timber.i("Login with symbol result: Success")
|
||||
view?.navigateToStudentSelect(loginData, requireNotNull(it.data))
|
||||
val enteredSymbolDetails = user.data.symbols
|
||||
.firstOrNull()
|
||||
?.takeIf { it.symbol == loginData.symbol }
|
||||
|
||||
if (enteredSymbolDetails?.error is InvalidSymbolException) {
|
||||
view?.run {
|
||||
setErrorSymbolInvalid()
|
||||
showContact(true)
|
||||
}
|
||||
} else {
|
||||
Timber.i("Login with symbol result: Success")
|
||||
view?.navigateToStudentSelect(loginData, requireNotNull(user.data))
|
||||
}
|
||||
}
|
||||
}
|
||||
analytics.logEvent(
|
||||
@ -102,10 +114,10 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
"students" to -1,
|
||||
"scrapperBaseUrl" to loginData.baseUrl,
|
||||
"symbol" to view?.symbolValue,
|
||||
"error" to it.error.message.ifNullOrBlank { "No message" }
|
||||
"error" to user.error.message.ifNullOrBlank { "No message" }
|
||||
)
|
||||
loginErrorHandler.dispatch(it.error)
|
||||
lastError = it.error
|
||||
loginErrorHandler.dispatch(user.error)
|
||||
lastError = user.error
|
||||
view?.showContact(true)
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ interface LoginSymbolView : BaseView {
|
||||
|
||||
fun setErrorSymbolIncorrect()
|
||||
|
||||
fun setErrorSymbolInvalid()
|
||||
|
||||
fun setErrorSymbolRequire()
|
||||
|
||||
fun setErrorSymbol(message: String)
|
||||
|
Loading…
x
Reference in New Issue
Block a user