Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-CanteeneoAndroid
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-CanteeneoAndroid
Commits
7b9c93e2
Commit
7b9c93e2
authored
Dec 01, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove AsyncTask from login, add proper messages
parent
e4ac1aeb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
56 deletions
+24
-56
LoginActivity.java
app/src/main/java/com/testapp/LoginActivity.java
+24
-56
No files found.
app/src/main/java/com/testapp/LoginActivity.java
View file @
7b9c93e2
...
...
@@ -27,8 +27,6 @@ import retrofit2.Response;
public
class
LoginActivity
extends
AppCompatActivity
{
private
UserLoginTask
mAuthTask
=
null
;
private
AutoCompleteTextView
mUsernameView
;
private
EditText
mPasswordView
;
private
View
mProgressView
;
...
...
@@ -92,10 +90,6 @@ public class LoginActivity extends AppCompatActivity {
}
private
void
attemptLogin
()
{
if
(
mAuthTask
!=
null
)
{
return
;
}
mUsernameView
.
setError
(
null
);
mPasswordView
.
setError
(
null
);
...
...
@@ -121,14 +115,34 @@ public class LoginActivity extends AppCompatActivity {
focusView
.
requestFocus
();
}
else
{
showProgress
(
true
);
mAuthTask
=
new
UserLoginTask
(
username
,
password
);
mAuthTask
.
execute
((
Void
)
null
);
Intent
intent
=
new
Intent
(
this
,
NavDrawerActivity
.
class
);
AppUtils
.
username
=
username
;
AppUtils
.
password
=
password
;
Call
<
Token
>
call
=
AppUtils
.
service
.
getToken
();
call
.
enqueue
(
new
Callback
<
Token
>()
{
@Override
public
void
onResponse
(
Call
<
Token
>
call
,
Response
<
Token
>
response
)
{
showProgress
(
false
);
if
(
response
.
code
()
==
401
)
{
mUsernameView
.
setError
(
""
);
mPasswordView
.
setError
(
""
);
Toast
.
makeText
(
LoginActivity
.
this
,
"Invalid credentials!"
,
Toast
.
LENGTH_LONG
).
show
();
}
else
{
Toast
.
makeText
(
LoginActivity
.
this
,
"Logged in as "
+
AppUtils
.
username
+
" successfully."
,
Toast
.
LENGTH_LONG
).
show
();
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
NavDrawerActivity
.
class
);
startActivity
(
intent
);
}
}
@Override
public
void
onFailure
(
Call
<
Token
>
call
,
Throwable
t
)
{
showProgress
(
false
);
Toast
.
makeText
(
LoginActivity
.
this
,
"Server failure, please try again. Message: "
+
t
.
getMessage
(),
Toast
.
LENGTH_LONG
);
}
});
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
HONEYCOMB_MR2
)
private
void
showProgress
(
final
boolean
show
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
HONEYCOMB_MR2
)
{
...
...
@@ -156,50 +170,4 @@ public class LoginActivity extends AppCompatActivity {
mLoginFormView
.
setVisibility
(
show
?
View
.
GONE
:
View
.
VISIBLE
);
}
}
public
class
UserLoginTask
extends
AsyncTask
<
Void
,
Void
,
Boolean
>
{
private
final
String
mUsername
;
private
final
String
mPassword
;
UserLoginTask
(
String
username
,
String
password
)
{
mUsername
=
username
;
mPassword
=
password
;
}
@Override
protected
Boolean
doInBackground
(
Void
...
params
)
{
AppUtils
.
username
=
mUsername
;
AppUtils
.
password
=
mPassword
;
Call
<
Token
>
call
=
AppUtils
.
service
.
getToken
();
call
.
enqueue
(
new
Callback
<
Token
>()
{
@Override
public
void
onResponse
(
Call
<
Token
>
call
,
Response
<
Token
>
response
)
{
Toast
.
makeText
(
LoginActivity
.
this
,
response
.
body
().
getToken
(),
Toast
.
LENGTH_LONG
).
show
();
}
@Override
public
void
onFailure
(
Call
<
Token
>
call
,
Throwable
t
)
{
}
});
return
true
;
}
@Override
protected
void
onPostExecute
(
final
Boolean
success
)
{
mAuthTask
=
null
;
showProgress
(
false
);
if
(
success
)
{
finish
();
}
}
@Override
protected
void
onCancelled
()
{
mAuthTask
=
null
;
showProgress
(
false
);
}
}
}
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