Commit 647b7dd3 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Check for server accounts information before showing the login options view.

This also will show the login with username/email + password with there is only this method enabled by the server.
parent e89bc7cc
...@@ -15,11 +15,13 @@ import chat.rocket.android.analytics.AnalyticsManager ...@@ -15,11 +15,13 @@ import chat.rocket.android.analytics.AnalyticsManager
import chat.rocket.android.analytics.event.ScreenViewEvent import chat.rocket.android.analytics.event.ScreenViewEvent
import chat.rocket.android.authentication.login.presentation.LoginPresenter import chat.rocket.android.authentication.login.presentation.LoginPresenter
import chat.rocket.android.authentication.login.presentation.LoginView import chat.rocket.android.authentication.login.presentation.LoginView
import chat.rocket.android.authentication.ui.AuthenticationActivity
import chat.rocket.android.helper.getCredentials import chat.rocket.android.helper.getCredentials
import chat.rocket.android.helper.hasCredentialsSupport import chat.rocket.android.helper.hasCredentialsSupport
import chat.rocket.android.helper.requestStoredCredentials import chat.rocket.android.helper.requestStoredCredentials
import chat.rocket.android.helper.saveCredentials import chat.rocket.android.helper.saveCredentials
import chat.rocket.android.util.extension.asObservable import chat.rocket.android.util.extension.asObservable
import chat.rocket.android.util.extensions.clearLightStatusBar
import chat.rocket.android.util.extensions.inflate import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
...@@ -27,25 +29,40 @@ import chat.rocket.android.util.extensions.ui ...@@ -27,25 +29,40 @@ import chat.rocket.android.util.extensions.ui
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Observables import io.reactivex.rxkotlin.Observables
import kotlinx.android.synthetic.main.app_bar.*
import kotlinx.android.synthetic.main.fragment_authentication_log_in.* import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import javax.inject.Inject import javax.inject.Inject
private const val SERVER_NAME = "server_name"
internal const val REQUEST_CODE_FOR_SIGN_IN_REQUIRED = 1 internal const val REQUEST_CODE_FOR_SIGN_IN_REQUIRED = 1
internal const val REQUEST_CODE_FOR_MULTIPLE_ACCOUNTS_RESOLUTION = 2 internal const val REQUEST_CODE_FOR_MULTIPLE_ACCOUNTS_RESOLUTION = 2
internal const val REQUEST_CODE_FOR_SAVE_RESOLUTION = 3 internal const val REQUEST_CODE_FOR_SAVE_RESOLUTION = 3
fun newInstance() = LoginFragment() fun newInstance(serverName: String): Fragment {
return LoginFragment().apply {
arguments = Bundle(1).apply {
putString(SERVER_NAME, serverName)
}
}
}
class LoginFragment : Fragment(), LoginView { class LoginFragment : Fragment(), LoginView {
@Inject @Inject
lateinit var presenter: LoginPresenter lateinit var presenter: LoginPresenter
@Inject @Inject
lateinit var analyticsManager: AnalyticsManager lateinit var analyticsManager: AnalyticsManager
private var serverName: String? = null
private val editTextsDisposable = CompositeDisposable() private val editTextsDisposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
val bundle = arguments
if (bundle != null) {
serverName = bundle.getString(SERVER_NAME)
}
} }
override fun onCreateView( override fun onCreateView(
...@@ -56,11 +73,10 @@ class LoginFragment : Fragment(), LoginView { ...@@ -56,11 +73,10 @@ class LoginFragment : Fragment(), LoginView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setupToolbar()
presenter.setupView() presenter.setupView()
subscribeEditTexts() subscribeEditTexts()
setupOnClickListener() setupOnClickListener()
analyticsManager.logScreenView(ScreenViewEvent.Login) analyticsManager.logScreenView(ScreenViewEvent.Login)
} }
...@@ -95,6 +111,15 @@ class LoginFragment : Fragment(), LoginView { ...@@ -95,6 +111,15 @@ class LoginFragment : Fragment(), LoginView {
unsubscribeEditTexts() unsubscribeEditTexts()
} }
private fun setupToolbar() {
with(activity as AuthenticationActivity) {
this.clearLightStatusBar()
toolbar.isVisible = true
toolbar.title = serverName?.replace(getString(R.string.default_protocol), "")
}
}
override fun showLoading() { override fun showLoading() {
ui { ui {
disableUserInput() disableUserInput()
......
package chat.rocket.android.authentication.onboarding.presentation package chat.rocket.android.authentication.onboarding.presentation
import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.behaviours.showMessage import chat.rocket.android.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetAccountsInteractor import chat.rocket.android.server.domain.GetAccountsInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.RefreshSettingsInteractor import chat.rocket.android.server.domain.RefreshSettingsInteractor
import chat.rocket.android.server.domain.SaveConnectingServerInteractor import chat.rocket.android.server.domain.SaveConnectingServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.server.presentation.CheckServerPresenter
import chat.rocket.android.util.extension.launchUI import chat.rocket.android.util.extension.launchUI
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.withContext
import javax.inject.Inject import javax.inject.Inject
class OnBoardingPresenter @Inject constructor( class OnBoardingPresenter @Inject constructor(
...@@ -16,31 +20,71 @@ class OnBoardingPresenter @Inject constructor( ...@@ -16,31 +20,71 @@ class OnBoardingPresenter @Inject constructor(
private val navigator: AuthenticationNavigator, private val navigator: AuthenticationNavigator,
private val serverInteractor: SaveConnectingServerInteractor, private val serverInteractor: SaveConnectingServerInteractor,
private val refreshSettingsInteractor: RefreshSettingsInteractor, private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val getAccountsInteractor: GetAccountsInteractor private val getAccountsInteractor: GetAccountsInteractor,
) { val settingsInteractor: GetSettingsInteractor,
val factory: RocketChatClientFactory
) : CheckServerPresenter(strategy, factory, settingsInteractor) {
fun toConnectWithAServer(deepLinkInfo: LoginDeepLinkInfo?) = fun toSignInToYourServer() = navigator.toSignInToYourServer()
navigator.toConnectWithAServer(deepLinkInfo)
fun connectToCommunityServer(communityServer: String) = fun connectToCommunityServer(communityServerUrl: String) {
connectToServer(communityServer) { navigator.toLoginOptions(communityServer) } connectToServer(communityServerUrl) {
if (totalSocialAccountsEnabled == 0 && !isNewAccountCreationEnabled) {
navigator.toLogin(communityServerUrl)
} else {
navigator.toLoginOptions(
communityServerUrl,
state,
facebookOauthUrl,
githubOauthUrl,
googleOauthUrl,
linkedinOauthUrl,
gitlabOauthUrl,
wordpressOauthUrl,
casLoginUrl,
casToken,
customOauthUrl,
customOauthServiceName,
customOauthServiceNameTextColor,
customOauthServiceButtonColor,
samlUrl,
samlToken,
samlServiceName,
samlServiceNameTextColor,
samlServiceButtonColor,
totalSocialAccountsEnabled,
isLoginFormEnabled,
isNewAccountCreationEnabled
)
}
}
}
fun toCreateANewServer(createServerUrl: String) = navigator.toWebPage(createServerUrl) fun toCreateANewServer(createServerUrl: String) = navigator.toWebPage(createServerUrl)
private fun connectToServer(server: String, block: () -> Unit) { private fun connectToServer(serverUrl: String, block: () -> Unit) {
launchUI(strategy) { launchUI(strategy) {
// Check if we already have an account for this server... // Check if we already have an account for this server...
val account = getAccountsInteractor.get().firstOrNull { it.serverUrl == server } val account = getAccountsInteractor.get().firstOrNull { it.serverUrl == serverUrl }
if (account != null) { if (account != null) {
navigator.toChatList(server) navigator.toChatList(serverUrl)
return@launchUI return@launchUI
} }
view.showLoading() view.showLoading()
try { try {
refreshSettingsInteractor.refresh(server) withContext(DefaultDispatcher) {
serverInteractor.save(server) setupConnectionInfo(serverUrl)
// preparing next fragment before showing it
checkEnabledAccounts(serverUrl)
checkIfLoginFormIsEnabled()
checkIfCreateNewAccountIsEnabled()
refreshSettingsInteractor.refresh(serverUrl)
serverInteractor.save(serverUrl)
block() block()
}
} catch (ex: Exception) { } catch (ex: Exception) {
view.showMessage(ex) view.showMessage(ex)
} finally { } finally {
......
...@@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment ...@@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager import chat.rocket.android.analytics.AnalyticsManager
import chat.rocket.android.analytics.event.ScreenViewEvent import chat.rocket.android.analytics.event.ScreenViewEvent
import chat.rocket.android.authentication.domain.model.getLoginDeepLinkInfo
import chat.rocket.android.authentication.onboarding.presentation.OnBoardingPresenter import chat.rocket.android.authentication.onboarding.presentation.OnBoardingPresenter
import chat.rocket.android.authentication.onboarding.presentation.OnBoardingView import chat.rocket.android.authentication.onboarding.presentation.OnBoardingView
import chat.rocket.android.authentication.ui.AuthenticationActivity import chat.rocket.android.authentication.ui.AuthenticationActivity
...@@ -42,13 +41,12 @@ class OnBoardingFragment : Fragment(), OnBoardingView { ...@@ -42,13 +41,12 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setupToobar() setupToolbar()
setupOnClickListener() setupOnClickListener()
analyticsManager.logScreenView(ScreenViewEvent.OnBoarding) analyticsManager.logScreenView(ScreenViewEvent.OnBoarding)
} }
private fun setupToobar() { private fun setupToolbar() {
with(activity as AuthenticationActivity) { with(activity as AuthenticationActivity) {
view?.let { this.setLightStatusBar(it) } view?.let { this.setLightStatusBar(it) }
toolbar.isVisible = false toolbar.isVisible = false
...@@ -56,7 +54,7 @@ class OnBoardingFragment : Fragment(), OnBoardingView { ...@@ -56,7 +54,7 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
} }
private fun setupOnClickListener() { private fun setupOnClickListener() {
connect_with_a_server_container.setOnClickListener { connectWithAServer() } connect_with_a_server_container.setOnClickListener { signInToYourServer() }
join_community_container.setOnClickListener { joinInTheCommunity() } join_community_container.setOnClickListener { joinInTheCommunity() }
create_server_container.setOnClickListener { createANewServer() } create_server_container.setOnClickListener { createANewServer() }
} }
...@@ -87,21 +85,19 @@ class OnBoardingFragment : Fragment(), OnBoardingView { ...@@ -87,21 +85,19 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error)) override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
private fun connectWithAServer() = ui { private fun signInToYourServer() = ui {
presenter.toConnectWithAServer(activity?.intent?.getLoginDeepLinkInfo()) presenter.toSignInToYourServer()
} }
private fun joinInTheCommunity() = ui { private fun joinInTheCommunity() = ui {
presenter.connectToCommunityServer( presenter.connectToCommunityServer(
getString(R.string.default_protocol) + getString(R.string.default_protocol) + getString(R.string.community_server_url)
getString(R.string.community_server_url)
) )
} }
private fun createANewServer() = ui { private fun createANewServer() = ui {
presenter.toCreateANewServer( presenter.toCreateANewServer(
getString(R.string.default_protocol) + getString(R.string.default_protocol) + getString(R.string.create_server_url)
getString(R.string.create_server_url)
) )
} }
} }
...@@ -13,18 +13,66 @@ import chat.rocket.android.webview.ui.webViewIntent ...@@ -13,18 +13,66 @@ import chat.rocket.android.webview.ui.webViewIntent
class AuthenticationNavigator(internal val activity: AuthenticationActivity) { class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
fun toConnectWithAServer(deepLinkInfo: LoginDeepLinkInfo?) { fun toSignInToYourServer() {
activity.addFragmentBackStack(ScreenViewEvent.Server.screenName, R.id.fragment_container) { activity.addFragmentBackStack(ScreenViewEvent.Server.screenName, R.id.fragment_container) {
chat.rocket.android.authentication.server.ui.newInstance(deepLinkInfo) chat.rocket.android.authentication.server.ui.newInstance()
} }
} }
fun toLoginOptions(server: String, deepLinkInfo: LoginDeepLinkInfo? = null) { fun toLoginOptions(
serverUrl: String,
state: String? = null,
facebookOauthUrl: String? = null,
githubOauthUrl: String? = null,
googleOauthUrl: String? = null,
linkedinOauthUrl: String? = null,
gitlabOauthUrl: String? = null,
wordpressOauthUrl: String? = null,
casLoginUrl: String? = null,
casToken: String? = null,
customOauthUrl: String? = null,
customOauthServiceName: String? = null,
customOauthServiceNameTextColor: Int = 0,
customOauthServiceButtonColor: Int = 0,
samlUrl: String? = null,
samlToken: String? = null,
samlServiceName: String? = null,
samlServiceNameTextColor: Int = 0,
samlServiceButtonColor: Int = 0,
totalSocialAccountsEnabled: Int = 0,
isLoginFormEnabled: Boolean = true,
isNewAccountCreationEnabled: Boolean = true,
deepLinkInfo: LoginDeepLinkInfo? = null
) {
activity.addFragmentBackStack( activity.addFragmentBackStack(
ScreenViewEvent.LoginOptions.screenName, ScreenViewEvent.LoginOptions.screenName,
R.id.fragment_container R.id.fragment_container
) { ) {
chat.rocket.android.authentication.loginoptions.ui.newInstance(server, deepLinkInfo) chat.rocket.android.authentication.loginoptions.ui.newInstance(
serverUrl,
state,
facebookOauthUrl,
githubOauthUrl,
googleOauthUrl,
linkedinOauthUrl,
gitlabOauthUrl,
wordpressOauthUrl,
casLoginUrl,
casToken,
customOauthUrl,
customOauthServiceName,
customOauthServiceNameTextColor,
customOauthServiceButtonColor,
samlUrl,
samlToken,
samlServiceName,
samlServiceNameTextColor,
samlServiceButtonColor,
totalSocialAccountsEnabled,
isLoginFormEnabled,
isNewAccountCreationEnabled,
deepLinkInfo
)
} }
} }
...@@ -40,9 +88,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) { ...@@ -40,9 +88,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
} }
} }
fun toLogin() { fun toLogin(serverUrl: String) {
activity.addFragmentBackStack(ScreenViewEvent.Login.screenName, R.id.fragment_container) { activity.addFragmentBackStack(ScreenViewEvent.Login.screenName, R.id.fragment_container) {
chat.rocket.android.authentication.login.ui.newInstance() chat.rocket.android.authentication.login.ui.newInstance(serverUrl)
} }
} }
......
...@@ -5,6 +5,7 @@ import chat.rocket.android.authentication.presentation.AuthenticationNavigator ...@@ -5,6 +5,7 @@ import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.behaviours.showMessage import chat.rocket.android.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetAccountsInteractor import chat.rocket.android.server.domain.GetAccountsInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.RefreshSettingsInteractor import chat.rocket.android.server.domain.RefreshSettingsInteractor
import chat.rocket.android.server.domain.SaveConnectingServerInteractor import chat.rocket.android.server.domain.SaveConnectingServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
...@@ -20,20 +21,57 @@ class ServerPresenter @Inject constructor( ...@@ -20,20 +21,57 @@ class ServerPresenter @Inject constructor(
private val serverInteractor: SaveConnectingServerInteractor, private val serverInteractor: SaveConnectingServerInteractor,
private val refreshSettingsInteractor: RefreshSettingsInteractor, private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val getAccountsInteractor: GetAccountsInteractor, private val getAccountsInteractor: GetAccountsInteractor,
factory: RocketChatClientFactory val settingsInteractor: GetSettingsInteractor,
) : CheckServerPresenter(strategy, factory, view) { val factory: RocketChatClientFactory
) : CheckServerPresenter(strategy, factory, settingsInteractor, view) {
fun checkServer(server: String) { fun checkServer(server: String) {
if (!server.isValidUrl()) { if (!server.isValidUrl()) {
view.showInvalidServerUrlMessage() view.showInvalidServerUrlMessage()
} else { } else {
view.showLoading() view.showLoading()
setupConnectionInfo(server)
checkServerInfo(server) checkServerInfo(server)
} }
} }
fun connect(server: String) { fun connect(serverUrl: String) {
connectToServer(server) { navigator.toLoginOptions(server) } connectToServer(serverUrl) {
if (totalSocialAccountsEnabled == 0 && !isNewAccountCreationEnabled) {
navigator.toLogin(serverUrl)
} else {
navigator.toLoginOptions(
serverUrl,
state,
facebookOauthUrl,
githubOauthUrl,
googleOauthUrl,
linkedinOauthUrl,
gitlabOauthUrl,
wordpressOauthUrl,
casLoginUrl,
casToken,
customOauthUrl,
customOauthServiceName,
customOauthServiceNameTextColor,
customOauthServiceButtonColor,
samlUrl,
samlToken,
samlServiceName,
samlServiceNameTextColor,
samlServiceButtonColor,
totalSocialAccountsEnabled,
isLoginFormEnabled,
isNewAccountCreationEnabled
)
}
}
}
fun deepLink(deepLinkInfo: LoginDeepLinkInfo) {
connectToServer(deepLinkInfo.url) {
navigator.toLoginOptions(deepLinkInfo.url, deepLinkInfo = deepLinkInfo)
}
} }
private fun connectToServer(server: String, block: () -> Unit) { private fun connectToServer(server: String, block: () -> Unit) {
...@@ -47,11 +85,18 @@ class ServerPresenter @Inject constructor( ...@@ -47,11 +85,18 @@ class ServerPresenter @Inject constructor(
navigator.toChatList(server) navigator.toChatList(server)
return@launchUI return@launchUI
} }
view.showLoading() view.showLoading()
try { try {
refreshSettingsInteractor.refresh(server) refreshSettingsInteractor.refresh(server)
serverInteractor.save(server) serverInteractor.save(server)
setupConnectionInfo(server)
// preparing next fragment before showing it
checkEnabledAccounts(server)
checkIfLoginFormIsEnabled()
checkIfCreateNewAccountIsEnabled()
block() block()
} catch (ex: Exception) { } catch (ex: Exception) {
view.showMessage(ex) view.showMessage(ex)
...@@ -62,9 +107,4 @@ class ServerPresenter @Inject constructor( ...@@ -62,9 +107,4 @@ class ServerPresenter @Inject constructor(
} }
} }
fun deepLink(deepLinkInfo: LoginDeepLinkInfo) {
connectToServer(deepLinkInfo.url) {
navigator.toLoginOptions(deepLinkInfo.url, deepLinkInfo)
}
}
} }
\ No newline at end of file
...@@ -41,13 +41,7 @@ import okhttp3.HttpUrl ...@@ -41,13 +41,7 @@ import okhttp3.HttpUrl
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
fun newInstance(deepLinkInfo: LoginDeepLinkInfo?): Fragment { fun newInstance() = ServerFragment()
return ServerFragment().apply {
arguments = Bundle(1).apply {
putParcelable(DEEP_LINK_INFO, deepLinkInfo)
}
}
}
private const val DEEP_LINK_INFO = "DeepLinkInfo" private const val DEEP_LINK_INFO = "DeepLinkInfo"
......
...@@ -99,7 +99,7 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { ...@@ -99,7 +99,7 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
R.id.fragment_container, R.id.fragment_container,
allowStateLoss = true allowStateLoss = true
) { ) {
chat.rocket.android.authentication.server.ui.newInstance(deepLinkInfo) chat.rocket.android.authentication.server.ui.newInstance()
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment