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

Merge pull request #597 from filipedelimabrito/layout/bug-authentication-screen

[LAYOUT][V2] Fix bug on login authentication screen and improve code.
parents 6a2607df ca271939
......@@ -11,6 +11,6 @@ class AuthenticationActivity : BaseActivity() {
setContentView(R.layout.activity_authentication)
LayoutHelper.androidBug5497Workaround(this)
addFragment(AuthenticationLoginFragment(), "authenticationServerFragment", R.id.fragment_container)
addFragment(AuthenticationSignUpFragment(), "authenticationSignUpFragment", R.id.fragment_container)
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package chat.rocket.android.app
import DrawableHelper
import android.app.Fragment
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
......@@ -28,13 +27,13 @@ class AuthenticationLoginFragment : Fragment() {
// Just an example: if the server allow the login via social accounts (oauth authentication) then show the respective interface.
shouldShowOauthView(true)
// In this case we need to setup the text_username_or_email and text_password EditText to hide and show the oauth interface when the user touch the respective fields.
setupEditTextListener()
// In this case 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 and text_password EditText).
setupGlobalLayoutListener()
// Show the first three social account's ImageButton (REMARK: we must show at maximum *three* views)
showLoginUsingFacebookImagebutton()
showLoginUsingGithubImagebutton()
showLoginUsingGoogleImagebutton()
showLoginUsingFacebookImageButton()
showLoginUsingGithubImageButton()
showLoginUsingGoogleImageButton()
// Setup the FloatingActionButton to show more social account's ImageButton (it expands the social accounts interface to show more views).
setupFabListener()
......@@ -43,22 +42,6 @@ class AuthenticationLoginFragment : Fragment() {
shouldShowSignUpMsgView(true)
}
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
if (KeyboardHelper.isHardKeyboardShown(newConfig)) {
shouldShowOauthView(false)
shouldShowSignUpMsgView(false)
shouldShowLoginButton(true)
} else {
if (isEditTextNullOrBlank()) {
shouldShowOauthView(true)
shouldShowSignUpMsgView(true)
shouldShowLoginButton(false)
}
}
}
private fun tintEditTextDrawableStart() {
val context = activity.applicationContext
......@@ -71,23 +54,9 @@ class AuthenticationLoginFragment : Fragment() {
DrawableHelper.compoundDrawables(arrayOf(text_username_or_email, text_password), drawables)
}
private fun setupEditTextListener() {
text_username_or_email.viewTreeObserver.addOnGlobalLayoutListener({
if (KeyboardHelper.isSoftKeyboardShown(text_username_or_email.rootView)) {
shouldShowOauthView(false)
shouldShowSignUpMsgView(false)
shouldShowLoginButton(true)
} else {
if (isEditTextNullOrBlank()) {
shouldShowOauthView(true)
shouldShowSignUpMsgView(true)
shouldShowLoginButton(false)
}
}
})
text_password.viewTreeObserver.addOnGlobalLayoutListener({
if (KeyboardHelper.isSoftKeyboardShown(text_password.rootView)) {
private fun setupGlobalLayoutListener() {
scroll_view.viewTreeObserver.addOnGlobalLayoutListener({
if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) {
shouldShowOauthView(false)
shouldShowSignUpMsgView(false)
shouldShowLoginButton(true)
......@@ -127,40 +96,40 @@ class AuthenticationLoginFragment : Fragment() {
}
}
private fun showLoginUsingFacebookImagebutton() {
private fun showLoginUsingFacebookImageButton() {
button_facebook.visibility = View.VISIBLE
}
private fun showLoginUsingGithubImagebutton() {
private fun showLoginUsingGithubImageButton() {
button_github.visibility = View.VISIBLE
}
private fun showLoginUsingGoogleImagebutton() {
private fun showLoginUsingGoogleImageButton() {
button_google.visibility = View.VISIBLE
}
private fun showLoginUsingLinkedinImagebutton() {
private fun showLoginUsingLinkedinImageButton() {
button_linkedin.visibility = View.VISIBLE
}
private fun showLoginUsingMeteorImagebutton() {
private fun showLoginUsingMeteorImageButton() {
button_meteor.visibility = View.VISIBLE
}
private fun showLoginUsingTwitterImagebutton() {
private fun showLoginUsingTwitterImageButton() {
button_twitter.visibility = View.VISIBLE
}
private fun showLoginUsingGitlabImagebutton() {
private fun showLoginUsingGitlabImageButton() {
button_gitlab.visibility = View.VISIBLE
}
private fun setupFabListener() {
button_fab.setOnClickListener({
showLoginUsingLinkedinImagebutton()
showLoginUsingMeteorImagebutton()
showLoginUsingTwitterImagebutton()
showLoginUsingGitlabImagebutton()
showLoginUsingLinkedinImageButton()
showLoginUsingMeteorImageButton()
showLoginUsingTwitterImageButton()
showLoginUsingGitlabImageButton()
scrollToBottom()
hideFab()
......@@ -173,10 +142,14 @@ class AuthenticationLoginFragment : Fragment() {
}
private fun scrollToBottom() {
scroll_view.postDelayed({ scroll_view.fullScroll(ScrollView.FOCUS_DOWN); }, 1000)
scroll_view.postDelayed({
scroll_view.fullScroll(ScrollView.FOCUS_DOWN)
}, 1000)
}
private fun hideFab() {
button_fab.postDelayed({button_fab.hide() }, 1500)
button_fab.postDelayed({
button_fab.hide()
}, 1500)
}
}
\ No newline at end of file
......@@ -23,6 +23,8 @@ class AuthenticationSignUpFragment : Fragment() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
tintEditTextDrawableStart()
}
setupGlobalLayoutListener()
}
private fun tintEditTextDrawableStart() {
......@@ -38,4 +40,14 @@ class AuthenticationSignUpFragment : Fragment() {
DrawableHelper.tintDrawables(drawables, context, R.color.colorDrawableTintGrey)
DrawableHelper.compoundDrawables(arrayOf(text_name, text_username, text_password, text_email), drawables)
}
private fun setupGlobalLayoutListener() {
constraint_layout.viewTreeObserver.addOnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(constraint_layout.rootView)) {
text_new_user_agreement.visibility = View.GONE
} else {
text_new_user_agreement.visibility = View.VISIBLE
}
}
}
}
\ No newline at end of file
package chat.rocket.android.app
import android.content.res.Configuration
import android.graphics.Rect
import android.view.View
......@@ -22,17 +21,4 @@ object KeyboardHelper {
val heightDiff = rootView.bottom - rect.bottom
return heightDiff > softKeyboardHeight * dm.density
}
/**
* Returns true if the hard keyboard is shown, false otherwise.
*
* @param newConfig The configuration.
* @return true if the hard keyboard is shown, false otherwise.
*/
fun isHardKeyboardShown(newConfig: Configuration?): Boolean {
if (newConfig?.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
return true
}
return false
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
......
......@@ -11,6 +11,7 @@
<item name="android:maxLines">1</item>
<item name="android:drawablePadding">@dimen/edit_text_drawable_padding</item>
<item name="android:drawableTint">@color/colorDrawableTintGrey</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:background">@drawable/style_edit_text</item>
</style>
......
......@@ -32,6 +32,7 @@
<item name="android:paddingEnd">@dimen/edit_text_margin</item>
<item name="android:maxLines">1</item>
<item name="android:drawablePadding">@dimen/edit_text_drawable_padding</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:background">@drawable/style_edit_text</item>
</style>
......
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