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
6d8f41a2
Commit
6d8f41a2
authored
Dec 04, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logout
parent
54833820
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
2 deletions
+40
-2
AppUtils.java
app/src/main/java/com/testapp/AppUtils.java
+4
-0
LoginActivity.java
app/src/main/java/com/testapp/LoginActivity.java
+2
-1
NavDrawerActivity.java
app/src/main/java/com/testapp/NavDrawerActivity.java
+34
-1
No files found.
app/src/main/java/com/testapp/AppUtils.java
View file @
6d8f41a2
...
@@ -39,6 +39,10 @@ public class AppUtils {
...
@@ -39,6 +39,10 @@ public class AppUtils {
userId
=
-
1
;
userId
=
-
1
;
}
}
public
static
boolean
isLoggedIn
()
{
return
userId
!=
-
1
;
}
public
static
String
getUsername
()
{
public
static
String
getUsername
()
{
return
username
;
return
username
;
}
}
...
...
app/src/main/java/com/testapp/LoginActivity.java
View file @
6d8f41a2
...
@@ -116,6 +116,7 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -116,6 +116,7 @@ public class LoginActivity extends AppCompatActivity {
}
else
{
}
else
{
showProgress
(
true
);
showProgress
(
true
);
AppUtils
.
login
(
username
,
password
,
-
1
);
Call
<
Token
>
call
=
AppUtils
.
service
.
getToken
();
Call
<
Token
>
call
=
AppUtils
.
service
.
getToken
();
call
.
enqueue
(
new
Callback
<
Token
>()
{
call
.
enqueue
(
new
Callback
<
Token
>()
{
@Override
@Override
...
@@ -126,7 +127,7 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -126,7 +127,7 @@ public class LoginActivity extends AppCompatActivity {
mPasswordView
.
setError
(
""
);
mPasswordView
.
setError
(
""
);
Toast
.
makeText
(
LoginActivity
.
this
,
"Invalid credentials!"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
LoginActivity
.
this
,
"Invalid credentials!"
,
Toast
.
LENGTH_LONG
).
show
();
}
else
{
}
else
{
Toast
.
makeText
(
LoginActivity
.
this
,
"Logged in as "
+
username
+
" successfully."
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
LoginActivity
.
this
,
"Logged in as "
+
AppUtils
.
getUsername
()
+
" successfully."
,
Toast
.
LENGTH_LONG
).
show
();
AppUtils
.
login
(
username
,
password
,
response
.
body
().
getId
());
AppUtils
.
login
(
username
,
password
,
response
.
body
().
getId
());
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
NavDrawerActivity
.
class
);
Intent
intent
=
new
Intent
(
LoginActivity
.
this
,
NavDrawerActivity
.
class
);
startActivity
(
intent
);
startActivity
(
intent
);
...
...
app/src/main/java/com/testapp/NavDrawerActivity.java
View file @
6d8f41a2
package
com
.
testapp
;
package
com
.
testapp
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.design.widget.FloatingActionButton
;
...
@@ -17,9 +20,13 @@ import android.view.Menu;
...
@@ -17,9 +20,13 @@ import android.view.Menu;
import
android.view.MenuItem
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView
;
import
android.widget.Button
;
import
android.widget.CheckBox
;
import
android.widget.CheckBox
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.ListView
;
import
android.widget.ListView
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.Filter
;
import
com.testapp.entities.Filter
;
...
@@ -27,6 +34,7 @@ import com.testapp.entities.Filter;
...
@@ -27,6 +34,7 @@ import com.testapp.entities.Filter;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Response
;
...
@@ -88,7 +96,32 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
...
@@ -88,7 +96,32 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
}
}
});
});
RelativeLayout
loggedInHeader
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
logged_in_header
);
if
(
AppUtils
.
isLoggedIn
())
{
loggedInHeader
.
setVisibility
(
View
.
VISIBLE
);
((
TextView
)
findViewById
(
R
.
id
.
greeting
)).
setText
(
"Hello, "
+
AppUtils
.
getUsername
());
findViewById
(
R
.
id
.
logout_button
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
final
Activity
context
=
NavDrawerActivity
.
this
;
new
AlertDialog
.
Builder
(
context
)
.
setTitle
(
"Logout"
)
.
setMessage
(
"Are you sure you want to log out?"
)
.
setPositiveButton
(
R
.
string
.
yes
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
AppUtils
.
logout
();
Intent
i
=
new
Intent
(
context
,
LoginActivity
.
class
);
context
.
startActivity
(
i
);
}
})
.
setNegativeButton
(
R
.
string
.
no
,
null
)
.
show
();
}
});
}
else
{
loggedInHeader
.
setVisibility
(
View
.
GONE
);
}
}
}
public
<
T
extends
Filter
>
void
populateFilter
(
Call
<
List
<
T
>>
call
,
int
layout_id
)
{
public
<
T
extends
Filter
>
void
populateFilter
(
Call
<
List
<
T
>>
call
,
int
layout_id
)
{
...
...
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