Commit 855167d7 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Rename function.

parent 3fa2133c
...@@ -13,9 +13,9 @@ interface LoginView : LoadingView, MessageView, ShakeView { ...@@ -13,9 +13,9 @@ interface LoginView : LoadingView, MessageView, ShakeView {
* [enableLoginByLinkedin], [enableLoginByMeteor], [enableLoginByTwitter] or [enableLoginByGitlab]) for the oauth view. * [enableLoginByLinkedin], [enableLoginByMeteor], [enableLoginByTwitter] or [enableLoginByGitlab]) for the oauth view.
* If the possibility of login via social accounts exceeds 3 different ways we should set up the FAB ([setupFabListener]) to show the remaining view(s). * If the possibility of login via social accounts exceeds 3 different ways we should set up the FAB ([setupFabListener]) to show the remaining view(s).
* *
* @param show True to show the oauth view, false otherwise. * @param value True to show the oauth view, false otherwise.
*/ */
fun shouldShowOauthView(show: Boolean) fun showOauthView(value: Boolean)
/** /**
* Setups the FloatingActionButton to show more social accounts views (expanding the oauth view interface to show the remaining view(s)). * Setups the FloatingActionButton to show more social accounts views (expanding the oauth view interface to show the remaining view(s)).
...@@ -60,7 +60,7 @@ interface LoginView : LoadingView, MessageView, ShakeView { ...@@ -60,7 +60,7 @@ interface LoginView : LoadingView, MessageView, ShakeView {
/** /**
* Shows the sign up view if the server settings allow the new users registration. * Shows the sign up view if the server settings allow the new users registration.
* *
* @param show True to show the sign up view, false otherwise. * @param value True to show the sign up view, false otherwise.
*/ */
fun shouldShowSignUpView(show: Boolean) fun showSignUpView(value: Boolean)
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ import DrawableHelper ...@@ -4,6 +4,7 @@ import DrawableHelper
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.text.style.ClickableSpan
import android.view.* import android.view.*
import android.widget.ScrollView import android.widget.ScrollView
import android.widget.Toast import android.widget.Toast
...@@ -12,6 +13,7 @@ import chat.rocket.android.authentication.login.presentation.LoginPresenter ...@@ -12,6 +13,7 @@ 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.helper.AnimationHelper import chat.rocket.android.helper.AnimationHelper
import chat.rocket.android.helper.KeyboardHelper import chat.rocket.android.helper.KeyboardHelper
import chat.rocket.android.helper.TextHelper
import chat.rocket.android.util.setVisibility import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.textContent import chat.rocket.android.util.textContent
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
...@@ -22,14 +24,14 @@ class LoginFragment : Fragment(), LoginView { ...@@ -22,14 +24,14 @@ class LoginFragment : Fragment(), LoginView {
@Inject lateinit var presenter: LoginPresenter @Inject lateinit var presenter: LoginPresenter
private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener { private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) { if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) {
shouldShowOauthView(false) showOauthView(false)
shouldShowSignUpView(false) showSignUpView(false)
shouldShowLoginButton(true) showLoginButton(true)
} else { } else {
if (isEditTextEmpty()) { if (isEditTextEmpty()) {
shouldShowOauthView(true) showOauthView(true)
shouldShowSignUpView(true) showSignUpView(true)
shouldShowLoginButton(false) showLoginButton(false)
} }
} }
} }
...@@ -45,7 +47,8 @@ class LoginFragment : Fragment(), LoginView { ...@@ -45,7 +47,8 @@ class LoginFragment : Fragment(), LoginView {
} }
} }
lateinit var serverUrl: String // Todo remove
private lateinit var serverUrl: String
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
...@@ -68,7 +71,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -68,7 +71,7 @@ class LoginFragment : Fragment(), LoginView {
// TODO: THIS IS A PRESENTER CONCERN - REMOVE THAT ! // TODO: THIS IS A PRESENTER CONCERN - REMOVE THAT !
// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
shouldShowOauthView(true) showOauthView(true)
// Show the first three social account's ImageButton (REMARK: we must show at maximum *three* views) // Show the first three social account's ImageButton (REMARK: we must show at maximum *three* views)
enableLoginByFacebook() enableLoginByFacebook()
...@@ -78,7 +81,8 @@ class LoginFragment : Fragment(), LoginView { ...@@ -78,7 +81,8 @@ class LoginFragment : Fragment(), LoginView {
setupFabListener() setupFabListener()
// Just an example: if the server allow the new users registration then show the respective interface. // Just an example: if the server allow the new users registration then show the respective interface.
shouldShowSignUpView(true) setupSignUpListener()
showSignUpView(true)
// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
button_log_in.setOnClickListener { presenter.authenticate(text_username_or_email, text_password) } button_log_in.setOnClickListener { presenter.authenticate(text_username_or_email, text_password) }
...@@ -92,8 +96,8 @@ class LoginFragment : Fragment(), LoginView { ...@@ -92,8 +96,8 @@ class LoginFragment : Fragment(), LoginView {
} }
} }
override fun shouldShowOauthView(show: Boolean) { override fun showOauthView(value: Boolean) {
if (show) { if (value) {
social_accounts_container.setVisibility(true) social_accounts_container.setVisibility(true)
button_fab.setVisibility(true) button_fab.setVisibility(true)
...@@ -111,13 +115,9 @@ class LoginFragment : Fragment(), LoginView { ...@@ -111,13 +115,9 @@ class LoginFragment : Fragment(), LoginView {
override fun setupFabListener() { override fun setupFabListener() {
button_fab.setOnClickListener({ button_fab.setOnClickListener({
enableLoginByLinkedin() button_fab.hide()
enableLoginByMeteor() showRemainingSocialAccountsView()
enableLoginByTwitter()
enableLoginByGitlab()
scrollToBottom() scrollToBottom()
hideFab()
}) })
} }
...@@ -149,21 +149,18 @@ class LoginFragment : Fragment(), LoginView { ...@@ -149,21 +149,18 @@ class LoginFragment : Fragment(), LoginView {
button_gitlab.setVisibility(true) button_gitlab.setVisibility(true)
} }
override fun shouldShowSignUpView(show: Boolean) { override fun showSignUpView(value: Boolean) {
if (show) { text_new_to_rocket_chat.setVisibility(value)
text_new_to_rocket_chat.setVisibility(true)
text_new_to_rocket_chat.setOnClickListener { presenter.signup() }
} else {
text_new_to_rocket_chat.setVisibility(false)
}
} }
override fun showLoading() { override fun showLoading() {
view_loading.setVisibility(true) enableUserInput(false)
view_loading.show()
} }
override fun hideLoading() { override fun hideLoading() {
view_loading.setVisibility(false) view_loading.hide()
enableUserInput(true)
} }
override fun showMessage(message: String) { override fun showMessage(message: String) {
...@@ -171,7 +168,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -171,7 +168,7 @@ class LoginFragment : Fragment(), LoginView {
} }
override fun shakeView(viewToShake: View) { override fun shakeView(viewToShake: View) {
AnimationHelper.vibrate(viewToShake.context) AnimationHelper.vibrateSmartPhone(viewToShake.context)
AnimationHelper.shakeView(viewToShake) AnimationHelper.shakeView(viewToShake)
viewToShake.requestFocus() viewToShake.requestFocus()
} }
...@@ -188,12 +185,27 @@ class LoginFragment : Fragment(), LoginView { ...@@ -188,12 +185,27 @@ class LoginFragment : Fragment(), LoginView {
} }
} }
private fun shouldShowLoginButton(show: Boolean) { private fun showLoginButton(value: Boolean) {
if (show) { button_log_in.setVisibility(value)
button_log_in.setVisibility(true) }
} else {
button_log_in.setVisibility(false) private fun setupSignUpListener() {
val signUp = getString(R.string.title_sign_up)
val newToRocketChat = String.format(getString(R.string.msg_new_to_rocket_chat), signUp)
text_new_to_rocket_chat.text = newToRocketChat
val signUpListener = object : ClickableSpan() {
override fun onClick(view: View) = presenter.signup()
} }
TextHelper.addLink(text_new_to_rocket_chat, arrayOf(signUp), arrayOf(signUpListener))
}
private fun enableUserInput(value: Boolean) {
button_log_in.isEnabled = value
text_username_or_email.isEnabled = value
text_password.isEnabled = value
} }
// Returns true if *all* EditTexts are empty. // Returns true if *all* EditTexts are empty.
...@@ -201,15 +213,18 @@ class LoginFragment : Fragment(), LoginView { ...@@ -201,15 +213,18 @@ class LoginFragment : Fragment(), LoginView {
return text_username_or_email.textContent.isBlank() && text_password.textContent.isEmpty() return text_username_or_email.textContent.isBlank() && text_password.textContent.isEmpty()
} }
private fun scrollToBottom() { private fun showRemainingSocialAccountsView() {
scroll_view.postDelayed({ social_accounts_container.postDelayed({
scroll_view.fullScroll(ScrollView.FOCUS_DOWN) enableLoginByLinkedin()
enableLoginByMeteor()
enableLoginByTwitter()
enableLoginByGitlab()
}, 1000) }, 1000)
} }
private fun hideFab() { private fun scrollToBottom() {
button_fab.postDelayed({ scroll_view.postDelayed({
button_fab.hide() scroll_view.fullScroll(ScrollView.FOCUS_DOWN)
}, 1500) }, 1250)
} }
} }
\ No newline at end of file
...@@ -14,7 +14,6 @@ import chat.rocket.android.authentication.twofactor.presentation.TwoFAPresenter ...@@ -14,7 +14,6 @@ import chat.rocket.android.authentication.twofactor.presentation.TwoFAPresenter
import chat.rocket.android.authentication.twofactor.presentation.TwoFAView import chat.rocket.android.authentication.twofactor.presentation.TwoFAView
import chat.rocket.android.helper.AnimationHelper import chat.rocket.android.helper.AnimationHelper
import chat.rocket.android.util.setVisibility import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.textContent
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_two_fa.* import kotlinx.android.synthetic.main.fragment_authentication_two_fa.*
import javax.inject.Inject import javax.inject.Inject
...@@ -78,7 +77,7 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -78,7 +77,7 @@ class TwoFAFragment : Fragment(), TwoFAView {
} }
override fun shakeView(viewToShake: View) { override fun shakeView(viewToShake: View) {
AnimationHelper.vibrate(viewToShake.context) AnimationHelper.vibrateSmartPhone(viewToShake.context)
AnimationHelper.shakeView(viewToShake) AnimationHelper.shakeView(viewToShake)
} }
......
...@@ -35,7 +35,7 @@ object AnimationHelper { ...@@ -35,7 +35,7 @@ object AnimationHelper {
/** /**
* Vibrates the smart phone. * Vibrates the smart phone.
*/ */
fun vibrate(context: Context) { fun vibrateSmartPhone(context: Context) {
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= 26) {
vibrator.vibrate(VibrationEffect.createOneShot(200, VibrationEffect.DEFAULT_AMPLITUDE)) vibrator.vibrate(VibrationEffect.createOneShot(200, VibrationEffect.DEFAULT_AMPLITUDE))
......
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