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
53a89ce2
Commit
53a89ce2
authored
Dec 04, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement favorites and reviews for stalls, improve scrolling on dish ListView
parent
08204b59
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
410 additions
and
122 deletions
+410
-122
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+5
-1
CanteeneoApiInterface.java
app/src/main/java/com/testapp/CanteeneoApiInterface.java
+7
-0
DishAdapter.java
app/src/main/java/com/testapp/DishAdapter.java
+21
-8
DishReviewAdapter.java
app/src/main/java/com/testapp/DishReviewAdapter.java
+0
-1
StallReviewActivity.java
app/src/main/java/com/testapp/StallReviewActivity.java
+105
-0
StallReviewAdapter.java
app/src/main/java/com/testapp/StallReviewAdapter.java
+69
-6
StallViewActivity.java
app/src/main/java/com/testapp/StallViewActivity.java
+39
-3
StallReview.java
app/src/main/java/com/testapp/entities/StallReview.java
+8
-4
activity_add_review.xml
app/src/main/res/layout/activity_add_review.xml
+1
-1
content_stall_view.xml
app/src/main/res/layout/content_stall_view.xml
+153
-97
strings.xml
app/src/main/res/values/strings.xml
+2
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
53a89ce2
...
...
@@ -31,7 +31,7 @@
android:theme=
"@style/AppTheme.NoActionBar"
/>
<activity
android:name=
".DishViewActivity"
android:label=
"@string/title_activity_
blahblah
"
android:label=
"@string/title_activity_
dish_view
"
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".StallViewActivity"
...
...
@@ -41,6 +41,10 @@
android:name=
".DishReviewActivity"
android:label=
"@string/title_activity_add_dish_review"
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".StallReviewActivity"
android:label=
"@string/title_activity_add_stall_review"
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".RegisterActivity"
>
</activity>
</application>
...
...
app/src/main/java/com/testapp/CanteeneoApiInterface.java
View file @
53a89ce2
...
...
@@ -84,6 +84,13 @@ public interface CanteeneoApiInterface {
@POST
(
"api/stalls/{id}/reviews"
)
Call
<
ResponseBody
>
newStallReview
(
@Path
(
"id"
)
int
id
,
@Body
StallReview
review
);
@PUT
(
"api/stalls/{id}/reviews/{review_id}"
)
Call
<
ResponseBody
>
editStallReview
(
@Path
(
"id"
)
int
id
,
@Path
(
"review_id"
)
int
review_id
,
@Body
StallReview
review
);
@DELETE
(
"api/stalls/{id}/reviews/{review_id}"
)
Call
<
ResponseBody
>
deleteStallReview
(
@Path
(
"id"
)
int
id
,
@Path
(
"review_id"
)
int
review_id
);
@GET
(
"api/stalls/{id}/dishes"
)
Call
<
List
<
Dish
>>
getDishesByStall
(
@Path
(
"id"
)
int
id
);
...
...
app/src/main/java/com/testapp/DishAdapter.java
View file @
53a89ce2
...
...
@@ -36,16 +36,29 @@ public class DishAdapter extends BaseAdapter {
@Override
public
View
getView
(
int
position
,
View
convertView
,
ViewGroup
parent
)
{
View
v
=
context
.
getLayoutInflater
().
inflate
(
R
.
layout
.
dish_row
,
null
);
TextView
name
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
tvName
);
TextView
price
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
tvPrice
);
ImageView
image
=
(
ImageView
)
v
.
findViewById
(
R
.
id
.
iv
);
DishViewHolder
holder
;
if
(
convertView
==
null
)
{
convertView
=
context
.
getLayoutInflater
().
inflate
(
R
.
layout
.
dish_row
,
null
);
holder
=
new
DishViewHolder
();
holder
.
name
=
(
TextView
)
convertView
.
findViewById
(
R
.
id
.
tvName
);
holder
.
price
=
(
TextView
)
convertView
.
findViewById
(
R
.
id
.
tvPrice
);
holder
.
image
=
(
ImageView
)
convertView
.
findViewById
(
R
.
id
.
iv
);
convertView
.
setTag
(
holder
);
}
else
{
holder
=
(
DishViewHolder
)
convertView
.
getTag
();
}
Dish
d
=
dishes
.
get
(
position
);
name
.
setText
(
d
.
getName
());
price
.
setText
(
d
.
getPrice
()+
""
);
Picasso
.
with
(
context
).
load
(
"http://"
+
parent
.
getResources
().
getString
(
R
.
string
.
server_ip
)
+
":5000/static/uploads/"
+
d
.
getImagePath
()).
fit
().
centerCrop
().
into
(
image
);
holder
.
name
.
setText
(
d
.
getName
());
holder
.
price
.
setText
(
d
.
getPrice
()+
""
);
Picasso
.
with
(
context
).
load
(
"http://"
+
parent
.
getResources
().
getString
(
R
.
string
.
server_ip
)
+
":5000/static/uploads/"
+
d
.
getImagePath
()).
fit
().
centerCrop
().
tag
(
context
).
into
(
holder
.
image
);
return
v
;
return
convertView
;
}
static
class
DishViewHolder
{
TextView
name
;
TextView
price
;
ImageView
image
;
}
}
app/src/main/java/com/testapp/DishReviewAdapter.java
View file @
53a89ce2
...
...
@@ -112,7 +112,6 @@ public class DishReviewAdapter extends BaseAdapter {
deleteButton
.
setVisibility
(
View
.
INVISIBLE
);
}
Toast
.
makeText
(
v
.
getContext
(),
dr
.
getBody
(),
Toast
.
LENGTH_SHORT
).
show
();
return
v
;
}
}
app/src/main/java/com/testapp/StallReviewActivity.java
0 → 100644
View file @
53a89ce2
package
com
.
testapp
;
import
android.os.Bundle
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.RatingBar
;
import
android.widget.Toast
;
import
com.testapp.entities.DishReview
;
import
com.testapp.entities.StallReview
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
StallReviewActivity
extends
AppCompatActivity
{
private
EditText
title
;
private
EditText
body
;
private
RatingBar
rating
;
private
int
id
;
private
int
reviewId
;
private
boolean
editing
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_add_review
);
Toolbar
toolbar
=
(
Toolbar
)
findViewById
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
editing
=
getIntent
().
getBooleanExtra
(
"EDITING"
,
false
);
title
=
(
EditText
)
findViewById
(
R
.
id
.
rv_title
);
body
=
(
EditText
)
findViewById
(
R
.
id
.
rv_body
);
rating
=
(
RatingBar
)
findViewById
(
R
.
id
.
rv_rating
);
if
(
editing
)
{
setTitle
(
"Edit Stall Review"
);
reviewId
=
getIntent
().
getIntExtra
(
"REVIEW_ID"
,
0
);
title
.
setText
(
getIntent
().
getStringExtra
(
"EDIT_TITLE"
));
body
.
setText
(
getIntent
().
getStringExtra
(
"EDIT_BODY"
));
rating
.
setRating
(
getIntent
().
getFloatExtra
(
"EDIT_RATING"
,
0
f
));
}
else
{
setTitle
(
"Add Stall Review"
);
}
id
=
getIntent
().
getIntExtra
(
"ID"
,
0
);
FloatingActionButton
fab
=
(
FloatingActionButton
)
findViewById
(
R
.
id
.
fab
);
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
StallReview
rv
=
new
StallReview
();
rv
.
setTitle
(
title
.
getText
().
toString
());
rv
.
setBody
(
body
.
getText
().
toString
());
rv
.
setRating
(
rating
.
getRating
());
rv
.
setStallId
(
id
);
rv
.
setUserId
(
AppUtils
.
userId
);
if
(
editing
)
{
editReview
(
reviewId
,
rv
);
}
else
{
newReview
(
rv
);
}
}
});
}
public
void
newReview
(
StallReview
review
)
{
Call
<
ResponseBody
>
call
=
AppUtils
.
service
.
newStallReview
(
id
,
review
);
call
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
Call
<
ResponseBody
>
call
,
Response
<
ResponseBody
>
response
)
{
setResult
(
RESULT_OK
);
finish
();
}
@Override
public
void
onFailure
(
Call
<
ResponseBody
>
call
,
Throwable
t
)
{
Toast
.
makeText
(
getApplicationContext
(),
"Posting review failed"
,
Toast
.
LENGTH_SHORT
);
}
});
}
public
void
editReview
(
int
reviewId
,
StallReview
review
)
{
Call
<
ResponseBody
>
call
=
AppUtils
.
service
.
editStallReview
(
id
,
reviewId
,
review
);
call
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
Call
<
ResponseBody
>
call
,
Response
<
ResponseBody
>
response
)
{
setResult
(
RESULT_OK
);
finish
();
}
@Override
public
void
onFailure
(
Call
<
ResponseBody
>
call
,
Throwable
t
)
{
Toast
.
makeText
(
getApplicationContext
(),
"Editing review failed"
,
Toast
.
LENGTH_SHORT
);
}
});
}
}
app/src/main/java/com/testapp/StallReviewAdapter.java
View file @
53a89ce2
package
com
.
testapp
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.Button
;
import
android.widget.RatingBar
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.testapp.entities.StallReview
;
import
java.util.ArrayList
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
StallReviewAdapter
extends
BaseAdapter
{
private
Activity
context
;
ArrayList
<
StallReview
>
stallReviews
;
...
...
@@ -43,12 +53,65 @@ public class StallReviewAdapter extends BaseAdapter {
TextView
body
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
body
);
TextView
username
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
user
);
StallReview
dr
=
stallReviews
.
get
(
position
);
title
.
setText
(
dr
.
getTitle
());
rating
.
setRating
(
dr
.
getRating
());
body
.
setText
(
dr
.
getBody
());
username
.
setText
(
dr
.
getUser
());
// TODO set username
final
StallReview
sr
=
stallReviews
.
get
(
position
);
title
.
setText
(
sr
.
getTitle
());
rating
.
setRating
(
sr
.
getRating
());
body
.
setText
(
sr
.
getBody
());
username
.
setText
(
sr
.
getUser
());
Button
editButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
edit_button
);
Button
deleteButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
delete_button
);
if
(
sr
.
getUserId
()
==
AppUtils
.
userId
)
{
editButton
.
setVisibility
(
View
.
VISIBLE
);
editButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Activity
context
=
StallReviewAdapter
.
this
.
context
;
Intent
i
=
new
Intent
(
context
,
StallReviewActivity
.
class
);
i
.
putExtra
(
"ID"
,
sr
.
getUserId
());
i
.
putExtra
(
"REVIEW_ID"
,
sr
.
getId
());
i
.
putExtra
(
"EDITING"
,
true
);
i
.
putExtra
(
"EDIT_TITLE"
,
sr
.
getTitle
());
i
.
putExtra
(
"EDIT_BODY"
,
sr
.
getBody
());
i
.
putExtra
(
"EDIT_RATING"
,
sr
.
getRating
());
context
.
startActivityForResult
(
i
,
0
);
}
});
deleteButton
.
setVisibility
(
View
.
VISIBLE
);
deleteButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
final
StallViewActivity
context
=
(
StallViewActivity
)
StallReviewAdapter
.
this
.
context
;
new
AlertDialog
.
Builder
(
context
)
.
setTitle
(
"Confirm Delete"
)
.
setMessage
(
"Are you sure you want to delete your review? This cannot be undone."
)
.
setPositiveButton
(
R
.
string
.
yes
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Call
<
ResponseBody
>
call
=
AppUtils
.
service
.
deleteStallReview
(
sr
.
getStallId
(),
sr
.
getId
());
call
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
Call
<
ResponseBody
>
call
,
Response
<
ResponseBody
>
response
)
{
Toast
.
makeText
(
context
,
"Review deleted"
,
Toast
.
LENGTH_SHORT
).
show
();
context
.
getStallReviews
(
sr
.
getStallId
());
}
@Override
public
void
onFailure
(
Call
<
ResponseBody
>
call
,
Throwable
t
)
{
}
});
}
})
.
setNegativeButton
(
R
.
string
.
no
,
null
)
.
show
();
}
});
}
else
{
editButton
.
setVisibility
(
View
.
INVISIBLE
);
deleteButton
.
setVisibility
(
View
.
INVISIBLE
);
}
return
v
;
}
}
app/src/main/java/com/testapp/StallViewActivity.java
View file @
53a89ce2
...
...
@@ -7,10 +7,12 @@ import android.support.v7.widget.Toolbar;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.Button
;
import
android.widget.CheckBox
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.squareup.picasso.Picasso
;
import
com.testapp.entities.Dish
;
...
...
@@ -73,8 +75,8 @@ public class StallViewActivity extends AppCompatActivity {
location
.
setText
(
s
.
getLocation
());
TextView
description
=
(
TextView
)
findViewById
(
R
.
id
.
stall_description
);
description
.
setText
(
s
.
getDescription
());
ImageView
image
=
(
ImageView
)
findViewById
(
R
.
id
.
stall_logo
);
Picasso
.
with
(
getApplicationContext
()).
load
(
"http://"
+
getResources
().
getString
(
R
.
string
.
server_ip
)
+
":5000/static/uploads/"
+
s
.
getImagePath
()).
fit
().
centerCrop
().
into
(
image
);
//
ImageView image = (ImageView) findViewById(R.id.stall_logo);
//
Picasso.with(getApplicationContext()).load("http://" + getResources().getString(R.string.server_ip) + ":5000/static/uploads/"+ s.getImagePath()).fit().centerCrop().into(image);
favoriteCheckbox
=
(
CheckBox
)
findViewById
(
R
.
id
.
favorite_checkbox
);
favoriteCheckbox
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -108,6 +110,16 @@ public class StallViewActivity extends AppCompatActivity {
}
});
Button
addReviewBtn
=
(
Button
)
findViewById
(
R
.
id
.
add_review_button
);
addReviewBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Intent
i
=
new
Intent
(
StallViewActivity
.
this
,
StallReviewActivity
.
class
);
i
.
putExtra
(
"ID"
,
id
);
startActivityForResult
(
i
,
0
);
}
});
ListView
lvDishes
=
(
ListView
)
findViewById
(
R
.
id
.
stall_dishes
);
dAdapter
=
new
DishAdapter
(
StallViewActivity
.
this
,
dishes
);
getStallDishes
(
id
);
...
...
@@ -157,13 +169,27 @@ public class StallViewActivity extends AppCompatActivity {
}
});
}
private
void
getStallReviews
(
int
id
)
{
public
void
getStallReviews
(
int
id
)
{
Call
<
List
<
StallReview
>>
call
=
AppUtils
.
service
.
getStallReviews
(
id
);
call
.
enqueue
(
new
Callback
<
List
<
StallReview
>>()
{
@Override
public
void
onResponse
(
Call
<
List
<
StallReview
>>
call
,
Response
<
List
<
StallReview
>>
response
)
{
List
<
StallReview
>
newReviews
=
response
.
body
();
StallReview
ownedReview
=
null
;
for
(
StallReview
review:
newReviews
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
userId
)
{
ownedReview
=
review
;
break
;
}
}
reviews
.
clear
();
if
(
ownedReview
!=
null
)
{
newReviews
.
remove
(
ownedReview
);
reviews
.
add
(
ownedReview
);
}
findViewById
(
R
.
id
.
add_review_button
).
setVisibility
(
ownedReview
!=
null
?
View
.
INVISIBLE
:
View
.
VISIBLE
);
reviews
.
addAll
(
newReviews
);
srAdapter
.
notifyDataSetChanged
();
}
...
...
@@ -174,4 +200,14 @@ public class StallViewActivity extends AppCompatActivity {
}
});
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
requestCode
==
0
)
{
if
(
resultCode
==
RESULT_OK
)
{
Toast
.
makeText
(
this
,
"Review Posted!"
,
Toast
.
LENGTH_SHORT
).
show
();
getStallReviews
(
id
);
}
}
}
}
app/src/main/java/com/testapp/entities/StallReview.java
View file @
53a89ce2
...
...
@@ -5,12 +5,16 @@ public class StallReview {
int
id
;
String
title
;
String
body
;
in
t
rating
;
floa
t
rating
;
String
user
;
int
user_id
;
int
stall_id
;
public
StallReview
(
int
id
,
String
title
,
String
body
,
String
user
,
int
rating
,
int
user_id
,
int
stall_id
)
{
public
StallReview
()
{
}
public
StallReview
(
int
id
,
String
title
,
String
body
,
String
user
,
float
rating
,
int
user_id
,
int
stall_id
)
{
this
.
id
=
id
;
this
.
title
=
title
;
this
.
body
=
body
;
...
...
@@ -32,9 +36,9 @@ public class StallReview {
public
void
setBody
(
String
body
)
{
this
.
body
=
body
;
}
public
in
t
getRating
()
{
return
rating
;
}
public
floa
t
getRating
()
{
return
rating
;
}
public
void
setRating
(
in
t
rating
)
{
this
.
rating
=
rating
;
}
public
void
setRating
(
floa
t
rating
)
{
this
.
rating
=
rating
;
}
public
String
getUser
()
{
return
user
;
...
...
app/src/main/res/layout/activity_add_review.xml
View file @
53a89ce2
...
...
@@ -5,7 +5,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:fitsSystemWindows=
"true"
tools:context=
"com.testapp.
Dish
ReviewActivity"
>
tools:context=
"com.testapp.
Stall
ReviewActivity"
>
<android.support.design.widget.AppBarLayout
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/content_stall_view.xml
View file @
53a89ce2
This diff is collapsed.
Click to expand it.
app/src/main/res/values/strings.xml
View file @
53a89ce2
...
...
@@ -39,9 +39,10 @@
<item>
Item 222
</item>
<item>
Item 333
</item>
</string-array>
<string
name=
"title_activity_
blahblah"
>
blahblah
</string>
<string
name=
"title_activity_
dish_view"
>
DishViewActivity
</string>
<string
name=
"title_activity_stall_view"
>
StallViewActivity
</string>
<string
name=
"title_activity_add_dish_review"
>
AddDishReviewActivity
</string>
<string
name=
"title_activity_add_stall_review"
>
AddStallReviewActivity
</string>
<string
name=
"yes"
>
Yes
</string>
<string
name=
"no"
>
No
</string>
</resources>
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