mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 05:31:59 +00:00
Improve layout food detail
This commit is contained in:
@@ -350,7 +350,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
} else if(response.code() == 404){
|
||||
//Don't have user comment
|
||||
user_comment_layout.setVisibility(View.GONE);
|
||||
user_comment_layout.setVisibility(View.INVISIBLE);
|
||||
showUI();
|
||||
} else {
|
||||
Toast.makeText(FoodDetailActivity.this, "Có lỗi từ hệ thống! Mã lỗi: " + response.code(), Toast.LENGTH_SHORT).show();
|
||||
@@ -548,14 +548,14 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
EditText comment_content = dialog.findViewById(R.id.edit_text_comment);
|
||||
RotationRatingBar ratingBar = dialog.findViewById(R.id.rating_bar);
|
||||
RotationRatingBar ratingBarDialog = dialog.findViewById(R.id.rating_bar);
|
||||
Button confirm = dialog.findViewById(R.id.confirm_button);
|
||||
Button cancel = dialog.findViewById(R.id.cancel_button);
|
||||
|
||||
if(actionCode == EDIT_COMMENT){
|
||||
//Init data
|
||||
if(commentUser != null){
|
||||
ratingBar.setRating(commentUser.getRating());
|
||||
ratingBarDialog.setRating(commentUser.getRating());
|
||||
comment_content.setText(commentUser.getContent());
|
||||
}
|
||||
|
||||
@@ -568,8 +568,6 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -577,61 +575,18 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
|
||||
if(actionCode == CREATE_COMMENT){
|
||||
//Create comment
|
||||
Comment comment = new Comment(comment_content.getText().toString(), ratingBar.getRating(), Common.CURRENT_USER.getId());
|
||||
FoodApiToken.apiService.createComment(Integer.parseInt(foodId), comment).enqueue(new Callback<Comment>() {
|
||||
@Override
|
||||
public void onResponse(Call<Comment> call, Response<Comment> response) {
|
||||
if(response.code() == 201){
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã thêm bình luận thành công!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
//Init data
|
||||
getCommentUser();
|
||||
createComment(comment_content.getText().toString(), ratingBarDialog);
|
||||
|
||||
//Show comment layout and hide rating button when comment completed!
|
||||
user_comment_layout.setVisibility(View.VISIBLE);
|
||||
rating_button.setVisibility(View.GONE);
|
||||
dialog.dismiss();
|
||||
|
||||
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
Toast.makeText(FoodDetailActivity.this, "Lỗi hệ thống! Mã lỗi: " + response.code(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Comment> call, Throwable t) {
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã xuất hiện lỗi hệ thống!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} else if(actionCode == EDIT_COMMENT){
|
||||
//Edit comment
|
||||
if(commentUser != null){
|
||||
|
||||
//Create object comment
|
||||
Comment newComment = new Comment(comment_content.getText().toString(), ratingBar.getRating(), Common.CURRENT_USER.getId());
|
||||
editComment(comment_content.getText().toString(), ratingBarDialog);
|
||||
|
||||
FoodApiToken.apiService.updateComment(Integer.parseInt(foodId), commentUser.getId(), newComment).enqueue(new Callback<CustomResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<CustomResponse> call, Response<CustomResponse> response) {
|
||||
if(response.code() == 200){
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã cập nhật bình luận thành công!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
ratingBarComment.setRating(ratingBar.getRating());
|
||||
contentComment.setText(comment_content.getText().toString());
|
||||
|
||||
dialog.dismiss();
|
||||
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi hệ thống! Mã lỗi: " + response.code(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CustomResponse> call, Throwable t) {
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi kết nối đến hệ thống!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -641,6 +596,67 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void editComment(String content, RotationRatingBar ratingBarDialog) {
|
||||
//Create object comment
|
||||
Comment newComment = new Comment(content, ratingBarDialog.getRating(), Common.CURRENT_USER.getId());
|
||||
|
||||
FoodApiToken.apiService.updateComment(Integer.parseInt(foodId), commentUser.getId(), newComment).enqueue(new Callback<CustomResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<CustomResponse> call, Response<CustomResponse> response) {
|
||||
if(response.code() == 200){
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã cập nhật bình luận thành công!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
ratingBarComment.setRating(ratingBarDialog.getRating());
|
||||
contentComment.setText(content);
|
||||
|
||||
//Update information food
|
||||
progressLayout.setVisibility(View.VISIBLE);
|
||||
getFoodById(foodId);
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi hệ thống! Mã lỗi: " + response.code(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CustomResponse> call, Throwable t) {
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi kết nối đến hệ thống!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createComment(String content, RotationRatingBar ratingBarDialog){
|
||||
Comment comment = new Comment(content, ratingBarDialog.getRating(), Common.CURRENT_USER.getId());
|
||||
FoodApiToken.apiService.createComment(Integer.parseInt(foodId), comment).enqueue(new Callback<Comment>() {
|
||||
@Override
|
||||
public void onResponse(Call<Comment> call, Response<Comment> response) {
|
||||
if(response.code() == 201){
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã thêm bình luận thành công!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
//Init data
|
||||
getCommentUser();
|
||||
|
||||
//Show comment layout and hide rating button when comment completed!
|
||||
user_comment_layout.setVisibility(View.VISIBLE);
|
||||
rating_button.setVisibility(View.GONE);
|
||||
|
||||
//Update information food
|
||||
progressLayout.setVisibility(View.VISIBLE);
|
||||
getFoodById(foodId);
|
||||
|
||||
} else {
|
||||
Toast.makeText(FoodDetailActivity.this, "Lỗi hệ thống! Mã lỗi: " + response.code(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Comment> call, Throwable t) {
|
||||
Toast.makeText(FoodDetailActivity.this, "Đã xuất hiện lỗi hệ thống!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void deleteComment(){
|
||||
FoodApiToken.apiService.deleteComment(Integer.parseInt(foodId), commentUser.getId()).enqueue(new Callback<CustomResponse>() {
|
||||
@Override
|
||||
@@ -654,7 +670,11 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
|
||||
//Remove layout comment
|
||||
rating_button.setVisibility(View.VISIBLE);
|
||||
user_comment_layout.setVisibility(View.GONE);
|
||||
user_comment_layout.setVisibility(View.INVISIBLE);
|
||||
|
||||
//Update information food
|
||||
progressLayout.setVisibility(View.VISIBLE);
|
||||
getFoodById(foodId);
|
||||
|
||||
commentUser = null;
|
||||
}
|
||||
|
||||
@@ -129,6 +129,38 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rating_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/shop_name_text_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
>
|
||||
|
||||
<com.willy.ratingbar.ScaleRatingBar
|
||||
android:id="@+id/rating_bar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srb_starPadding="5dp"
|
||||
app:srb_clickable="false"
|
||||
app:srb_starWidth="22dp"
|
||||
app:srb_starHeight="22dp"
|
||||
app:srb_numStars="5"
|
||||
app:srb_scrollable="false"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/count_rating_text_view"
|
||||
android:textSize="13sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="235 đánh giá" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description_text_view"
|
||||
android:text="Mô tả"
|
||||
@@ -138,7 +170,7 @@
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/shop_name_text_view"
|
||||
app:layout_constraintTop_toBottomOf="@id/rating_layout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
@@ -152,54 +184,12 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rating_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
>
|
||||
<TextView
|
||||
android:text="Đánh giá:"
|
||||
android:textSize="17sp"
|
||||
android:textColor="@color/black"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="10dp"
|
||||
/>
|
||||
|
||||
<com.willy.ratingbar.ScaleRatingBar
|
||||
android:id="@+id/rating_bar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srb_starPadding="5dp"
|
||||
app:srb_clickable="false"
|
||||
android:layout_marginEnd="10dp"
|
||||
app:srb_starWidth="22dp"
|
||||
app:srb_starHeight="22dp"
|
||||
app:srb_numStars="5"
|
||||
app:srb_scrollable="false"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/count_rating_text_view"
|
||||
android:textSize="13sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="235 đánh giá" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/rating_layout"
|
||||
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
>
|
||||
|
||||
@@ -401,24 +391,13 @@
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<View
|
||||
android:id="@+id/line2"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="2dp"
|
||||
android:background="#c0c0c0"
|
||||
android:layout_marginTop="5dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/user_comment_layout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_comment"
|
||||
tools:listitem="@layout/item_comment"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/line2"
|
||||
app:layout_constraintTop_toBottomOf="@id/user_comment_layout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user