Commit 7e61d679 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add TODOS, comments and organize code.

parent 456ac71c
...@@ -7,6 +7,7 @@ import android.os.Bundle ...@@ -7,6 +7,7 @@ import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.view.* import android.view.*
import android.view.inputmethod.InputMethodManager
import android.widget.ScrollView import android.widget.ScrollView
import android.widget.Toast import android.widget.Toast
import chat.rocket.android.R import chat.rocket.android.R
...@@ -15,6 +16,7 @@ import chat.rocket.android.authentication.login.presentation.LoginView ...@@ -15,6 +16,7 @@ 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.helper.TextHelper
import chat.rocket.android.util.inflate
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
...@@ -23,8 +25,9 @@ import javax.inject.Inject ...@@ -23,8 +25,9 @@ import javax.inject.Inject
class LoginFragment : Fragment(), LoginView { class LoginFragment : Fragment(), LoginView {
@Inject lateinit var presenter: LoginPresenter @Inject lateinit var presenter: LoginPresenter
@Inject lateinit var appContext: Context @Inject lateinit var appContext: Context // TODO we really need it? Check alternatives...
/*
private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener { private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) { if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) {
showSignUpView(false) showSignUpView(false)
...@@ -39,7 +42,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -39,7 +42,7 @@ class LoginFragment : Fragment(), LoginView {
} }
} }
private var isGlobalLayoutListenerSetUp = false private var isGlobalLayoutListenerSetUp = false
*/
companion object { companion object {
fun newInstance() = LoginFragment() fun newInstance() = LoginFragment()
} }
...@@ -49,18 +52,27 @@ class LoginFragment : Fragment(), LoginView { ...@@ -49,18 +52,27 @@ class LoginFragment : Fragment(), LoginView {
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_authentication_log_in, container, false) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = container?.inflate(R.layout.fragment_authentication_log_in)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) activity?.apply {
text_username_or_email.requestFocus()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(text_username_or_email, InputMethodManager.SHOW_IMPLICIT)
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
tintEditTextDrawableStart() tintEditTextDrawableStart()
} }
// TODO: THIS IS A PRESENTER CONCERN - REMOVE THAT ! button_log_in.setOnClickListener {
presenter.authenticate(text_username_or_email.textContent, text_password.textContent)
}
/*
// TODO: THIS IS A PRESENTER CONCERN - REMOVE THAT ! WE SHOULD GET THE SERVER SETTINGS!
// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
showOauthView(true) showOauthView(true)
...@@ -75,10 +87,9 @@ class LoginFragment : Fragment(), LoginView { ...@@ -75,10 +87,9 @@ class LoginFragment : Fragment(), LoginView {
setupSignUpListener() setupSignUpListener()
showSignUpView(true) showSignUpView(true)
// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
*/
button_log_in.setOnClickListener { presenter.authenticate(text_username_or_email.textContent, text_password.textContent) }
} }
/*
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
if (isGlobalLayoutListenerSetUp) { if (isGlobalLayoutListenerSetUp) {
...@@ -86,30 +97,30 @@ class LoginFragment : Fragment(), LoginView { ...@@ -86,30 +97,30 @@ class LoginFragment : Fragment(), LoginView {
isGlobalLayoutListenerSetUp = false isGlobalLayoutListenerSetUp = false
} }
} }
*/
override fun showOauthView(value: Boolean) { override fun showOauthView(value: Boolean) {
if (value) { // if (value) {
social_accounts_container.setVisibility(true) // social_accounts_container.setVisibility(true)
button_fab.setVisibility(true) // button_fab.setVisibility(true)
//
// We need to setup the layout to hide and show the oauth interface when the soft keyboard is shown // // We need to setup the layout to hide and show the oauth interface when the soft keyboard is shown
// (means that the user touched the text_username_or_email or text_password EditText to fill that respective fields). // // (means that the user touched the text_username_or_email or text_password EditText to fill that respective fields).
if (!isGlobalLayoutListenerSetUp) { // if (!isGlobalLayoutListenerSetUp) {
scroll_view.viewTreeObserver.addOnGlobalLayoutListener(layoutListener) // scroll_view.viewTreeObserver.addOnGlobalLayoutListener(layoutListener)
isGlobalLayoutListenerSetUp = true // isGlobalLayoutListenerSetUp = true
} // }
} else { // } else {
social_accounts_container.setVisibility(false) // social_accounts_container.setVisibility(false)
button_fab.setVisibility(false) // button_fab.setVisibility(false)
} // }
} }
override fun setupFabListener() { override fun setupFabListener() {
button_fab.setOnClickListener({ // button_fab.setOnClickListener({
button_fab.hide() // button_fab.hide()
showRemainingSocialAccountsView() // showRemainingSocialAccountsView()
scrollToBottom() // scrollToBottom()
}) // })
} }
override fun enableLoginByFacebook() { override fun enableLoginByFacebook() {
...@@ -140,9 +151,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -140,9 +151,7 @@ class LoginFragment : Fragment(), LoginView {
button_gitlab.setVisibility(true) button_gitlab.setVisibility(true)
} }
override fun showSignUpView(value: Boolean) { override fun showSignUpView(value: Boolean) = text_new_to_rocket_chat.setVisibility(value)
text_new_to_rocket_chat.setVisibility(value)
}
override fun alertWrongUsernameOrEmail() { override fun alertWrongUsernameOrEmail() {
AnimationHelper.vibrateSmartPhone(appContext) AnimationHelper.vibrateSmartPhone(appContext)
...@@ -166,20 +175,17 @@ class LoginFragment : Fragment(), LoginView { ...@@ -166,20 +175,17 @@ class LoginFragment : Fragment(), LoginView {
enableUserInput(true) enableUserInput(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()
}
override fun showGenericErrorMessage() {
showMessage(getString(R.string.msg_generic_error))
}
override fun showNoInternetConnection() { override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
}
override fun showNoInternetConnection() = showMessage(getString(R.string.msg_no_internet_connection))
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
activity?.applicationContext?.apply { activity?.apply {
val personDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_assignment_ind_black_24dp, this) val personDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_assignment_ind_black_24dp, this)
val lockDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_lock_black_24dp, this) val lockDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_lock_black_24dp, this)
...@@ -189,7 +195,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -189,7 +195,7 @@ class LoginFragment : Fragment(), LoginView {
DrawableHelper.compoundDrawables(arrayOf(text_username_or_email, text_password), drawables) DrawableHelper.compoundDrawables(arrayOf(text_username_or_email, text_password), drawables)
} }
} }
/*
private fun showLoginButton(value: Boolean) { private fun showLoginButton(value: Boolean) {
button_log_in.setVisibility(value) button_log_in.setVisibility(value)
} }
...@@ -206,21 +212,19 @@ class LoginFragment : Fragment(), LoginView { ...@@ -206,21 +212,19 @@ class LoginFragment : Fragment(), LoginView {
TextHelper.addLink(text_new_to_rocket_chat, arrayOf(signUp), arrayOf(signUpListener)) TextHelper.addLink(text_new_to_rocket_chat, arrayOf(signUp), arrayOf(signUpListener))
} }
*/
private fun enableUserInput(value: Boolean) { private fun enableUserInput(value: Boolean) {
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()) { // if (isEditTextEmpty()) {
showSignUpView(value) // showSignUpView(value)
showOauthView(value) // showOauthView(value)
// }
} }
} /*
// Returns true if *all* EditTexts are empty. // Returns true if *all* EditTexts are empty.
private fun isEditTextEmpty(): Boolean { private fun isEditTextEmpty(): Boolean = text_username_or_email.textContent.isBlank() && text_password.textContent.isEmpty()
return text_username_or_email.textContent.isBlank() && text_password.textContent.isEmpty()
}
private fun showRemainingSocialAccountsView() { private fun showRemainingSocialAccountsView() {
social_accounts_container.postDelayed({ social_accounts_container.postDelayed({
...@@ -236,4 +240,5 @@ class LoginFragment : Fragment(), LoginView { ...@@ -236,4 +240,5 @@ class LoginFragment : Fragment(), LoginView {
scroll_view.fullScroll(ScrollView.FOCUS_DOWN) scroll_view.fullScroll(ScrollView.FOCUS_DOWN)
}, 1250) }, 1250)
} }
*/
} }
\ No newline at end of file
...@@ -11,10 +11,7 @@ import chat.rocket.android.R ...@@ -11,10 +11,7 @@ import chat.rocket.android.R
import chat.rocket.android.authentication.server.presentation.ServerPresenter 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.hintContent import chat.rocket.android.util.*
import chat.rocket.android.util.ifEmpty
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_server.* import kotlinx.android.synthetic.main.fragment_authentication_server.*
import javax.inject.Inject import javax.inject.Inject
...@@ -34,18 +31,12 @@ class ServerFragment : Fragment(), ServerView { ...@@ -34,18 +31,12 @@ class ServerFragment : Fragment(), ServerView {
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_authentication_server, container, false) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = container?.inflate(R.layout.fragment_authentication_server)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
relative_layout.viewTreeObserver.addOnGlobalLayoutListener(layoutListener) relative_layout.viewTreeObserver.addOnGlobalLayoutListener(layoutListener)
setupOnClickListener()
activity?.apply {
button_connect.setOnClickListener {
val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent)
presenter.connect(text_server_protocol.textContent + url)
}
}
} }
override fun onDestroyView() { override fun onDestroyView() {
...@@ -63,20 +54,21 @@ class ServerFragment : Fragment(), ServerView { ...@@ -63,20 +54,21 @@ class ServerFragment : Fragment(), ServerView {
enableUserInput(true) enableUserInput(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()
}
override fun showGenericErrorMessage() { override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
showMessage(getString(R.string.msg_generic_error))
}
override fun showNoInternetConnection() { override fun showNoInternetConnection() = showMessage(getString(R.string.msg_no_internet_connection))
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
}
private fun enableUserInput(value: Boolean) { private fun enableUserInput(value: Boolean) {
button_connect.isEnabled = value button_connect.isEnabled = value
text_server_url.isEnabled = value text_server_url.isEnabled = value
} }
private fun setupOnClickListener() {
button_connect.setOnClickListener {
val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent)
presenter.connect(text_server_protocol.textContent + url)
}
}
} }
\ No newline at end of file
...@@ -8,7 +8,7 @@ import android.support.v4.app.Fragment ...@@ -8,7 +8,7 @@ import android.support.v4.app.Fragment
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.authentication.twofactor.presentation.TwoFAPresenter import chat.rocket.android.authentication.twofactor.presentation.TwoFAPresenter
...@@ -22,7 +22,7 @@ import javax.inject.Inject ...@@ -22,7 +22,7 @@ import javax.inject.Inject
class TwoFAFragment : Fragment(), TwoFAView { class TwoFAFragment : Fragment(), TwoFAView {
@Inject lateinit var presenter: TwoFAPresenter @Inject lateinit var presenter: TwoFAPresenter
@Inject lateinit var appContext: Context @Inject lateinit var appContext: Context // TODO we really need it? Check alternatives...
companion object { companion object {
fun newInstance() = TwoFAFragment() fun newInstance() = TwoFAFragment()
...@@ -38,15 +38,16 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -38,15 +38,16 @@ class TwoFAFragment : Fragment(), TwoFAView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) activity?.apply {
text_two_factor_auth.requestFocus()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(text_two_factor_auth, InputMethodManager.SHOW_IMPLICIT)
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
tintEditTextDrawableStart() tintEditTextDrawableStart()
} }
setupOnClickListener()
button_log_in.setOnClickListener {
presenter.authenticate(text_two_factor_auth.textContent)
}
} }
override fun alertBlankTwoFactorAuthenticationCode() { override fun alertBlankTwoFactorAuthenticationCode() {
...@@ -54,9 +55,7 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -54,9 +55,7 @@ class TwoFAFragment : Fragment(), TwoFAView {
AnimationHelper.shakeView(text_two_factor_auth) AnimationHelper.shakeView(text_two_factor_auth)
} }
override fun alertInvalidTwoFactorAuthenticationCode() { override fun alertInvalidTwoFactorAuthenticationCode() = showMessage(getString(R.string.msg_invalid_2fa_code))
showMessage(getString(R.string.msg_invalid_2fa_code))
}
override fun showLoading() { override fun showLoading() {
enableUserInput(false) enableUserInput(false)
...@@ -68,22 +67,15 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -68,22 +67,15 @@ class TwoFAFragment : Fragment(), TwoFAView {
enableUserInput(true) enableUserInput(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()
}
override fun showGenericErrorMessage() { override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
showMessage(getString(R.string.msg_generic_error))
}
override fun showNoInternetConnection() { override fun showNoInternetConnection() = showMessage(getString(R.string.msg_no_internet_connection))
showMessage(getString(R.string.msg_no_internet_connection))
}
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
activity?.applicationContext?.apply { activity?.apply {
val lockDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_vpn_key_black_24dp, this) val lockDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_vpn_key_black_24dp, this)
DrawableHelper.wrapDrawable(lockDrawable) DrawableHelper.wrapDrawable(lockDrawable)
DrawableHelper.tintDrawable(lockDrawable, this, R.color.colorDrawableTintGrey) DrawableHelper.tintDrawable(lockDrawable, this, R.color.colorDrawableTintGrey)
DrawableHelper.compoundDrawable(text_two_factor_auth, lockDrawable) DrawableHelper.compoundDrawable(text_two_factor_auth, lockDrawable)
...@@ -94,4 +86,10 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -94,4 +86,10 @@ class TwoFAFragment : Fragment(), TwoFAView {
button_log_in.isEnabled = value button_log_in.isEnabled = value
text_two_factor_auth.isEnabled = value text_two_factor_auth.isEnabled = value
} }
private fun setupOnClickListener() {
button_log_in.setOnClickListener {
presenter.authenticate(text_two_factor_auth.textContent)
}
}
} }
\ No newline at end of file
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