Unverified Commit 946aa43e authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #823 from samrmur/improve-layout

[IMPROVEMENT] Fixed Layout for Login Screen
parents b8e10260 e1e60b6f
...@@ -12,6 +12,7 @@ import android.view.ViewGroup ...@@ -12,6 +12,7 @@ import android.view.ViewGroup
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.ScrollView import android.widget.ScrollView
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.authentication.login.presentation.LoginPresenter import chat.rocket.android.authentication.login.presentation.LoginPresenter
import chat.rocket.android.authentication.login.presentation.LoginView import chat.rocket.android.authentication.login.presentation.LoginView
...@@ -22,6 +23,7 @@ import chat.rocket.android.util.extensions.inflate ...@@ -22,6 +23,7 @@ import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.setVisible import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_log_in.* import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import javax.inject.Inject import javax.inject.Inject
...@@ -31,18 +33,9 @@ class LoginFragment : Fragment(), LoginView { ...@@ -31,18 +33,9 @@ class LoginFragment : Fragment(), LoginView {
@Inject lateinit var appContext: Context // TODO we really need it? Check alternatives... @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)) { areLoginOptionsNeeded()
showSignUpView(false)
showOauthView(false)
showLoginButton(true)
} else {
if (isEditTextEmpty()) {
showSignUpView(true)
showOauthView(true)
showLoginButton(false)
}
}
} }
private var isGlobalLayoutListenerSetUp = false private var isGlobalLayoutListenerSetUp = false
companion object { companion object {
...@@ -74,15 +67,10 @@ class LoginFragment : Fragment(), LoginView { ...@@ -74,15 +67,10 @@ class LoginFragment : Fragment(), LoginView {
setupSignUpListener() setupSignUpListener()
} }
private fun showThreeSocialMethods() { override fun onViewStateRestored(savedInstanceState: Bundle?) {
var count = 0 super.onViewStateRestored(savedInstanceState)
for (i in 0..social_accounts_container.childCount) {
val view = social_accounts_container.getChildAt(i) as? ImageButton ?: continue areLoginOptionsNeeded()
if (view.isEnabled && count < 3) {
view.visibility = View.VISIBLE
count++
}
}
} }
override fun onDestroyView() { override fun onDestroyView() {
...@@ -179,6 +167,17 @@ class LoginFragment : Fragment(), LoginView { ...@@ -179,6 +167,17 @@ class LoginFragment : Fragment(), LoginView {
override fun showNoInternetConnection() = showMessage(getString(R.string.msg_no_internet_connection)) override fun showNoInternetConnection() = showMessage(getString(R.string.msg_no_internet_connection))
private fun areLoginOptionsNeeded() {
if (!isEditTextEmpty() || KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) {
showSignUpView(false)
showOauthView(false)
showLoginButton(true)
} else {
showSignUpView(true)
showOauthView(true)
showLoginButton(false)
}
}
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
activity?.apply { activity?.apply {
...@@ -213,10 +212,6 @@ class LoginFragment : Fragment(), LoginView { ...@@ -213,10 +212,6 @@ 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.
...@@ -231,6 +226,17 @@ class LoginFragment : Fragment(), LoginView { ...@@ -231,6 +226,17 @@ class LoginFragment : Fragment(), LoginView {
}, 1000) }, 1000)
} }
private fun showThreeSocialMethods() {
var count = 0
for (i in 0..social_accounts_container.childCount) {
val view = social_accounts_container.getChildAt(i) as? ImageButton ?: continue
if (view.isEnabled && count < 3) {
view.visibility = View.VISIBLE
count++
}
}
}
private fun scrollToBottom() { private fun scrollToBottom() {
scroll_view.postDelayed({ scroll_view.postDelayed({
scroll_view.fullScroll(ScrollView.FOCUS_DOWN) scroll_view.fullScroll(ScrollView.FOCUS_DOWN)
......
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