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
c20d33d3
Commit
c20d33d3
authored
Dec 04, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add deleting reviews
parent
b63e073a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
36 deletions
+110
-36
CanteeneoApiInterface.java
app/src/main/java/com/testapp/CanteeneoApiInterface.java
+4
-0
DishReviewAdapter.java
app/src/main/java/com/testapp/DishReviewAdapter.java
+64
-3
DishViewActivity.java
app/src/main/java/com/testapp/DishViewActivity.java
+8
-26
content_dish_view.xml
app/src/main/res/layout/content_dish_view.xml
+0
-7
review_row.xml
app/src/main/res/layout/review_row.xml
+30
-0
colors.xml
app/src/main/res/values/colors.xml
+1
-0
dimens.xml
app/src/main/res/values/dimens.xml
+1
-0
strings.xml
app/src/main/res/values/strings.xml
+2
-0
No files found.
app/src/main/java/com/testapp/CanteeneoApiInterface.java
View file @
c20d33d3
...
@@ -17,6 +17,7 @@ import okhttp3.ResponseBody;
...
@@ -17,6 +17,7 @@ import okhttp3.ResponseBody;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.http.Body
;
import
retrofit2.http.Body
;
import
retrofit2.http.DELETE
;
import
retrofit2.http.Field
;
import
retrofit2.http.Field
;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.GET
;
import
retrofit2.http.GET
;
...
@@ -61,6 +62,9 @@ public interface CanteeneoApiInterface {
...
@@ -61,6 +62,9 @@ public interface CanteeneoApiInterface {
@PUT
(
"api/dishes/{id}/reviews/{review_id}"
)
@PUT
(
"api/dishes/{id}/reviews/{review_id}"
)
Call
<
ResponseBody
>
editDishReview
(
@Path
(
"id"
)
int
id
,
@Path
(
"review_id"
)
int
review_id
,
@Body
DishReview
review
);
Call
<
ResponseBody
>
editDishReview
(
@Path
(
"id"
)
int
id
,
@Path
(
"review_id"
)
int
review_id
,
@Body
DishReview
review
);
@DELETE
(
"api/dishes/{id}/reviews/{review_id}"
)
Call
<
ResponseBody
>
deleteDishReview
(
@Path
(
"id"
)
int
id
,
@Path
(
"review_id"
)
int
review_id
);
@GET
(
"api/dishes/{id}/reviews"
)
@GET
(
"api/dishes/{id}/reviews"
)
Call
<
List
<
DishReview
>>
getDishReviews
(
@Path
(
"id"
)
int
id
);
Call
<
List
<
DishReview
>>
getDishReviews
(
@Path
(
"id"
)
int
id
);
...
...
app/src/main/java/com/testapp/DishReviewAdapter.java
View file @
c20d33d3
package
com
.
testapp
;
package
com
.
testapp
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.BaseAdapter
;
import
android.widget.Button
;
import
android.widget.RatingBar
;
import
android.widget.RatingBar
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.testapp.entities.DishReview
;
import
com.testapp.entities.DishReview
;
import
com.testapp.entities.StallReview
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
DishReviewAdapter
extends
BaseAdapter
{
public
class
DishReviewAdapter
extends
BaseAdapter
{
private
Activity
context
;
private
Activity
context
;
ArrayList
<
DishReview
>
dishReviews
;
ArrayList
<
DishReview
>
dishReviews
;
...
@@ -45,13 +53,66 @@ public class DishReviewAdapter extends BaseAdapter {
...
@@ -45,13 +53,66 @@ public class DishReviewAdapter extends BaseAdapter {
TextView
body
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
body
);
TextView
body
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
body
);
TextView
username
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
user
);
TextView
username
=
(
TextView
)
v
.
findViewById
(
R
.
id
.
user
);
DishReview
dr
=
dishReviews
.
get
(
position
);
final
DishReview
dr
=
dishReviews
.
get
(
position
);
title
.
setText
(
dr
.
getTitle
());
title
.
setText
(
dr
.
getTitle
());
rating
.
setRating
(
dr
.
getRating
());
rating
.
setRating
(
dr
.
getRating
());
body
.
setText
(
dr
.
getBody
());
body
.
setText
(
dr
.
getBody
());
username
.
setText
(
dr
.
getUser
());
Button
editButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
edit_button
);
Button
deleteButton
=
(
Button
)
v
.
findViewById
(
R
.
id
.
delete_button
);
if
(
dr
.
getUserId
()
==
AppUtils
.
userId
)
{
editButton
.
setVisibility
(
View
.
VISIBLE
);
editButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Activity
context
=
DishReviewAdapter
.
this
.
context
;
Intent
i
=
new
Intent
(
context
,
DishReviewActivity
.
class
);
i
.
putExtra
(
"ID"
,
dr
.
getUserId
());
i
.
putExtra
(
"REVIEW_ID"
,
dr
.
getId
());
i
.
putExtra
(
"EDITING"
,
true
);
i
.
putExtra
(
"EDIT_TITLE"
,
dr
.
getTitle
());
i
.
putExtra
(
"EDIT_BODY"
,
dr
.
getBody
());
i
.
putExtra
(
"EDIT_RATING"
,
dr
.
getRating
());
context
.
startActivityForResult
(
i
,
0
);
}
});
deleteButton
.
setVisibility
(
View
.
VISIBLE
);
deleteButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
final
DishViewActivity
context
=
(
DishViewActivity
)
DishReviewAdapter
.
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
.
deleteDishReview
(
dr
.
getDishId
(),
dr
.
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
.
getDishReviews
(
dr
.
getDishId
());
}
@Override
public
void
onFailure
(
Call
<
ResponseBody
>
call
,
Throwable
t
)
{
}
});
}
})
.
setNegativeButton
(
R
.
string
.
no
,
null
)
.
show
();
}
});
}
else
{
editButton
.
setVisibility
(
View
.
INVISIBLE
);
deleteButton
.
setVisibility
(
View
.
INVISIBLE
);
}
Toast
.
makeText
(
v
.
getContext
(),
dr
.
getBody
(),
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
v
.
getContext
(),
dr
.
getBody
(),
Toast
.
LENGTH_SHORT
).
show
();
// TODO set username
return
v
;
return
v
;
}
}
}
}
app/src/main/java/com/testapp/DishViewActivity.java
View file @
c20d33d3
...
@@ -33,8 +33,6 @@ public class DishViewActivity extends AppCompatActivity {
...
@@ -33,8 +33,6 @@ public class DishViewActivity extends AppCompatActivity {
private
int
id
;
private
int
id
;
private
DishReview
ownedReview
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -135,42 +133,26 @@ public class DishViewActivity extends AppCompatActivity {
...
@@ -135,42 +133,26 @@ public class DishViewActivity extends AppCompatActivity {
}
}
}
}
p
rivate
void
getDishReviews
(
int
id
)
{
p
ublic
void
getDishReviews
(
int
id
)
{
Call
<
List
<
DishReview
>>
call
=
AppUtils
.
service
.
getDishReviews
(
id
);
Call
<
List
<
DishReview
>>
call
=
AppUtils
.
service
.
getDishReviews
(
id
);
call
.
enqueue
(
new
Callback
<
List
<
DishReview
>>()
{
call
.
enqueue
(
new
Callback
<
List
<
DishReview
>>()
{
@Override
@Override
public
void
onResponse
(
Call
<
List
<
DishReview
>>
call
,
Response
<
List
<
DishReview
>>
response
)
{
public
void
onResponse
(
Call
<
List
<
DishReview
>>
call
,
Response
<
List
<
DishReview
>>
response
)
{
List
<
DishReview
>
newReviews
=
response
.
body
();
List
<
DishReview
>
newReviews
=
response
.
body
();
reviews
.
clear
();
DishReview
ownedReview
=
null
;
reviews
.
addAll
(
newReviews
);
for
(
DishReview
review:
newReviews
)
{
ownedReview
=
null
;
for
(
DishReview
review:
reviews
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
userId
)
{
if
(
review
.
getUserId
()
==
AppUtils
.
userId
)
{
ownedReview
=
review
;
ownedReview
=
review
;
break
;
}
}
}
}
reviews
.
clear
();
Button
editReviewBtn
=
(
Button
)
findViewById
(
R
.
id
.
edit_review_button
);
if
(
ownedReview
!=
null
)
{
if
(
ownedReview
!=
null
)
{
editReviewBtn
.
setVisibility
(
View
.
VISIBLE
);
newReviews
.
remove
(
ownedReview
);
editReviewBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
reviews
.
add
(
ownedReview
);
@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
);
}
}
reviews
.
addAll
(
newReviews
);
adapter
.
notifyDataSetChanged
();
adapter
.
notifyDataSetChanged
();
}
}
...
...
app/src/main/res/layout/content_dish_view.xml
View file @
c20d33d3
...
@@ -147,13 +147,6 @@
...
@@ -147,13 +147,6 @@
android:textSize=
"18sp"
android:textSize=
"18sp"
android:layout_weight=
"1"
/>
android:layout_weight=
"1"
/>
<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
<Button
android:layout_width=
"47dp"
android:layout_width=
"47dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
...
...
app/src/main/res/layout/review_row.xml
View file @
c20d33d3
...
@@ -42,4 +42,34 @@
...
@@ -42,4 +42,34 @@
android:layout_below=
"@+id/user"
android:layout_below=
"@+id/user"
android:layout_alignParentLeft=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
/>
android:layout_alignParentStart=
"true"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignTop=
"@+id/body"
android:layout_alignParentRight=
"true"
android:layout_alignParentEnd=
"true"
android:id=
"@+id/delete_button"
android:backgroundTint=
"@color/deleteTint"
android:background=
"@drawable/ic_clear_black_24dp"
android:textAllCaps=
"false"
android:elevation=
"0dp"
style=
"@style/Widget.AppCompat.Button.Borderless"
android:minHeight=
"@dimen/button_size"
android:minWidth=
"@dimen/button_size"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/edit_button"
android:background=
"@drawable/ic_mode_edit_black_24dp"
android:textAllCaps=
"false"
android:elevation=
"0dp"
style=
"@style/Widget.AppCompat.Button.Borderless"
android:minHeight=
"@dimen/button_size"
android:minWidth=
"@dimen/button_size"
android:layout_alignBaseline=
"@+id/delete_button"
android:layout_alignBottom=
"@+id/delete_button"
android:layout_toLeftOf=
"@+id/delete_button"
android:layout_toStartOf=
"@+id/delete_button"
/>
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
c20d33d3
...
@@ -3,4 +3,5 @@
...
@@ -3,4 +3,5 @@
<color
name=
"colorPrimary"
>
#3f51b5
</color>
<color
name=
"colorPrimary"
>
#3f51b5
</color>
<color
name=
"colorPrimaryDark"
>
#303F9F
</color>
<color
name=
"colorPrimaryDark"
>
#303F9F
</color>
<color
name=
"colorAccent"
>
#FF4081
</color>
<color
name=
"colorAccent"
>
#FF4081
</color>
<color
name=
"deleteTint"
>
#FF0000
</color>
</resources>
</resources>
app/src/main/res/values/dimens.xml
View file @
c20d33d3
...
@@ -6,4 +6,5 @@
...
@@ -6,4 +6,5 @@
<dimen
name=
"nav_header_vertical_spacing"
>
16dp
</dimen>
<dimen
name=
"nav_header_vertical_spacing"
>
16dp
</dimen>
<dimen
name=
"nav_header_height"
>
160dp
</dimen>
<dimen
name=
"nav_header_height"
>
160dp
</dimen>
<dimen
name=
"fab_margin"
>
16dp
</dimen>
<dimen
name=
"fab_margin"
>
16dp
</dimen>
<dimen
name=
"button_size"
>
24dp
</dimen>
</resources>
</resources>
app/src/main/res/values/strings.xml
View file @
c20d33d3
...
@@ -42,4 +42,6 @@
...
@@ -42,4 +42,6 @@
<string
name=
"title_activity_blahblah"
>
blahblah
</string>
<string
name=
"title_activity_blahblah"
>
blahblah
</string>
<string
name=
"title_activity_stall_view"
>
StallViewActivity
</string>
<string
name=
"title_activity_stall_view"
>
StallViewActivity
</string>
<string
name=
"title_activity_add_dish_review"
>
AddDishReviewActivity
</string>
<string
name=
"title_activity_add_dish_review"
>
AddDishReviewActivity
</string>
<string
name=
"yes"
>
Yes
</string>
<string
name=
"no"
>
No
</string>
</resources>
</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