mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Add validate comment
This commit is contained in:
@@ -32,7 +32,7 @@ public interface FoodApi {
|
|||||||
Gson gson = new GsonBuilder().setDateFormat("HH:mm:ss dd-MM-yyyy").setLenient().create();
|
Gson gson = new GsonBuilder().setDateFormat("HH:mm:ss dd-MM-yyyy").setLenient().create();
|
||||||
|
|
||||||
FoodApi apiService = new Retrofit.Builder()
|
FoodApi apiService = new Retrofit.Builder()
|
||||||
.baseUrl("https://foodify-backend-production.up.railway.app/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
.baseUrl("http://192.168.1.183:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||||
.build()
|
.build()
|
||||||
.create(FoodApi.class);
|
.create(FoodApi.class);
|
||||||
|
|
||||||
@@ -93,4 +93,7 @@ public interface FoodApi {
|
|||||||
|
|
||||||
@GET("shops/{id}")
|
@GET("shops/{id}")
|
||||||
Call<Shop> getShopById(@Path("id") int id);
|
Call<Shop> getShopById(@Path("id") int id);
|
||||||
|
|
||||||
|
@GET("products/{productId}/user")
|
||||||
|
Call<CustomResponse> checkUserBuyProduct(@Path("productId") int productId, @Query("userId") int userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public interface FoodApiToken {
|
|||||||
|
|
||||||
FoodApiToken apiService = new Retrofit.Builder()
|
FoodApiToken apiService = new Retrofit.Builder()
|
||||||
.client(client)
|
.client(client)
|
||||||
.baseUrl("https://foodify-backend-production.up.railway.app/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
.baseUrl("http://192.168.1.183:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||||
.build()
|
.build()
|
||||||
.create(FoodApiToken.class);
|
.create(FoodApiToken.class);
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
|||||||
private static final int PAGE_SIZE = 8;
|
private static final int PAGE_SIZE = 8;
|
||||||
private static final String SORT_BY = "id";
|
private static final String SORT_BY = "id";
|
||||||
private static final String SORT_DIR = "asc";
|
private static final String SORT_DIR = "asc";
|
||||||
private static boolean LAST_PAGE;
|
private static boolean LAST_PAGE, IS_BUY;
|
||||||
private HorizontalQuantitizer horizontalQuantitizer;
|
private HorizontalQuantitizer horizontalQuantitizer;
|
||||||
private ImageSlider imageSlider;
|
private ImageSlider imageSlider;
|
||||||
private ImageView back_image, not_favorite, is_favorite, delete_button, edt_button;
|
private ImageView back_image, not_favorite, is_favorite, delete_button, edt_button;
|
||||||
@@ -149,6 +149,8 @@ public class FoodDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
hideUI();
|
hideUI();
|
||||||
|
|
||||||
|
checkUserBuyThisProduct();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(Common.CURRENT_USER == null){
|
if(Common.CURRENT_USER == null){
|
||||||
@@ -195,10 +197,16 @@ public class FoodDetailActivity extends AppCompatActivity {
|
|||||||
rating_button.setOnClickListener(new View.OnClickListener() {
|
rating_button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(Common.CURRENT_USER != null)
|
if(Common.CURRENT_USER != null){
|
||||||
openCommentDialog(Gravity.CENTER, CREATE_COMMENT);
|
if(IS_BUY){
|
||||||
else
|
//If user already buy it
|
||||||
startActivity(new Intent(FoodDetailActivity.this, SignInActivity.class));
|
openCommentDialog(Gravity.CENTER, CREATE_COMMENT);
|
||||||
|
} else {
|
||||||
|
//If not
|
||||||
|
Toast.makeText(FoodDetailActivity.this, "Bạn cần phải mua sản phẩm trước khi bình luận!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
Toast.makeText(FoodDetailActivity.this, "Bạn cần phải đăng nhập để thực hiện hành động này!", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -267,6 +275,29 @@ public class FoodDetailActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkUserBuyThisProduct(){
|
||||||
|
|
||||||
|
if(Common.CURRENT_USER != null){
|
||||||
|
FoodApi.apiService.checkUserBuyProduct(Integer.parseInt(foodId), Common.CURRENT_USER.getId()).enqueue(new Callback<CustomResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<CustomResponse> call, Response<CustomResponse> response) {
|
||||||
|
if(response.code() == 200){
|
||||||
|
|
||||||
|
IS_BUY = response.body().isTrue();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Toast.makeText(FoodDetailActivity.this, "Đã xảy ra 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, "Đã xảy ra lỗi kết nối đến hệ thống!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void isFavoriteIcon(){
|
private void isFavoriteIcon(){
|
||||||
not_favorite.setVisibility(View.GONE);
|
not_favorite.setVisibility(View.GONE);
|
||||||
is_favorite.setVisibility(View.VISIBLE);
|
is_favorite.setVisibility(View.VISIBLE);
|
||||||
|
|||||||
@@ -325,7 +325,7 @@
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/rating_button"
|
android:id="@+id/rating_button"
|
||||||
android:text="Đánh giá"
|
android:text="Bình luận"
|
||||||
android:backgroundTint="@color/yellow"
|
android:backgroundTint="@color/yellow"
|
||||||
android:textColor="@color/black"
|
android:textColor="@color/black"
|
||||||
android:fontFamily="@font/opensans"
|
android:fontFamily="@font/opensans"
|
||||||
|
|||||||
Reference in New Issue
Block a user