Commit e25c7a05 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Remove logs and update/add funcitons.

parent 6c49a9fb
...@@ -26,24 +26,21 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -26,24 +26,21 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
} }
else -> { else -> {
launchUI(strategy) { launchUI(strategy) {
view.showLoading()
if (NetworkHelper.hasInternetAccess()) { if (NetworkHelper.hasInternetAccess()) {
view.showLoading()
try { try {
val token = client.login(usernameOrEmail, password) val token = client.login(usernameOrEmail, password)
Timber.d("Created token: $token") // TODO Salve token?
navigator.toChatList() navigator.toChatList()
} catch (rocketChatException: RocketChatException) { } catch (rocketChatException: RocketChatException) {
when (rocketChatException) { if (rocketChatException is RocketChatTwoFactorException) {
is RocketChatTwoFactorException -> {
navigator.toTwoFA(navigator.currentServer!!, usernameOrEmail, password) navigator.toTwoFA(navigator.currentServer!!, usernameOrEmail, password)
} } else {
else -> {
val errorMessage = rocketChatException.message val errorMessage = rocketChatException.message
if (errorMessage != null) { if (errorMessage != null) {
view.showMessage(errorMessage) view.showMessage(errorMessage)
} }
} }
}
} finally { } finally {
view.hideLoading() view.hideLoading()
} }
......
...@@ -27,13 +27,13 @@ class LoginFragment : Fragment(), LoginView { ...@@ -27,13 +27,13 @@ class LoginFragment : Fragment(), LoginView {
private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener { private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) { if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) {
showOauthView(false)
showSignUpView(false) showSignUpView(false)
showOauthView(false)
showLoginButton(true) showLoginButton(true)
} else { } else {
if (isEditTextEmpty()) { if (isEditTextEmpty()) {
showOauthView(true)
showSignUpView(true) showSignUpView(true)
showOauthView(true)
showLoginButton(false) showLoginButton(false)
} }
} }
...@@ -219,6 +219,10 @@ class LoginFragment : Fragment(), LoginView { ...@@ -219,6 +219,10 @@ class LoginFragment : Fragment(), LoginView {
button_log_in.isEnabled = value button_log_in.isEnabled = value
text_username_or_email.isEnabled = value text_username_or_email.isEnabled = value
text_password.isEnabled = value text_password.isEnabled = value
if (isEditTextEmpty()) {
showSignUpView(value)
showOauthView(value)
}
} }
// Returns true if *all* EditTexts are empty. // Returns true if *all* EditTexts are empty.
......
...@@ -54,17 +54,16 @@ class ServerFragment : Fragment(), ServerView { ...@@ -54,17 +54,16 @@ class ServerFragment : Fragment(), ServerView {
} }
override fun showLoading() { override fun showLoading() {
text_server_url.isEnabled = false enableUserInput(false)
button_connect.isEnabled = false view_loading.show()
view_loading.setVisibility(true)
} }
override fun hideLoading() { override fun hideLoading() {
view_loading.setVisibility(false) view_loading.hide()
button_connect.isEnabled = true enableUserInput(true)
text_server_url.isEnabled = true
} }
override fun showMessage(message: String) { override fun showMessage(message: String) {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
} }
...@@ -72,4 +71,9 @@ class ServerFragment : Fragment(), ServerView { ...@@ -72,4 +71,9 @@ class ServerFragment : Fragment(), ServerView {
override fun showNoInternetConnection() { override fun showNoInternetConnection() {
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show() Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
} }
private fun enableUserInput(value: Boolean) {
button_connect.isEnabled = value
text_server_url.isEnabled = value
}
} }
\ No newline at end of file
...@@ -36,14 +36,12 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -36,14 +36,12 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
view.showLoading() view.showLoading()
try { try {
val user = client.signup(email, name, username, password) val user = client.signup(email, name, username, password)
Timber.d("Created user: $user") // TODO Salve user?
val token = client.login(username, password) val token = client.login(username, password)
Timber.d("Logged in. Token: $token") // TODO Salve token?
navigator.toChatList() navigator.toChatList()
} catch (ex: RocketChatException) { } catch (rocketChatException: RocketChatException) {
val errorMessage = ex.message val errorMessage = rocketChatException.message
if (errorMessage != null) { if (errorMessage != null) {
view.showMessage(errorMessage) view.showMessage(errorMessage)
} }
......
...@@ -77,7 +77,6 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -77,7 +77,6 @@ class TwoFAFragment : Fragment(), TwoFAView {
} }
override fun showLoading() { override fun showLoading() {
view_loading.setVisibility(true)
enableUserInput(false) enableUserInput(false)
view_loading.show() view_loading.show()
} }
......
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