Commit 78350cb1 authored by Lucio Maciel's avatar Lucio Maciel

Check server version on ServerFragment for deeplink also

parent 86fe6abe
...@@ -43,13 +43,11 @@ class LoginPresenter @Inject constructor( ...@@ -43,13 +43,11 @@ class LoginPresenter @Inject constructor(
serverInteractor: GetCurrentServerInteractor, serverInteractor: GetCurrentServerInteractor,
private val saveAccountInteractor: SaveAccountInteractor, private val saveAccountInteractor: SaveAccountInteractor,
private val factory: RocketChatClientFactory private val factory: RocketChatClientFactory
) : CheckServerPresenter(strategy, factory, view) { ) {
// TODO - we should validate the current server when opening the app, and have a nonnull get() // TODO - we should validate the current server when opening the app, and have a nonnull get()
private val currentServer = serverInteractor.get()!! private val currentServer = serverInteractor.get()!!
private lateinit var client: RocketChatClient private lateinit var client: RocketChatClient
private lateinit var settings: PublicSettings private lateinit var settings: PublicSettings
//private val client: RocketChatClient = factory.create(currentServer)
//private val settings: PublicSettings = settingsInteractor.get(currentServer)
private lateinit var usernameOrEmail: String private lateinit var usernameOrEmail: String
private lateinit var password: String private lateinit var password: String
private lateinit var credentialToken: String private lateinit var credentialToken: String
...@@ -98,19 +96,8 @@ class LoginPresenter @Inject constructor( ...@@ -98,19 +96,8 @@ class LoginPresenter @Inject constructor(
deepLinkUserId = deepLinkInfo.userId deepLinkUserId = deepLinkInfo.userId
deepLinkToken = deepLinkInfo.token deepLinkToken = deepLinkInfo.token
tokenRepository.save(serverUrl, Token(deepLinkUserId, deepLinkToken)) tokenRepository.save(serverUrl, Token(deepLinkUserId, deepLinkToken))
launchUI(strategy) {
try { doAuthentication(TYPE_LOGIN_DEEP_LINK)
val version = checkServerVersion(serverUrl).await()
when (version) {
is Version.OutOfDateError -> {
view.blockAndAlertNotRequiredVersion()
}
else -> doAuthentication(TYPE_LOGIN_DEEP_LINK)
}
} catch (ex: Exception) {
Timber.d(ex, "Error performing deep link login")
}
}
} }
private fun setupConnectionInfo(serverUrl: String) { private fun setupConnectionInfo(serverUrl: String) {
......
...@@ -4,7 +4,7 @@ import chat.rocket.android.authentication.server.presentation.VersionCheckView ...@@ -4,7 +4,7 @@ import chat.rocket.android.authentication.server.presentation.VersionCheckView
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
interface LoginView : LoadingView, MessageView, VersionCheckView { interface LoginView : LoadingView, MessageView {
/** /**
* Shows the form view (i.e the username/email and password fields) if it is enabled by the server settings. * Shows the form view (i.e the username/email and password fields) if it is enabled by the server settings.
......
...@@ -370,27 +370,6 @@ class LoginFragment : Fragment(), LoginView { ...@@ -370,27 +370,6 @@ class LoginFragment : Fragment(), LoginView {
} }
} }
override fun alertNotRecommendedVersion() {
ui {
AlertDialog.Builder(it)
.setMessage(getString(R.string.msg_ver_not_recommended, BuildConfig.RECOMMENDED_SERVER_VERSION))
.setPositiveButton(R.string.msg_ok, null)
.create()
.show()
}
}
override fun blockAndAlertNotRequiredVersion() {
ui {
AlertDialog.Builder(it)
.setMessage(getString(R.string.msg_ver_not_minimum, BuildConfig.REQUIRED_SERVER_VERSION))
.setOnDismissListener { activity?.onBackPressed() }
.setPositiveButton(R.string.msg_ok, null)
.create()
.show()
}
}
private fun showRemainingSocialAccountsView() { private fun showRemainingSocialAccountsView() {
social_accounts_container.postDelayed(300) { social_accounts_container.postDelayed(300) {
ui { ui {
......
package chat.rocket.android.authentication.server.ui package chat.rocket.android.authentication.server.ui
import android.app.AlertDialog import android.app.AlertDialog
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.view.LayoutInflater import android.view.LayoutInflater
...@@ -14,6 +15,7 @@ import chat.rocket.android.authentication.server.presentation.ServerPresenter ...@@ -14,6 +15,7 @@ import chat.rocket.android.authentication.server.presentation.ServerPresenter
import chat.rocket.android.authentication.server.presentation.ServerView import chat.rocket.android.authentication.server.presentation.ServerView
import chat.rocket.android.helper.KeyboardHelper import chat.rocket.android.helper.KeyboardHelper
import chat.rocket.android.util.extensions.* import chat.rocket.android.util.extensions.*
import chat.rocket.common.util.ifNull
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_server.* import kotlinx.android.synthetic.main.fragment_authentication_server.*
import javax.inject.Inject import javax.inject.Inject
...@@ -52,6 +54,8 @@ class ServerFragment : Fragment(), ServerView { ...@@ -52,6 +54,8 @@ class ServerFragment : Fragment(), ServerView {
setupOnClickListener() setupOnClickListener()
deepLinkInfo?.let { deepLinkInfo?.let {
val uri = Uri.parse(it.url)
uri?.let { text_server_protocol.hintContent = it.host }
presenter.deepLink(it) presenter.deepLink(it)
} }
} }
...@@ -99,8 +103,7 @@ class ServerFragment : Fragment(), ServerView { ...@@ -99,8 +103,7 @@ class ServerFragment : Fragment(), ServerView {
AlertDialog.Builder(it) AlertDialog.Builder(it)
.setMessage(getString(R.string.msg_ver_not_recommended, BuildConfig.RECOMMENDED_SERVER_VERSION)) .setMessage(getString(R.string.msg_ver_not_recommended, BuildConfig.RECOMMENDED_SERVER_VERSION))
.setPositiveButton(R.string.msg_ok, { _, _ -> .setPositiveButton(R.string.msg_ok, { _, _ ->
val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent) performConnect()
presenter.connect(text_server_protocol.textContent + url)
}) })
.create() .create()
.show() .show()
...@@ -113,15 +116,27 @@ class ServerFragment : Fragment(), ServerView { ...@@ -113,15 +116,27 @@ class ServerFragment : Fragment(), ServerView {
AlertDialog.Builder(it) AlertDialog.Builder(it)
.setMessage(getString(R.string.msg_ver_not_minimum, BuildConfig.REQUIRED_SERVER_VERSION)) .setMessage(getString(R.string.msg_ver_not_minimum, BuildConfig.REQUIRED_SERVER_VERSION))
.setPositiveButton(R.string.msg_ok, null) .setPositiveButton(R.string.msg_ok, null)
.setOnDismissListener {
// reset the deeplink info, so the user can log to another server...
deepLinkInfo = null
}
.create() .create()
.show() .show()
} }
} }
override fun versionOk() { override fun versionOk() {
performConnect()
}
private fun performConnect() {
ui { ui {
val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent) deepLinkInfo?.let {
presenter.connect(text_server_protocol.textContent + url) presenter.deepLink(it)
}.ifNull {
val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent)
presenter.connect(text_server_protocol.textContent + url)
}
} }
} }
......
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