From 67cef0f6d9062129bfd3410f051c29c21a846001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 6 Dec 2020 21:23:02 +0100 Subject: [PATCH] Add register variant auto-matching based on email (#1041) --- app/build.gradle | 2 +- .../repositories/timetable/TimetableRemote.kt | 2 +- .../modules/login/form/LoginFormFragment.kt | 8 ++++++ .../modules/login/form/LoginFormPresenter.kt | 17 +++++++++--- .../ui/modules/login/form/LoginFormView.kt | 4 +++ app/src/main/res/values/api_hosts.xml | 26 +++++++++---------- .../timetable/TimetableRemoteTest.kt | 4 +-- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c85af3c7..8dde9e7c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -142,7 +142,7 @@ configurations.all { } dependencies { - implementation "io.github.wulkanowy:sdk:bcf6b53" + implementation "io.github.wulkanowy:sdk:50c049ef" coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1' diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt index eef8729e..9fb80e77 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt @@ -14,7 +14,7 @@ class TimetableRemote @Inject constructor(private val sdk: Sdk) { suspend fun getTimetable(student: Student, semester: Semester, startDate: LocalDate, endDate: LocalDate): List { return sdk.init(student).switchDiary(semester.diaryId, semester.schoolYear) - .getTimetable(startDate, endDate) + .getTimetable(startDate, endDate).first .map { Timetable( studentId = semester.studentId, 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 41345686..c6d0209d 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 @@ -89,6 +89,8 @@ class LoginFormFragment : BaseFragment(R.layout.fragme } } + override fun getHostsValues(): List = hostValues.toList() + override fun setCredentials(username: String, pass: String) { with(binding) { loginFormUsername.setText(username) @@ -96,6 +98,12 @@ class LoginFormFragment : BaseFragment(R.layout.fragme } } + override fun setHost(host: String) { + binding.loginFormHost.setText( + hostKeys.getOrNull(hostValues.indexOf(host)).orEmpty() + ) + } + override fun setUsernameLabel(label: String) { binding.loginFormUsernameLayout.hint = label } 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 3e77cd77..35c79bb5 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 @@ -1,5 +1,6 @@ package io.github.wulkanowy.ui.modules.login.form +import androidx.core.net.toUri import io.github.wulkanowy.data.Status import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.ui.base.BasePresenter @@ -56,7 +57,7 @@ class LoginFormPresenter @Inject constructor( fun updateUsernameLabel() { view?.run { - setUsernameLabel(if ("standard" in formHostValue) emailLabel else nicknameLabel) + setUsernameLabel(if ("login" in formHostValue) nicknameLabel else emailLabel) } } @@ -66,6 +67,16 @@ class LoginFormPresenter @Inject constructor( fun onUsernameTextChanged() { view?.clearUsernameError() + + val username = view?.formUsernameValue.orEmpty().trim() + if ("@" in username && "@vulcan" !in username) { + val hosts = view?.getHostsValues().orEmpty().map { it.toUri().host to it }.toMap() + val usernameHost = username.substringAfter("@") + + hosts[usernameHost]?.let { + view?.setHost(it) + } + } } fun onSignInClick() { @@ -135,12 +146,12 @@ class LoginFormPresenter @Inject constructor( view?.setErrorUsernameRequired() isCorrect = false } else { - if ("@" in login && "standard" !in host) { + if ("@" in login && "login" in host) { view?.setErrorLoginRequired() isCorrect = false } - if ("@" !in login && "standard" in host) { + if ("@" !in login && "email" in host) { view?.setErrorEmailRequired() isCorrect = false } 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 77e66538..31f8a621 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 @@ -19,8 +19,12 @@ interface LoginFormView : BaseView { val emailLabel: String + fun getHostsValues(): List + fun setCredentials(username: String, pass: String) + fun setHost(host: String) + fun setUsernameLabel(label: String) fun setErrorUsernameRequired() diff --git a/app/src/main/res/values/api_hosts.xml b/app/src/main/res/values/api_hosts.xml index 29434602..0a43612d 100644 --- a/app/src/main/res/values/api_hosts.xml +++ b/app/src/main/res/values/api_hosts.xml @@ -22,25 +22,25 @@ Fakelog - https://vulcan.net.pl/?standard + https://vulcan.net.pl/?email https://eszkola.opolskie.pl https://edu.gdansk.pl https://edu.lublin.eu https://umt.tarnow.pl https://resman.pl https://eduportal.koszalin.pl - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - https://vulcan.net.pl/ - http://fakelog.tk/?standard + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + https://vulcan.net.pl/?login + http://fakelog.cf/?email Default diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt index c948ba31..a333e0d7 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt @@ -39,10 +39,10 @@ class TimetableRemoteTest { of(2018, 9, 10), of(2018, 9, 15) ) - } returns listOf( + } returns (listOf( getTimetable(of(2018, 9, 10)), getTimetable(of(2018, 9, 17)) - ) + ) to emptyList()) every { semesterMock.studentId } returns 1 every { semesterMock.diaryId } returns 1