Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
d12d3c06
Commit
d12d3c06
authored
Dec 24, 2017
by
Aniket
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds error messages to sign up dialog edit texts
parent
6f80a3c4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
165 additions
and
110 deletions
+165
-110
UserRegistrationDialogFragment.java
...ragment/server_config/UserRegistrationDialogFragment.java
+165
-110
No files found.
app/src/main/java/chat/rocket/android/fragment/server_config/UserRegistrationDialogFragment.java
View file @
d12d3c06
...
...
@@ -4,14 +4,17 @@ import android.app.Dialog;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.TextInputEditText
;
import
android.support.design.widget.TextInputLayout
;
import
android.support.v4.app.DialogFragment
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Patterns
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.jakewharton.rxbinding2.widget.RxTextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.TextUtils
;
...
...
@@ -24,7 +27,13 @@ public class UserRegistrationDialogFragment extends DialogFragment {
private
String
username
;
private
String
email
;
private
String
password
;
private
TextInputEditText
txtUsername
;
private
TextInputEditText
txtEmail
;
private
TextInputEditText
txtPasswd
;
private
TextInputLayout
textInputUsername
;
private
TextInputLayout
textInputEmail
;
private
TextInputLayout
textInputPassword
;
private
View
waitingView
;
public
UserRegistrationDialogFragment
()
{
super
();
}
...
...
@@ -88,9 +97,8 @@ public class UserRegistrationDialogFragment extends DialogFragment {
View
dialog
=
LayoutInflater
.
from
(
getContext
())
.
inflate
(
R
.
layout
.
dialog_user_registration
,
null
,
false
);
final
TextView
txtUsername
=
(
TextView
)
dialog
.
findViewById
(
R
.
id
.
editor_username
);
final
TextView
txtEmail
=
(
TextView
)
dialog
.
findViewById
(
R
.
id
.
editor_email
);
final
TextView
txtPasswd
=
(
TextView
)
dialog
.
findViewById
(
R
.
id
.
editor_passwd
);
initViews
(
dialog
);
setUpRxBinders
();
if
(!
TextUtils
.
isEmpty
(
username
))
{
txtUsername
.
setText
(
username
);
...
...
@@ -102,17 +110,19 @@ public class UserRegistrationDialogFragment extends DialogFragment {
txtPasswd
.
setText
(
password
);
}
final
View
waitingView
=
dialog
.
findViewById
(
R
.
id
.
waiting
);
waitingView
.
setVisibility
(
View
.
GONE
);
dialog
.
findViewById
(
R
.
id
.
btn_register_user
).
setOnClickListener
(
view
->
{
view
.
setEnabled
(
false
);
dialog
.
findViewById
(
R
.
id
.
btn_register_user
).
setOnClickListener
(
registerButton
->
{
if
(
checkIfEditTextsEmpty
())
return
;
registerButton
.
setEnabled
(
false
);
registerButton
.
setAlpha
(
0.5f
);
waitingView
.
setVisibility
(
View
.
VISIBLE
);
username
=
txtUsername
.
getText
().
toString
();
email
=
txtEmail
.
getText
().
toString
();
password
=
txtPasswd
.
getText
().
toString
();
MethodCallHelper
methodCallHelper
=
new
MethodCallHelper
(
getContext
(),
hostname
);
methodCallHelper
.
registerUser
(
username
,
email
,
password
,
password
)
.
onSuccessTask
(
task
->
methodCallHelper
.
loginWithEmail
(
email
,
password
))
...
...
@@ -126,7 +136,7 @@ public class UserRegistrationDialogFragment extends DialogFragment {
if
(
task
.
isFaulted
())
{
Exception
exception
=
task
.
getError
();
showError
(
exception
.
getMessage
());
view
.
setEnabled
(
true
);
registerButton
.
setEnabled
(
true
);
waitingView
.
setVisibility
(
View
.
GONE
);
}
return
null
;
...
...
@@ -135,6 +145,51 @@ public class UserRegistrationDialogFragment extends DialogFragment {
return
dialog
;
}
private
void
initViews
(
View
dialog
)
{
txtUsername
=
dialog
.
findViewById
(
R
.
id
.
editor_username
);
txtEmail
=
dialog
.
findViewById
(
R
.
id
.
editor_email
);
txtPasswd
=
dialog
.
findViewById
(
R
.
id
.
editor_passwd
);
textInputEmail
=
dialog
.
findViewById
(
R
.
id
.
text_input_email
);
textInputUsername
=
dialog
.
findViewById
(
R
.
id
.
text_input_username
);
textInputPassword
=
dialog
.
findViewById
(
R
.
id
.
text_input_passwd
);
waitingView
=
dialog
.
findViewById
(
R
.
id
.
waiting
);
}
private
boolean
checkIfEditTextsEmpty
()
{
boolean
check
=
false
;
if
(
TextUtils
.
isEmpty
(
txtEmail
.
getText
().
toString
()))
{
textInputEmail
.
setError
(
"Enter an email address"
);
textInputEmail
.
setErrorEnabled
(
true
);
check
=
true
;
}
if
(
TextUtils
.
isEmpty
(
txtUsername
.
getText
().
toString
()))
{
textInputUsername
.
setError
(
"Enter a username"
);
textInputUsername
.
setErrorEnabled
(
true
);
check
=
true
;
}
if
(
TextUtils
.
isEmpty
(
txtPasswd
.
getText
().
toString
()))
{
textInputPassword
.
setError
(
"Enter a password"
);
textInputPassword
.
setErrorEnabled
(
true
);
check
=
true
;
}
return
check
;
}
private
void
setUpRxBinders
()
{
RxTextView
.
textChanges
(
txtUsername
).
subscribe
(
text
->
{
if
(!
TextUtils
.
isEmpty
(
text
)
&&
textInputUsername
.
isErrorEnabled
())
textInputUsername
.
setErrorEnabled
(
false
);
});
RxTextView
.
textChanges
(
txtEmail
).
subscribe
(
text
->
{
if
(!
TextUtils
.
isEmpty
(
text
)
&&
textInputEmail
.
isErrorEnabled
())
textInputEmail
.
setErrorEnabled
(
false
);
});
RxTextView
.
textChanges
(
txtPasswd
).
subscribe
(
text
->
{
if
(!
TextUtils
.
isEmpty
(
text
)
&&
textInputPassword
.
isErrorEnabled
())
textInputPassword
.
setErrorEnabled
(
false
);
});
}
private
void
showError
(
String
errMessage
)
{
Toast
.
makeText
(
getContext
(),
errMessage
,
Toast
.
LENGTH_SHORT
).
show
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment