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
import chat.rocket.android.analytics.event.ScreenViewEvent
import chat.rocket.android.authentication.login.presentation.LoginPresenter
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.hasCredentialsSupport
import chat.rocket.android.helper.requestStoredCredentials
import chat.rocket.android.helper.saveCredentials
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.showToast
import chat.rocket.android.util.extensions.textContent
......@@ -27,25 +29,40 @@ import chat.rocket.android.util.extensions.ui
import dagger.android.support.AndroidSupportInjection
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Observables
import kotlinx.android.synthetic.main.app_bar.*
import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
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_MULTIPLE_ACCOUNTS_RESOLUTION = 2
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 {
@Inject
lateinit var presenter: LoginPresenter
@Inject
lateinit var analyticsManager: AnalyticsManager
private var serverName: String? = null
private val editTextsDisposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
val bundle = arguments
if (bundle != null) {
serverName = bundle.getString(SERVER_NAME)
}
}
override fun onCreateView(
......@@ -56,11 +73,10 @@ class LoginFragment : Fragment(), LoginView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar()
presenter.setupView()
subscribeEditTexts()
setupOnClickListener()
analyticsManager.logScreenView(ScreenViewEvent.Login)
}
......@@ -95,6 +111,15 @@ class LoginFragment : Fragment(), LoginView {
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() {
ui {
disableUserInput()
......
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.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy
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.SaveConnectingServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.server.presentation.CheckServerPresenter
import chat.rocket.android.util.extension.launchUI
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.withContext
import javax.inject.Inject
class OnBoardingPresenter @Inject constructor(
......@@ -16,31 +20,71 @@ class OnBoardingPresenter @Inject constructor(
private val navigator: AuthenticationNavigator,
private val serverInteractor: SaveConnectingServerInteractor,
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?) =
navigator.toConnectWithAServer(deepLinkInfo)
fun toSignInToYourServer() = navigator.toSignInToYourServer()
fun connectToCommunityServer(communityServer: String) =
connectToServer(communityServer) { navigator.toLoginOptions(communityServer) }
fun connectToCommunityServer(communityServerUrl: String) {
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)
private fun connectToServer(server: String, block: () -> Unit) {
private fun connectToServer(serverUrl: String, block: () -> Unit) {
launchUI(strategy) {
// 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) {
navigator.toChatList(server)
navigator.toChatList(serverUrl)
return@launchUI
}
view.showLoading()
try {
refreshSettingsInteractor.refresh(server)
serverInteractor.save(server)
block()
withContext(DefaultDispatcher) {
setupConnectionInfo(serverUrl)
// preparing next fragment before showing it
checkEnabledAccounts(serverUrl)
checkIfLoginFormIsEnabled()
checkIfCreateNewAccountIsEnabled()
refreshSettingsInteractor.refresh(serverUrl)
serverInteractor.save(serverUrl)
block()
}
} catch (ex: Exception) {
view.showMessage(ex)
} finally {
......
......@@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment
import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager
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.OnBoardingView
import chat.rocket.android.authentication.ui.AuthenticationActivity
......@@ -42,13 +41,12 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToobar()
setupToolbar()
setupOnClickListener()
analyticsManager.logScreenView(ScreenViewEvent.OnBoarding)
}
private fun setupToobar() {
private fun setupToolbar() {
with(activity as AuthenticationActivity) {
view?.let { this.setLightStatusBar(it) }
toolbar.isVisible = false
......@@ -56,7 +54,7 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
}
private fun setupOnClickListener() {
connect_with_a_server_container.setOnClickListener { connectWithAServer() }
connect_with_a_server_container.setOnClickListener { signInToYourServer() }
join_community_container.setOnClickListener { joinInTheCommunity() }
create_server_container.setOnClickListener { createANewServer() }
}
......@@ -87,21 +85,19 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
private fun connectWithAServer() = ui {
presenter.toConnectWithAServer(activity?.intent?.getLoginDeepLinkInfo())
private fun signInToYourServer() = ui {
presenter.toSignInToYourServer()
}
private fun joinInTheCommunity() = ui {
presenter.connectToCommunityServer(
getString(R.string.default_protocol) +
getString(R.string.community_server_url)
getString(R.string.default_protocol) + getString(R.string.community_server_url)
)
}
private fun createANewServer() = ui {
presenter.toCreateANewServer(
getString(R.string.default_protocol) +
getString(R.string.create_server_url)
getString(R.string.default_protocol) + getString(R.string.create_server_url)
)
}
}
......@@ -13,18 +13,66 @@ import chat.rocket.android.webview.ui.webViewIntent
class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
fun toConnectWithAServer(deepLinkInfo: LoginDeepLinkInfo?) {
fun toSignInToYourServer() {
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(
ScreenViewEvent.LoginOptions.screenName,
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) {
}
}
fun toLogin() {
fun toLogin(serverUrl: String) {
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
import chat.rocket.android.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy
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.SaveConnectingServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
......@@ -20,20 +21,57 @@ class ServerPresenter @Inject constructor(
private val serverInteractor: SaveConnectingServerInteractor,
private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val getAccountsInteractor: GetAccountsInteractor,
factory: RocketChatClientFactory
) : CheckServerPresenter(strategy, factory, view) {
val settingsInteractor: GetSettingsInteractor,
val factory: RocketChatClientFactory
) : CheckServerPresenter(strategy, factory, settingsInteractor, view) {
fun checkServer(server: String) {
if (!server.isValidUrl()) {
view.showInvalidServerUrlMessage()
} else {
view.showLoading()
setupConnectionInfo(server)
checkServerInfo(server)
}
}
fun connect(server: String) {
connectToServer(server) { navigator.toLoginOptions(server) }
fun connect(serverUrl: String) {
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) {
......@@ -47,11 +85,18 @@ class ServerPresenter @Inject constructor(
navigator.toChatList(server)
return@launchUI
}
view.showLoading()
try {
refreshSettingsInteractor.refresh(server)
serverInteractor.save(server)
setupConnectionInfo(server)
// preparing next fragment before showing it
checkEnabledAccounts(server)
checkIfLoginFormIsEnabled()
checkIfCreateNewAccountIsEnabled()
block()
} catch (ex: Exception) {
view.showMessage(ex)
......@@ -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
import java.util.concurrent.TimeUnit
import javax.inject.Inject
fun newInstance(deepLinkInfo: LoginDeepLinkInfo?): Fragment {
return ServerFragment().apply {
arguments = Bundle(1).apply {
putParcelable(DEEP_LINK_INFO, deepLinkInfo)
}
}
}
fun newInstance() = ServerFragment()
private const val DEEP_LINK_INFO = "DeepLinkInfo"
......
......@@ -99,7 +99,7 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
R.id.fragment_container,
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