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