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
54833820
Commit
54833820
authored
Dec 04, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abstract user login/logout, add header in navbar
parent
53a89ce2
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
72 additions
and
32 deletions
+72
-32
AppUtils.java
app/src/main/java/com/testapp/AppUtils.java
+27
-3
DishReviewActivity.java
app/src/main/java/com/testapp/DishReviewActivity.java
+1
-1
DishReviewAdapter.java
app/src/main/java/com/testapp/DishReviewAdapter.java
+1
-1
DishViewActivity.java
app/src/main/java/com/testapp/DishViewActivity.java
+1
-1
LoginActivity.java
app/src/main/java/com/testapp/LoginActivity.java
+4
-6
NavDrawerActivity.java
app/src/main/java/com/testapp/NavDrawerActivity.java
+7
-17
StallReviewActivity.java
app/src/main/java/com/testapp/StallReviewActivity.java
+1
-1
StallReviewAdapter.java
app/src/main/java/com/testapp/StallReviewAdapter.java
+1
-1
StallViewActivity.java
app/src/main/java/com/testapp/StallViewActivity.java
+1
-1
activity_nav_drawer.xml
app/src/main/res/layout/activity_nav_drawer.xml
+28
-0
No files found.
app/src/main/java/com/testapp/AppUtils.java
View file @
54833820
...
@@ -23,9 +23,33 @@ import retrofit2.converter.gson.GsonConverterFactory;
...
@@ -23,9 +23,33 @@ import retrofit2.converter.gson.GsonConverterFactory;
public
class
AppUtils
{
public
class
AppUtils
{
public
static
CanteeneoApiInterface
service
;
public
static
CanteeneoApiInterface
service
;
private
static
Context
c
;
private
static
Context
c
;
public
static
String
username
=
""
;
private
static
String
username
=
""
;
public
static
String
password
=
""
;
private
static
String
password
=
""
;
public
static
int
userId
=
-
1
;
private
static
int
userId
=
-
1
;
public
static
void
login
(
String
_username
,
String
_password
,
int
_userId
)
{
username
=
_username
;
password
=
_password
;
userId
=
_userId
;
}
public
static
void
logout
()
{
username
=
""
;
password
=
""
;
userId
=
-
1
;
}
public
static
String
getUsername
()
{
return
username
;
}
public
static
String
getPassword
()
{
return
password
;
}
public
static
int
getUserId
()
{
return
userId
;
}
public
static
boolean
isNetworkAvailable
(
Context
c
)
{
public
static
boolean
isNetworkAvailable
(
Context
c
)
{
ConnectivityManager
connectivity
=(
ConnectivityManager
)
c
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
ConnectivityManager
connectivity
=(
ConnectivityManager
)
c
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
...
...
app/src/main/java/com/testapp/DishReviewActivity.java
View file @
54833820
...
@@ -59,7 +59,7 @@ public class DishReviewActivity extends AppCompatActivity {
...
@@ -59,7 +59,7 @@ public class DishReviewActivity extends AppCompatActivity {
rv
.
setBody
(
body
.
getText
().
toString
());
rv
.
setBody
(
body
.
getText
().
toString
());
rv
.
setRating
(
rating
.
getRating
());
rv
.
setRating
(
rating
.
getRating
());
rv
.
setDishId
(
id
);
rv
.
setDishId
(
id
);
rv
.
setUserId
(
AppUtils
.
userId
);
rv
.
setUserId
(
AppUtils
.
getUserId
()
);
if
(
editing
)
{
if
(
editing
)
{
editReview
(
reviewId
,
rv
);
editReview
(
reviewId
,
rv
);
...
...
app/src/main/java/com/testapp/DishReviewAdapter.java
View file @
54833820
...
@@ -61,7 +61,7 @@ public class DishReviewAdapter extends BaseAdapter {
...
@@ -61,7 +61,7 @@ public class DishReviewAdapter extends BaseAdapter {
Button
editButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
edit_button
);
Button
editButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
edit_button
);
Button
deleteButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
delete_button
);
Button
deleteButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
delete_button
);
if
(
dr
.
getUserId
()
==
AppUtils
.
userId
)
{
if
(
dr
.
getUserId
()
==
AppUtils
.
getUserId
()
)
{
editButton
.
setVisibility
(
View
.
VISIBLE
);
editButton
.
setVisibility
(
View
.
VISIBLE
);
editButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
editButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
...
...
app/src/main/java/com/testapp/DishViewActivity.java
View file @
54833820
...
@@ -141,7 +141,7 @@ public class DishViewActivity extends AppCompatActivity {
...
@@ -141,7 +141,7 @@ public class DishViewActivity extends AppCompatActivity {
List
<
DishReview
>
newReviews
=
response
.
body
();
List
<
DishReview
>
newReviews
=
response
.
body
();
DishReview
ownedReview
=
null
;
DishReview
ownedReview
=
null
;
for
(
DishReview
review:
newReviews
)
{
for
(
DishReview
review:
newReviews
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
userId
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
getUserId
()
)
{
ownedReview
=
review
;
ownedReview
=
review
;
break
;
break
;
}
}
...
...
app/src/main/java/com/testapp/LoginActivity.java
View file @
54833820
...
@@ -93,8 +93,8 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -93,8 +93,8 @@ public class LoginActivity extends AppCompatActivity {
mUsernameView
.
setError
(
null
);
mUsernameView
.
setError
(
null
);
mPasswordView
.
setError
(
null
);
mPasswordView
.
setError
(
null
);
String
username
=
mUsernameView
.
getText
().
toString
();
final
String
username
=
mUsernameView
.
getText
().
toString
();
String
password
=
mPasswordView
.
getText
().
toString
();
final
String
password
=
mPasswordView
.
getText
().
toString
();
boolean
cancel
=
false
;
boolean
cancel
=
false
;
View
focusView
=
null
;
View
focusView
=
null
;
...
@@ -116,8 +116,6 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -116,8 +116,6 @@ public class LoginActivity extends AppCompatActivity {
}
else
{
}
else
{
showProgress
(
true
);
showProgress
(
true
);
AppUtils
.
username
=
username
;
AppUtils
.
password
=
password
;
Call
<
Token
>
call
=
AppUtils
.
service
.
getToken
();
Call
<
Token
>
call
=
AppUtils
.
service
.
getToken
();
call
.
enqueue
(
new
Callback
<
Token
>()
{
call
.
enqueue
(
new
Callback
<
Token
>()
{
@Override
@Override
...
@@ -128,8 +126,8 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -128,8 +126,8 @@ 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 "
+
AppUtils
.
username
+
" successfully."
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
LoginActivity
.
this
,
"Logged in as "
+
username
+
" successfully."
,
Toast
.
LENGTH_LONG
).
show
();
AppUtils
.
userId
=
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 @
54833820
...
@@ -4,44 +4,32 @@ import android.content.Context;
...
@@ -4,44 +4,32 @@ import android.content.Context;
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
;
import
android.support.design.widget.Snackbar
;
import
android.support.v7.widget.SearchView
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.support.design.widget.NavigationView
;
import
android.support.design.widget.NavigationView
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.view.GravityCompat
;
import
android.support.v4.view.GravityCompat
;
import
android.support.v4.widget.DrawerLayout
;
import
android.support.v4.widget.DrawerLayout
;
import
android.support.v7.app.ActionBarDrawerToggle
;
import
android.support.v7.app.ActionBarDrawerToggle
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.SearchView
;
import
android.support.v7.widget.Toolbar
;
import
android.support.v7.widget.Toolbar
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView
;
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.Toast
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.testapp.entities.Cuisine
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.Dish
;
import
com.testapp.entities.DishType
;
import
com.testapp.entities.Filter
;
import
com.testapp.entities.Filter
;
import
com.testapp.entities.Location
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
okhttp3.Cache
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Response
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
public
class
NavDrawerActivity
extends
AppCompatActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
public
class
NavDrawerActivity
extends
AppCompatActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
...
@@ -99,6 +87,8 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
...
@@ -99,6 +87,8 @@ public class NavDrawerActivity extends AppCompatActivity implements NavigationVi
startActivity
(
i
);
startActivity
(
i
);
}
}
});
});
}
}
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
)
{
...
...
app/src/main/java/com/testapp/StallReviewActivity.java
View file @
54833820
...
@@ -60,7 +60,7 @@ public class StallReviewActivity extends AppCompatActivity {
...
@@ -60,7 +60,7 @@ public class StallReviewActivity extends AppCompatActivity {
rv
.
setBody
(
body
.
getText
().
toString
());
rv
.
setBody
(
body
.
getText
().
toString
());
rv
.
setRating
(
rating
.
getRating
());
rv
.
setRating
(
rating
.
getRating
());
rv
.
setStallId
(
id
);
rv
.
setStallId
(
id
);
rv
.
setUserId
(
AppUtils
.
userId
);
rv
.
setUserId
(
AppUtils
.
getUserId
()
);
if
(
editing
)
{
if
(
editing
)
{
editReview
(
reviewId
,
rv
);
editReview
(
reviewId
,
rv
);
...
...
app/src/main/java/com/testapp/StallReviewAdapter.java
View file @
54833820
...
@@ -61,7 +61,7 @@ public class StallReviewAdapter extends BaseAdapter {
...
@@ -61,7 +61,7 @@ public class StallReviewAdapter extends BaseAdapter {
Button
editButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
edit_button
);
Button
editButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
edit_button
);
Button
deleteButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
delete_button
);
Button
deleteButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
delete_button
);
if
(
sr
.
getUserId
()
==
AppUtils
.
userId
)
{
if
(
sr
.
getUserId
()
==
AppUtils
.
getUserId
()
)
{
editButton
.
setVisibility
(
View
.
VISIBLE
);
editButton
.
setVisibility
(
View
.
VISIBLE
);
editButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
editButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
...
...
app/src/main/java/com/testapp/StallViewActivity.java
View file @
54833820
...
@@ -178,7 +178,7 @@ public class StallViewActivity extends AppCompatActivity {
...
@@ -178,7 +178,7 @@ public class StallViewActivity extends AppCompatActivity {
List
<
StallReview
>
newReviews
=
response
.
body
();
List
<
StallReview
>
newReviews
=
response
.
body
();
StallReview
ownedReview
=
null
;
StallReview
ownedReview
=
null
;
for
(
StallReview
review:
newReviews
)
{
for
(
StallReview
review:
newReviews
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
userId
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
getUserId
()
)
{
ownedReview
=
review
;
ownedReview
=
review
;
break
;
break
;
}
}
...
...
app/src/main/res/layout/activity_nav_drawer.xml
View file @
54833820
...
@@ -35,6 +35,34 @@
...
@@ -35,6 +35,34 @@
android:id=
"@+id/header"
android:id=
"@+id/header"
/>
/>
<RelativeLayout
android:id=
"@+id/logged_in_header"
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<Button
android:id=
"@+id/logout_button"
android:text=
"Log Out"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentRight=
"true"
style=
"@style/Widget.AppCompat.Button.Borderless.Colored"
/>
<TextView
android:id=
"@+id/greeting"
android:text=
"Hello, Willard"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textSize=
"24sp"
android:layout_centerVertical=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_marginLeft=
"10dp"
android:layout_marginStart=
"10dp"
/>
</RelativeLayout>
<Space
<Space
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"10dp"
/>
android:layout_height=
"10dp"
/>
...
...
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