From 981d6d559c2b153a653cb1c13e16818b5811cc1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Tue, 16 Nov 2021 22:05:00 +0100 Subject: [PATCH] Login improvements (#1645) --- .../login/advanced/LoginAdvancedFragment.kt | 2 +- .../modules/login/form/LoginFormFragment.kt | 10 ++++--- .../modules/login/form/LoginFormPresenter.kt | 8 ++++-- .../ui/modules/login/form/LoginFormView.kt | 2 ++ .../login/symbol/LoginSymbolFragment.kt | 21 ++++++++++++--- .../login/symbol/LoginSymbolPresenter.kt | 27 ++++++++++++------- .../modules/login/symbol/LoginSymbolView.kt | 2 ++ app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-sk/strings.xml | 2 +- app/src/main/res/values-uk/strings.xml | 2 +- app/src/main/res/values/strings.xml | 4 +-- 14 files changed, 62 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/advanced/LoginAdvancedFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/advanced/LoginAdvancedFragment.kt index 4a93d4ca..bc29cd14 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/advanced/LoginAdvancedFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/advanced/LoginAdvancedFragment.kt @@ -205,7 +205,7 @@ class LoginAdvancedFragment : override fun setErrorPassIncorrect(message: String?) { with(binding.loginFormPassLayout) { requestFocus() - error = message ?: getString(R.string.login_incorrect_password) + error = message ?: getString(R.string.login_incorrect_password_default) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt index 78cc6db0..c741da42 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt @@ -152,12 +152,11 @@ class LoginFormFragment : BaseFragment(R.layout.fragme } override fun setErrorPassIncorrect(message: String?) { - val error = message ?: getString(R.string.login_incorrect_password_default) - with(binding) { loginFormUsernameLayout.error = " " loginFormPassLayout.error = " " - loginFormErrorBox.text = getString(R.string.login_incorrect_password, error) + loginFormHostLayout.error = " " + loginFormErrorBox.text = message ?: getString(R.string.login_incorrect_password_default) loginFormErrorBox.isVisible = true } } @@ -178,6 +177,11 @@ class LoginFormFragment : BaseFragment(R.layout.fragme binding.loginFormErrorBox.isVisible = false } + override fun clearHostError() { + binding.loginFormHostLayout.error = null + binding.loginFormErrorBox.isVisible = false + } + override fun showSoftKeyboard() { activity?.showSoftInput() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormPresenter.kt index bd876b84..21cdf2a0 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormPresenter.kt @@ -30,7 +30,7 @@ class LoginFormPresenter @Inject constructor( showVersion() loginErrorHandler.onBadCredentials = { - setErrorPassIncorrect(it) + setErrorPassIncorrect(it.takeIf { !it.isNullOrBlank() }) showSoftKeyboard() Timber.i("Entered wrong username or password") } @@ -49,6 +49,7 @@ class LoginFormPresenter @Inject constructor( view?.apply { clearPassError() clearUsernameError() + clearHostError() if (formHostValue.contains("fakelog")) { setCredentials("jan@fakelog.cf", "jan123") } @@ -75,7 +76,10 @@ class LoginFormPresenter @Inject constructor( val usernameHost = username.substringAfter("@") hosts[usernameHost]?.let { - view?.setHost(it) + view?.run { + setHost(it) + clearHostError() + } } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormView.kt index efdaa082..30057355 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormView.kt @@ -45,6 +45,8 @@ interface LoginFormView : BaseView { fun clearPassError() + fun clearHostError() + fun showSoftKeyboard() fun hideSoftKeyboard() diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt index ae0f75a5..a8086935 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt @@ -7,6 +7,7 @@ import android.view.View.VISIBLE import android.view.inputmethod.EditorInfo.IME_ACTION_DONE import android.view.inputmethod.EditorInfo.IME_NULL import android.widget.ArrayAdapter +import androidx.core.text.parseAsHtml import androidx.core.widget.doOnTextChanged import dagger.hilt.android.AndroidEntryPoint import io.github.wulkanowy.R @@ -58,7 +59,13 @@ class LoginSymbolFragment : setOnEditorActionListener { _, id, _ -> if (id == IME_ACTION_DONE || id == IME_NULL) loginSymbolSignIn.callOnClick() else false } - setAdapter(ArrayAdapter(context, android.R.layout.simple_list_item_1, resources.getStringArray(R.array.symbols_values))) + setAdapter( + ArrayAdapter( + context, + android.R.layout.simple_list_item_1, + resources.getStringArray(R.array.symbols_values) + ) + ) } } } @@ -67,6 +74,10 @@ class LoginSymbolFragment : presenter.onParentInitSymbolView(loginData) } + override fun setLoginToHeading(login: String) { + binding.loginSymbolHeader.text = getString(R.string.login_header_symbol, login).parseAsHtml() + } + override fun setErrorSymbolIncorrect() { binding.loginSymbolNameLayout.apply { requestFocus() @@ -127,7 +138,10 @@ class LoginSymbolFragment : } override fun openFaqPage() { - context?.openInternetBrowser("https://wulkanowy.github.io/czesto-zadawane-pytania/co-to-jest-symbol", ::showMessage) + context?.openInternetBrowser( + "https://wulkanowy.github.io/czesto-zadawane-pytania/co-to-jest-symbol", + ::showMessage + ) } override fun openEmail(host: String, lastError: String) { @@ -135,7 +149,8 @@ class LoginSymbolFragment : chooserTitle = requireContext().getString(R.string.login_email_intent_title), email = "wulkanowyinc@gmail.com", subject = requireContext().getString(R.string.login_email_subject), - body = requireContext().getString(R.string.login_email_text, + body = requireContext().getString( + R.string.login_email_text, "${appInfo.systemManufacturer} ${appInfo.systemModel}", appInfo.systemVersion.toString(), appInfo.versionName, diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolPresenter.kt index 4593d880..7c84e1ec 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolPresenter.kt @@ -32,6 +32,16 @@ class LoginSymbolPresenter @Inject constructor( } if (savedLoginData is Triple<*, *, *>) { loginData = savedLoginData as Triple + view.setLoginToHeading(requireNotNull(loginData?.first)) + } + } + + fun onParentInitSymbolView(loginData: Triple) { + this.loginData = loginData + view?.apply { + setLoginToHeading(loginData.first) + clearAndFocusSymbol() + showSoftKeyboard() } } @@ -47,7 +57,14 @@ class LoginSymbolPresenter @Inject constructor( return } - flowWithResource { studentRepository.getStudentsScrapper(loginData!!.first, loginData!!.second, loginData!!.third, symbol) }.onEach { + flowWithResource { + studentRepository.getStudentsScrapper( + email = loginData!!.first, + password = loginData!!.second, + scrapperBaseUrl = loginData!!.third, + symbol = symbol, + ) + }.onEach { when (it.status) { Status.LOADING -> view?.run { Timber.i("Login with symbol started") @@ -98,14 +115,6 @@ class LoginSymbolPresenter @Inject constructor( }.launch("login") } - fun onParentInitSymbolView(loginData: Triple) { - this.loginData = loginData - view?.apply { - clearAndFocusSymbol() - showSoftKeyboard() - } - } - fun onFaqClick() { view?.openFaqPage() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolView.kt index 830c77d1..75523a7c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolView.kt @@ -9,6 +9,8 @@ interface LoginSymbolView : BaseView { fun initView() + fun setLoginToHeading(login: String) + fun setErrorSymbolIncorrect() fun setErrorSymbolRequire() diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index b48fc789..e4702028 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -30,7 +30,7 @@ Semestr %1$d, %2$d/%3$d Přihlaste se pomocí studentského nebo rodičovského účtu - Zadejte symbol ze stránky deníku + Zadejte symbol ze stránky deníku: <b>%1$s</b> Uživatelské jméno Email Přihlášení, číslo PESEL nebo e-mail diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a3e4037e..5515d921 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -30,7 +30,7 @@ Semester %1$d, %2$d/%3$d Melden Sie sich mit dem Studenten- oder Elternkonto an - Geben Sie das Symbol von der Registerseite ein + Geben Sie das Symbol von der Registerseite ein: <b>%1$s</b> Benutzername Email Anmeldung, PESEL oder e-mail diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 65bb02cb..1a035a3b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -30,7 +30,7 @@ Semestr %1$d, %2$d/%3$d Zaloguj się za pomocą konta ucznia lub rodzica - Podaj symbol ze strony dziennika + Podaj symbol ze strony dziennika dla konta: <b>%1$s</b> Nazwa użytkownika Adres e-mail Login, PESEL lub adres e-mail diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 3db5f71c..35ce0b63 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -30,7 +30,7 @@ %1$d семестр, %2$d/%3$d Авторизируйтесь при помощи аккаунта ученика или родителя - Введите символ со страницы регистрации + Введите символ со страницы регистрации: <b>%1$s</b> Имя пользователя Электронная почта Логин, PESEL или электронная почта diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 84e8c855..d6e82209 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -30,7 +30,7 @@ Semester %1$d, %2$d/%3$d Prihláste sa pomocou študentského alebo rodičovského konta - Zadajte symbol zo stránky denníka + Zadajte symbol zo stránky denníka: <b>%1$s</b> Užívateľské meno Email Prihlásenie, číslo PESEL alebo e-mail diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index fccbb06c..f4385dd3 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -30,7 +30,7 @@ %1$d семестр, %2$d/%3$d Авторизуйтеся за допомогою аккаунта учня або батьків - Введіть символ зі сторінки реєстру + Введіть символ зі сторінки реєстру: <b>%1$s</b> Ім\'я користувача Електронна пошта Логін, PESEL або електронна пошта diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00806956..6b56e077 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,7 +34,7 @@ Sign in with the student or parent account - Enter the symbol from the register page + Enter the symbol from the register page for account: <b>%1$s</b> Username Email Login, PESEL or e-mail @@ -71,7 +71,7 @@ Discord Send email Zgłoszenie: Problemy z logowaniem - Informacje o aplikacji:\n\nUrządzenie: %1$s\nWersja SDK: %2$s\nWersja aplikacji: %3$s\nDodatkowe informacje: %4$s\nOstatni błąd: %5$s\n\nOpis problemu (pełna nazwa szkoły, klasa ucznia): + Informacje o aplikacji:\n\nUrządzenie: %1$s\nWersja SDK: %2$s\nWersja aplikacji: %3$s\nDodatkowe informacje: %4$s\nOstatni błąd: %5$s\n\nPełna nazwa szkoły i klasa ucznia: Make sure you select the correct UONET+ register variation! I forgot my password Recover your account