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
fdf63cc3
Commit
fdf63cc3
authored
Dec 03, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add editing dish review functionality
parent
ad5aa333
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
21 deletions
+88
-21
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
CanteeneoApiInterface.java
app/src/main/java/com/testapp/CanteeneoApiInterface.java
+4
-0
DishReviewActivity.java
app/src/main/java/com/testapp/DishReviewActivity.java
+38
-9
DishViewActivity.java
app/src/main/java/com/testapp/DishViewActivity.java
+32
-4
DishReview.java
app/src/main/java/com/testapp/entities/DishReview.java
+4
-4
activity_add_review.xml
app/src/main/res/layout/activity_add_review.xml
+1
-1
content_add_review.xml
app/src/main/res/layout/content_add_review.xml
+1
-1
content_dish_view.xml
app/src/main/res/layout/content_dish_view.xml
+7
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
fdf63cc3
...
...
@@ -38,7 +38,7 @@
android:label=
"@string/title_activity_stall_view"
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".
Add
DishReviewActivity"
android:name=
".DishReviewActivity"
android:label=
"@string/title_activity_add_dish_review"
android:theme=
"@style/AppTheme"
/>
<activity
android:name=
".RegisterActivity"
>
...
...
app/src/main/java/com/testapp/CanteeneoApiInterface.java
View file @
fdf63cc3
...
...
@@ -21,6 +21,7 @@ import retrofit2.http.Field;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
import
retrofit2.http.PUT
;
import
retrofit2.http.Path
;
import
retrofit2.http.Query
;
...
...
@@ -57,6 +58,9 @@ public interface CanteeneoApiInterface {
@POST
(
"api/dishes/{id}/reviews"
)
Call
<
ResponseBody
>
newDishReview
(
@Path
(
"id"
)
int
id
,
@Body
DishReview
review
);
@PUT
(
"api/dishes/{id}/reviews/{review_id}"
)
Call
<
ResponseBody
>
editDishReview
(
@Path
(
"id"
)
int
id
,
@Path
(
"review_id"
)
int
review_id
,
@Body
DishReview
review
);
@GET
(
"api/dishes/{id}/reviews"
)
Call
<
List
<
DishReview
>>
getDishReviews
(
@Path
(
"id"
)
int
id
);
...
...
app/src/main/java/com/testapp/
Add
DishReviewActivity.java
→
app/src/main/java/com/testapp/DishReviewActivity.java
View file @
fdf63cc3
...
...
@@ -2,7 +2,6 @@ package com.testapp;
import
android.os.Bundle
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.design.widget.Snackbar
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
...
...
@@ -17,13 +16,16 @@ import retrofit2.Call;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
Add
DishReviewActivity
extends
AppCompatActivity
{
public
class
DishReviewActivity
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
);
...
...
@@ -31,14 +33,23 @@ public class AddDishReviewActivity extends AppCompatActivity {
Toolbar
toolbar
=
(
Toolbar
)
findViewById
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
setTitle
(
"Add Dish Review"
);
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 Dish 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 Dish Review"
);
}
id
=
getIntent
().
getIntExtra
(
"ID"
,
0
);
Toast
.
makeText
(
getApplicationContext
(),
id
+
""
,
Toast
.
LENGTH_SHORT
).
show
();
FloatingActionButton
fab
=
(
FloatingActionButton
)
findViewById
(
R
.
id
.
fab
);
fab
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -46,23 +57,26 @@ public class AddDishReviewActivity extends AppCompatActivity {
DishReview
rv
=
new
DishReview
();
rv
.
setTitle
(
title
.
getText
().
toString
());
rv
.
setBody
(
body
.
getText
().
toString
());
rv
.
setRating
(
(
int
)
rating
.
getRating
());
rv
.
setRating
(
rating
.
getRating
());
rv
.
setDishId
(
id
);
rv
.
setUserId
(
AppUtils
.
userId
);
sendReview
(
id
,
rv
);
if
(
editing
)
{
editReview
(
reviewId
,
rv
);
}
else
{
newReview
(
rv
);
}
}
});
}
p
rivate
void
sendReview
(
int
id
,
DishReview
rv
)
{
Call
<
ResponseBody
>
call
=
AppUtils
.
service
.
newDishReview
(
id
,
r
v
);
p
ublic
void
newReview
(
DishReview
review
)
{
Call
<
ResponseBody
>
call
=
AppUtils
.
service
.
newDishReview
(
id
,
r
eview
);
call
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
Call
<
ResponseBody
>
call
,
Response
<
ResponseBody
>
response
)
{
setResult
(
RESULT_OK
);
finish
();
}
@Override
...
...
@@ -72,4 +86,19 @@ public class AddDishReviewActivity extends AppCompatActivity {
});
}
public
void
editReview
(
int
reviewId
,
DishReview
review
)
{
Call
<
ResponseBody
>
call
=
AppUtils
.
service
.
editDishReview
(
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/DishViewActivity.java
View file @
fdf63cc3
...
...
@@ -33,6 +33,8 @@ public class DishViewActivity extends AppCompatActivity {
private
int
id
;
private
DishReview
ownedReview
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -104,7 +106,7 @@ public class DishViewActivity extends AppCompatActivity {
addReviewBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Intent
i
=
new
Intent
(
DishViewActivity
.
this
,
Add
DishReviewActivity
.
class
);
Intent
i
=
new
Intent
(
DishViewActivity
.
this
,
DishReviewActivity
.
class
);
i
.
putExtra
(
"ID"
,
id
);
startActivityForResult
(
i
,
0
);
}
...
...
@@ -126,7 +128,6 @@ public class DishViewActivity extends AppCompatActivity {
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
case
android
.
R
.
id
.
home
:
// app icon in action bar clicked; goto parent activity.
this
.
finish
();
return
true
;
default
:
...
...
@@ -142,12 +143,39 @@ public class DishViewActivity extends AppCompatActivity {
List
<
DishReview
>
newReviews
=
response
.
body
();
reviews
.
clear
();
reviews
.
addAll
(
newReviews
);
ownedReview
=
null
;
for
(
DishReview
review:
reviews
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
userId
)
{
ownedReview
=
review
;
}
}
Button
editReviewBtn
=
(
Button
)
findViewById
(
R
.
id
.
edit_review_button
);
if
(
ownedReview
!=
null
)
{
editReviewBtn
.
setVisibility
(
View
.
VISIBLE
);
editReviewBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Intent
i
=
new
Intent
(
DishViewActivity
.
this
,
DishReviewActivity
.
class
);
i
.
putExtra
(
"ID"
,
DishViewActivity
.
this
.
id
);
i
.
putExtra
(
"REVIEW_ID"
,
ownedReview
.
getId
());
i
.
putExtra
(
"EDITING"
,
true
);
i
.
putExtra
(
"EDIT_TITLE"
,
ownedReview
.
getTitle
());
i
.
putExtra
(
"EDIT_BODY"
,
ownedReview
.
getBody
());
i
.
putExtra
(
"EDIT_RATING"
,
ownedReview
.
getRating
());
startActivityForResult
(
i
,
0
);
}
});
}
else
{
editReviewBtn
.
setVisibility
(
View
.
INVISIBLE
);
}
adapter
.
notifyDataSetChanged
();
}
@Override
public
void
onFailure
(
Call
<
List
<
DishReview
>>
call
,
Throwable
t
)
{
}
});
}
...
...
@@ -156,7 +184,7 @@ public class DishViewActivity extends AppCompatActivity {
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
requestCode
==
0
)
{
if
(
resultCode
==
RESULT_OK
)
{
Toast
.
makeText
(
this
,
"Review
Added
"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
this
,
"Review
Posted!
"
,
Toast
.
LENGTH_SHORT
).
show
();
getDishReviews
(
id
);
}
}
...
...
app/src/main/java/com/testapp/entities/DishReview.java
View file @
fdf63cc3
...
...
@@ -5,14 +5,14 @@ public class DishReview {
int
id
;
String
title
;
String
body
;
in
t
rating
;
floa
t
rating
;
int
user_id
;
int
dish_id
;
public
DishReview
()
{
}
public
DishReview
(
int
id
,
String
title
,
String
body
,
in
t
rating
,
int
user_id
,
int
dish_id
)
{
public
DishReview
(
int
id
,
String
title
,
String
body
,
floa
t
rating
,
int
user_id
,
int
dish_id
)
{
this
.
id
=
id
;
this
.
title
=
title
;
this
.
body
=
body
;
...
...
@@ -33,9 +33,9 @@ public class DishReview {
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
int
getUserId
()
{
return
user_id
;
}
...
...
app/src/main/res/layout/activity_add_review.xml
View file @
fdf63cc3
...
...
@@ -5,7 +5,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:fitsSystemWindows=
"true"
tools:context=
"com.testapp.
Add
DishReviewActivity"
>
tools:context=
"com.testapp.DishReviewActivity"
>
<android.support.design.widget.AppBarLayout
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/content_add_review.xml
View file @
fdf63cc3
...
...
@@ -9,7 +9,7 @@
android:paddingRight=
"@dimen/activity_horizontal_margin"
android:paddingTop=
"@dimen/activity_vertical_margin"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:context=
"com.testapp.
Add
DishReviewActivity"
tools:context=
"com.testapp.DishReviewActivity"
tools:showIn=
"@layout/activity_add_review"
>
<EditText
...
...
app/src/main/res/layout/content_dish_view.xml
View file @
fdf63cc3
...
...
@@ -150,8 +150,14 @@
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/edit_review_button"
android:layout_marginRight=
"16dp"
android:text=
"Edit"
/>
<Button
android:layout_width=
"47dp"
android:layout_height=
"wrap_content"
android:id=
"@+id/add_review_button"
android:layout_weight=
"1"
android:text=
"+"
/>
</LinearLayout>
...
...
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