Commit 0fb0f006 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add useful methods to handle the social accounts interface.

parent 67cd9732
......@@ -8,6 +8,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.ScrollView
import chat.rocket.android.R
import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
......@@ -21,20 +23,41 @@ class AuthenticationLoginFragment : Fragment() {
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
tintEditTextDrawableStart()
}
// 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()
// Show the first three social account's ImageButton (REMARK: we must show at maximum *three* views)
showLoginUsingFacebookImagebutton()
showLoginUsingGithubImagebutton()
showLoginUsingGoogleImagebutton()
// Setup the FloatingActionButton to show more social account's ImageButton (it expands the social accounts interface to show more views).
setupFabListener()
// Just an example: if the server allow the new users registration then show the respective interface.
shouldShowSignUpMsgView(true)
}
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
if (KeyboardHelper.isHardKeyboardShown(newConfig)) {
shouldShowSocialAccountsAndSignUpMsgViews(false)
shouldShowOauthView(false)
shouldShowSignUpMsgView(false)
shouldShowLoginButton(true)
} else {
if (isEditTextNullOrBlank()) {
shouldShowSocialAccountsAndSignUpMsgViews(true)
shouldShowOauthView(true)
shouldShowSignUpMsgView(true)
shouldShowLoginButton(false)
}
}
}
......@@ -54,41 +77,110 @@ class AuthenticationLoginFragment : Fragment() {
private fun setupEditTextListener() {
text_username_or_email.viewTreeObserver.addOnGlobalLayoutListener({
if (KeyboardHelper.isSoftKeyboardShown(text_username_or_email.rootView)) {
shouldShowSocialAccountsAndSignUpMsgViews(false)
shouldShowOauthView(false)
shouldShowSignUpMsgView(false)
shouldShowLoginButton(true)
} else {
if (isEditTextNullOrBlank()) {
shouldShowSocialAccountsAndSignUpMsgViews(true)
shouldShowOauthView(true)
shouldShowSignUpMsgView(true)
shouldShowLoginButton(false)
}
}
})
text_password.viewTreeObserver.addOnGlobalLayoutListener({
if (KeyboardHelper.isSoftKeyboardShown(text_username_or_email.rootView)) {
shouldShowSocialAccountsAndSignUpMsgViews(false)
if (KeyboardHelper.isSoftKeyboardShown(text_password.rootView)) {
shouldShowOauthView(false)
shouldShowSignUpMsgView(false)
shouldShowLoginButton(true)
} else {
if (isEditTextNullOrBlank()) {
shouldShowSocialAccountsAndSignUpMsgViews(true)
shouldShowOauthView(true)
shouldShowSignUpMsgView(true)
shouldShowLoginButton(false)
}
}
})
}
private fun shouldShowSocialAccountsAndSignUpMsgViews(show: Boolean) {
private fun shouldShowOauthView(show: Boolean) {
if (show) {
social_accounts_container.visibility = View.VISIBLE
text_new_in_rocket_chat.visibility = View.VISIBLE
button_fab.visibility = View.VISIBLE
button_log_in.visibility = View.GONE
} else {
social_accounts_container.visibility = View.GONE
text_new_in_rocket_chat.visibility = View.GONE
button_fab.visibility = View.GONE
}
}
private fun shouldShowSignUpMsgView(show: Boolean) {
if (show) {
text_new_in_rocket_chat.visibility = View.VISIBLE
} else {
text_new_in_rocket_chat.visibility = View.GONE
}
}
private fun shouldShowLoginButton(show: Boolean) {
if (show) {
button_log_in.visibility = View.VISIBLE
} else {
button_log_in.visibility = View.GONE
}
}
private fun showLoginUsingFacebookImagebutton() {
button_facebook.visibility = View.VISIBLE
}
private fun showLoginUsingGithubImagebutton() {
button_github.visibility = View.VISIBLE
}
private fun showLoginUsingGoogleImagebutton() {
button_google.visibility = View.VISIBLE
}
private fun showLoginUsingLinkedinImagebutton() {
button_linkedin.visibility = View.VISIBLE
}
private fun showLoginUsingMeteorImagebutton() {
button_meteor.visibility = View.VISIBLE
}
private fun showLoginUsingTwitterImagebutton() {
button_twitter.visibility = View.VISIBLE
}
private fun showLoginUsingGitlabImagebutton() {
button_gitlab.visibility = View.VISIBLE
}
private fun setupFabListener() {
button_fab.setOnClickListener({
showLoginUsingLinkedinImagebutton()
showLoginUsingMeteorImagebutton()
showLoginUsingTwitterImagebutton()
showLoginUsingGitlabImagebutton()
scrollToBottom()
hideFab()
})
}
// Returns true if *all* EditText are null or blank.
private fun isEditTextNullOrBlank(): Boolean {
return text_username_or_email.text.isNullOrBlank() && text_password.text.isNullOrBlank()
}
private fun scrollToBottom() {
// scroll_view.postDelayed({ scroll_view.smoothScrollTo(0, view.top) }, 1000)
scroll_view.postDelayed({ scroll_view.fullScroll(ScrollView.FOCUS_DOWN); }, 1000)
}
private fun hideFab() {
button_fab.postDelayed({button_fab.hide() }, 1500)
}
}
\ 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