mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 05:31:59 +00:00
Merge home fragment to back-end API project
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:theme="@style/Theme.Foodify"
|
||||
tools:replace="android:theme"
|
||||
tools:targetApi="31">
|
||||
|
||||
@@ -3,7 +3,8 @@ package com.capstone.foodify.API;
|
||||
import com.capstone.foodify.Model.Category.Category;
|
||||
import com.capstone.foodify.Model.DistrictWard.DistrictWardResponse;
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.Model.Food.ImageFood;
|
||||
import com.capstone.foodify.Model.Response.Foods;
|
||||
import com.capstone.foodify.Model.Response.Shops;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
@@ -25,18 +26,21 @@ public interface FoodApi {
|
||||
Gson gson = new GsonBuilder().setDateFormat("HH:mm:ss dd-MM-yyyy").create();
|
||||
|
||||
FoodApi apiService = new Retrofit.Builder()
|
||||
.baseUrl("https://63eb52abbfdd4299674540d4.mockapi.io/api/v1/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl("http://10.0.2.2:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
.create(FoodApi.class);
|
||||
|
||||
@GET("randomProduct")
|
||||
Call<List<Food>> bestFoodResponse();
|
||||
@GET("products?pageNo=0&pageSize=10&sortBy=id&sortDir=asc")
|
||||
Call<Foods> recommendFood();
|
||||
|
||||
@GET("recommend")
|
||||
Call<List<Food>> drinksFoodResponse();
|
||||
@GET("products?pageNo=0&pageSize=10&sortBy=createdTime&sortDir=desc")
|
||||
Call<Foods> recentFood();
|
||||
|
||||
@GET("listFood")
|
||||
Call<List<Food>> listFood(@Query("search") String search, @Query("page") int page, @Query("limit") int limit);
|
||||
@GET("shops?pageNo=0&pageSize=10&sortBy=id&sortDir=asc")
|
||||
Call<Shops> allShops();
|
||||
|
||||
@GET("products/search/")
|
||||
Call<List<Food>> listFood(@Path("search") String search, @Query("pageNo") int pageNo, @Query("pageSize") int pageSize, @Query("sortBy") String sortBy, @Query("sortDir") String sortDir);
|
||||
|
||||
@GET("listFood")
|
||||
Call<List<Food>> listFood(@Query("page") int page, @Query("limit") int limit);
|
||||
@@ -50,8 +54,8 @@ public interface FoodApi {
|
||||
@GET("detail/{id}")
|
||||
Call<Food> detailFood(@Path("id") String id);
|
||||
|
||||
@GET("detail/{id}/image")
|
||||
Call<List<ImageFood>> getImageFoodById(@Path("id") String id);
|
||||
// @GET("detail/{id}/image")
|
||||
// Call<List<ImageFood>> getImageFoodById(@Path("id") String id);
|
||||
|
||||
@GET("district/{districtId}/ward")
|
||||
Call<List<DistrictWardResponse>> wardResponse(@Path("districtId") int district_id);
|
||||
|
||||
@@ -13,8 +13,6 @@ import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -27,7 +25,6 @@ import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Basket.Basket;
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.Model.Food.ImageFood;
|
||||
import com.capstone.foodify.Model.Review.Review;
|
||||
import com.capstone.foodify.Model.Review.ReviewAdapter;
|
||||
import com.capstone.foodify.R;
|
||||
@@ -41,10 +38,8 @@ import com.saadahmedsoft.popupdialog.PopupDialog;
|
||||
import com.saadahmedsoft.popupdialog.Styles;
|
||||
import com.willy.ratingbar.RotationRatingBar;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@@ -153,38 +148,38 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
add_to_basket_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(horizontalQuantitizer.getValue() > 0){
|
||||
Basket foodInBasket = getFoodExistInBasket(food.getId());
|
||||
if(foodInBasket == null){
|
||||
//If item is not exist in basket
|
||||
Common.LIST_BASKET_FOOD.add(new Basket(food.getId(), imageFood.get(0), food.getName(), food.getPrice(), "Shop Name",
|
||||
String.valueOf(horizontalQuantitizer.getValue()), "0"));
|
||||
Toast.makeText(FoodDetailActivity.this, "Thêm vào giỏ hàng thành công!", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(FoodDetailActivity.this, MainActivity.class));
|
||||
} else {
|
||||
//If item is exist in basket
|
||||
|
||||
for(int i = 0; i < Common.LIST_BASKET_FOOD.size(); i++){
|
||||
String foodId = Common.LIST_BASKET_FOOD.get(i).getId();
|
||||
//Find foodId exist
|
||||
if(foodId.equals(food.getId())){
|
||||
//Get quantity food from basket
|
||||
String quantity = Common.LIST_BASKET_FOOD.get(i).getQuantity();
|
||||
|
||||
//Change quantity food from basket
|
||||
int quantityInt = Integer.parseInt(quantity) + horizontalQuantitizer.getValue();
|
||||
Common.LIST_BASKET_FOOD.get(i).setQuantity(String.valueOf(quantityInt));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Toast.makeText(FoodDetailActivity.this, "Thêm vào giỏ hàng thành công!", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(FoodDetailActivity.this, MainActivity.class));
|
||||
}
|
||||
|
||||
} else {
|
||||
Toast.makeText(FoodDetailActivity.this, "Bạn chưa chọn số lượng đồ ăn cần đặt!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
// if(horizontalQuantitizer.getValue() > 0){
|
||||
// Basket foodInBasket = getFoodExistInBasket(food.getId());
|
||||
// if(foodInBasket == null){
|
||||
// //If item is not exist in basket
|
||||
// Common.LIST_BASKET_FOOD.add(new Basket(food.getId(), imageFood.get(0), food.getName(), food.getPrice(), "Shop Name",
|
||||
// String.valueOf(horizontalQuantitizer.getValue()), "0"));
|
||||
// Toast.makeText(FoodDetailActivity.this, "Thêm vào giỏ hàng thành công!", Toast.LENGTH_SHORT).show();
|
||||
// startActivity(new Intent(FoodDetailActivity.this, MainActivity.class));
|
||||
// } else {
|
||||
// //If item is exist in basket
|
||||
//
|
||||
// for(int i = 0; i < Common.LIST_BASKET_FOOD.size(); i++){
|
||||
// String foodId = Common.LIST_BASKET_FOOD.get(i).getId();
|
||||
// //Find foodId exist
|
||||
// if(foodId.equals(food.getId())){
|
||||
// //Get quantity food from basket
|
||||
// String quantity = Common.LIST_BASKET_FOOD.get(i).getQuantity();
|
||||
//
|
||||
// //Change quantity food from basket
|
||||
// int quantityInt = Integer.parseInt(quantity) + horizontalQuantitizer.getValue();
|
||||
// Common.LIST_BASKET_FOOD.get(i).setQuantity(String.valueOf(quantityInt));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Toast.makeText(FoodDetailActivity.this, "Thêm vào giỏ hàng thành công!", Toast.LENGTH_SHORT).show();
|
||||
// startActivity(new Intent(FoodDetailActivity.this, MainActivity.class));
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// Toast.makeText(FoodDetailActivity.this, "Bạn chưa chọn số lượng đồ ăn cần đặt!", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
@@ -227,23 +222,23 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initData(){
|
||||
price = Float.parseFloat(food.getPrice());
|
||||
|
||||
foodName_txt.setText(food.getName());
|
||||
shopName_txt.setText("Shop Name");
|
||||
price_txt.setText(Common.changeCurrencyUnit(Float.parseFloat(food.getPrice())));
|
||||
discount_txt.setText("-" + food.getDiscount() + "%");
|
||||
description_content_txt.setText(food.getDescription());
|
||||
countRating_txt.setText(food.getReviewCount() + " rating");
|
||||
|
||||
add_to_basket_button.setText("ADD TO BASKET - " + Common.changeCurrencyUnit(0));
|
||||
|
||||
List<SlideModel> slideModels = new ArrayList<>();
|
||||
if(imageFood != null){
|
||||
for(String imageUrl: imageFood)
|
||||
slideModels.add(new SlideModel(imageUrl, null));
|
||||
}
|
||||
imageSlider.setImageList(slideModels, ScaleTypes.FIT);
|
||||
// price = Float.parseFloat(food.getPrice());
|
||||
//
|
||||
// foodName_txt.setText(food.getName());
|
||||
// shopName_txt.setText("Shop Name");
|
||||
// price_txt.setText(Common.changeCurrencyUnit(Float.parseFloat(food.getPrice())));
|
||||
// discount_txt.setText("-" + food.getDiscount() + "%");
|
||||
// description_content_txt.setText(food.getDescription());
|
||||
// countRating_txt.setText(food.getReviewCount() + " rating");
|
||||
//
|
||||
// add_to_basket_button.setText("ADD TO BASKET - " + Common.changeCurrencyUnit(0));
|
||||
//
|
||||
// List<SlideModel> slideModels = new ArrayList<>();
|
||||
// if(imageFood != null){
|
||||
// for(String imageUrl: imageFood)
|
||||
// slideModels.add(new SlideModel(imageUrl, null));
|
||||
// }
|
||||
// imageSlider.setImageList(slideModels, ScaleTypes.FIT);
|
||||
|
||||
}
|
||||
|
||||
@@ -267,25 +262,25 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void getImageFoodById(String foodId) {
|
||||
FoodApi.apiService.getImageFoodById(foodId).enqueue(new Callback<List<ImageFood>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<ImageFood>> call, Response<List<ImageFood>> response) {
|
||||
List<ImageFood> imageFoodData = response.body();
|
||||
if (imageFoodData != null){
|
||||
imageFood.clear();
|
||||
for(ImageFood imageFoodTemp: imageFoodData){
|
||||
imageFood.add(imageFoodTemp.getImageUrl());
|
||||
}
|
||||
}
|
||||
|
||||
getFoodById(foodId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<ImageFood>> call, Throwable t) {
|
||||
Toast.makeText(FoodDetailActivity.this, "Lỗi Image" + t, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
// FoodApi.apiService.getImageFoodById(foodId).enqueue(new Callback<List<ImageFood>>() {
|
||||
// @Override
|
||||
// public void onResponse(Call<List<ImageFood>> call, Response<List<ImageFood>> response) {
|
||||
// List<ImageFood> imageFoodData = response.body();
|
||||
// if (imageFoodData != null){
|
||||
// imageFood.clear();
|
||||
// for(ImageFood imageFoodTemp: imageFoodData){
|
||||
// imageFood.add(imageFoodTemp.getImageUrl());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// getFoodById(foodId);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Call<List<ImageFood>> call, Throwable t) {
|
||||
// Toast.makeText(FoodDetailActivity.this, "Lỗi Image" + t, Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ public class ShopDetailActivity extends AppCompatActivity {
|
||||
//Init temp data
|
||||
Picasso.get().load("https://firebasestorage.googleapis.com/v0/b/foodify-55954.appspot.com/o/Free%20Food%20Advertising%20Banner%20Template.jpg?alt=media&token=8b836fd7-f18f-46c6-a14f-27680e51a1d5").into(imageShop);
|
||||
|
||||
for(int i = 1; i <= 10; i++){
|
||||
listFood.add(new Food("https://images.unsplash.com/photo-1546069901-ba9599a7e63c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8&w=1000&q=80", "Food " + i, "50.000đ"));
|
||||
}
|
||||
// for(int i = 1; i <= 10; i++){
|
||||
// listFood.add(new Food("https://images.unsplash.com/photo-1546069901-ba9599a7e63c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8&w=1000&q=80", "Food " + i, "50.000đ"));
|
||||
// }
|
||||
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
recycler_view_food_shop.setLayoutManager(linearLayoutManager);
|
||||
|
||||
@@ -17,6 +17,8 @@ import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.Model.Menu.Menu;
|
||||
import com.capstone.foodify.Model.Menu.MenuAdapter;
|
||||
import com.capstone.foodify.Model.Response.Foods;
|
||||
import com.capstone.foodify.Model.Response.Shops;
|
||||
import com.capstone.foodify.Model.Shop.Shop;
|
||||
import com.capstone.foodify.Model.Shop.ShopAdapter;
|
||||
import com.capstone.foodify.R;
|
||||
@@ -39,7 +41,9 @@ import retrofit2.Response;
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
public static List<Food> listFood = new ArrayList<>();
|
||||
private static List<Food> drinkFood = new ArrayList<>();
|
||||
private static List<Food> recentFood = new ArrayList<>();
|
||||
|
||||
private static List<Shop> shopList = new ArrayList<>();
|
||||
|
||||
private ImageSlider imageSlider;
|
||||
|
||||
@@ -61,7 +65,7 @@ public class HomeFragment extends Fragment {
|
||||
shopAdapter = new ShopAdapter(getContext());
|
||||
|
||||
|
||||
if(listFood.isEmpty() || drinkFood.isEmpty()){
|
||||
if(listFood.isEmpty() || recentFood.isEmpty()){
|
||||
getListFood();
|
||||
} else {
|
||||
menuAdapter.setData(getListMenu());
|
||||
@@ -81,16 +85,8 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
imageSlider.setImageList(slideModels, ScaleTypes.FIT);
|
||||
|
||||
//Restaurant
|
||||
List<Shop> shopList = new ArrayList<>();
|
||||
shopList.add(new Shop(R.drawable.burgerking));
|
||||
shopList.add(new Shop(R.drawable.dominopizza));
|
||||
shopList.add(new Shop(R.drawable.mcdonals));
|
||||
shopList.add(new Shop(R.drawable.pizzahut));
|
||||
shopList.add(new Shop(R.drawable.subway));
|
||||
|
||||
shopAdapter.setData(shopList);
|
||||
recyclerView_restaurant.setAdapter(shopAdapter);
|
||||
//Get list shop
|
||||
getListShop();
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
return view;
|
||||
@@ -100,54 +96,88 @@ public class HomeFragment extends Fragment {
|
||||
List<Menu> listMenu = new ArrayList<>();
|
||||
|
||||
listMenu.add(new Menu("Recommend Food", listFood));
|
||||
listMenu.add(new Menu("Popular Food", drinkFood));
|
||||
listMenu.add(new Menu("Popular Food", recentFood));
|
||||
|
||||
return listMenu;
|
||||
}
|
||||
|
||||
private void getListFood() {
|
||||
FoodApi.apiService.bestFoodResponse().enqueue(new Callback<List<Food>>() {
|
||||
FoodApi.apiService.recommendFood().enqueue(new Callback<Foods>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Food>> call, Response<List<Food>> response) {
|
||||
List<Food> foodData = response.body();
|
||||
public void onResponse(Call<Foods> call, Response<Foods> response) {
|
||||
Foods foodResponse = response.body();
|
||||
|
||||
if(foodData != null)
|
||||
listFood.addAll(foodData);
|
||||
//Check null data
|
||||
if(foodResponse == null)
|
||||
return;
|
||||
|
||||
drinkListFood();
|
||||
listFood = foodResponse.getProducts();
|
||||
|
||||
|
||||
recentFood();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Food>> call, Throwable t) {
|
||||
public void onFailure(Call<Foods> call, Throwable t) {
|
||||
//Check internet connection
|
||||
if(getContext() != null){
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
Common.showErrorInternetConnectionNotification(getActivity());
|
||||
}
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
Common.showErrorInternetConnectionNotification(getActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void drinkListFood() {
|
||||
FoodApi.apiService.drinksFoodResponse().enqueue(new Callback<List<Food>>() {
|
||||
private void recentFood() {
|
||||
FoodApi.apiService.recentFood().enqueue(new Callback<Foods>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Food>> call, Response<List<Food>> response) {
|
||||
List<Food> foodData = response.body();
|
||||
public void onResponse(Call<Foods> call, Response<Foods> response) {
|
||||
Foods foodResponse = response.body();
|
||||
|
||||
if(foodData != null)
|
||||
drinkFood.addAll(foodData);
|
||||
//Check null data
|
||||
if(foodResponse == null)
|
||||
return;
|
||||
|
||||
recentFood = foodResponse.getProducts();
|
||||
|
||||
menuAdapter.setData(getListMenu());
|
||||
rcvMenu.setAdapter(menuAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Food>> call, Throwable t) {
|
||||
public void onFailure(Call<Foods> call, Throwable t) {
|
||||
//Check internet connection
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
Common.showErrorInternetConnectionNotification(getActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getListShop(){
|
||||
FoodApi.apiService.allShops().enqueue(new Callback<Shops>() {
|
||||
@Override
|
||||
public void onResponse(Call<Shops> call, Response<Shops> response) {
|
||||
Shops shopData = response.body();
|
||||
|
||||
if(shopData == null)
|
||||
return;
|
||||
|
||||
shopList = shopData.getShops();
|
||||
|
||||
shopAdapter.setData(shopList);
|
||||
recyclerView_restaurant.setAdapter(shopAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Shops> call, Throwable t) {
|
||||
//Check internet connection
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
|
||||
@@ -135,7 +135,7 @@ public class SearchFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void getListFoodBySearch(String query, int page) {
|
||||
FoodApi.apiService.listFood(query, page, LIMIT).enqueue(new Callback<List<Food>>() {
|
||||
FoodApi.apiService.listFood(query, page, LIMIT, "id", "asc").enqueue(new Callback<List<Food>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Food>> call, Response<List<Food>> response) {
|
||||
loadFoodAdapter(response);
|
||||
|
||||
@@ -1,86 +1,112 @@
|
||||
package com.capstone.foodify.Model.Food;
|
||||
|
||||
import com.capstone.foodify.Model.Category.Category;
|
||||
import com.capstone.foodify.Model.Image;
|
||||
import com.capstone.foodify.Model.Shop.Shop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Food implements Comparable<Food>{
|
||||
private String id;
|
||||
private String img;
|
||||
private String name;
|
||||
private String price;
|
||||
private String discount;
|
||||
private String description;
|
||||
private String shopName;
|
||||
private boolean isEnabled;
|
||||
private float discountPercent;
|
||||
private float cost;
|
||||
private float averageRating;
|
||||
private String reviewCount;
|
||||
private String quantity_sold;
|
||||
private Shop shop;
|
||||
private List<Category> categories;
|
||||
private List<Image> images;
|
||||
public Food() {
|
||||
}
|
||||
public Food(String id, String img, String name, String price, String shopName) {
|
||||
this.id = id;
|
||||
this.img = img;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
this.shopName = shopName;
|
||||
}
|
||||
|
||||
public Food(String img, String name, String price) {
|
||||
this.img = img;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
public void setPrice(String price) {
|
||||
this.price = price;
|
||||
}
|
||||
public String getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
public void setDiscount(String discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getShopName() {
|
||||
return shopName;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
public void setShopName(String shopName) {
|
||||
this.shopName = shopName;
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
public float getDiscountPercent() {
|
||||
return discountPercent;
|
||||
}
|
||||
|
||||
public void setDiscountPercent(float discountPercent) {
|
||||
this.discountPercent = discountPercent;
|
||||
}
|
||||
|
||||
public float getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public void setCost(float cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public float getAverageRating() {
|
||||
return averageRating;
|
||||
}
|
||||
|
||||
public void setAverageRating(float averageRating) {
|
||||
this.averageRating = averageRating;
|
||||
}
|
||||
|
||||
public String getReviewCount() {
|
||||
return reviewCount;
|
||||
}
|
||||
|
||||
public void setReviewCount(String reviewCount) {
|
||||
this.reviewCount = reviewCount;
|
||||
}
|
||||
|
||||
public String getQuantity_sold() {
|
||||
return quantity_sold;
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
|
||||
public void setQuantity_sold(String quantity_sold) {
|
||||
this.quantity_sold = quantity_sold;
|
||||
public void setShop(Shop shop) {
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
public List<Category> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(List<Category> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public List<Image> getImages() {
|
||||
return images;
|
||||
}
|
||||
|
||||
public void setImages(List<Image> images) {
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,8 +55,24 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
|
||||
} else {
|
||||
holder.name.setText(foodName);
|
||||
}
|
||||
Picasso.get().load(food.getImg()).into(holder.image);
|
||||
holder.price.setText(Common.changeCurrencyUnit(Float.parseFloat(food.getPrice())));
|
||||
Picasso.get().load(food.getImages().get(0).getImageUrl()).into(holder.image);
|
||||
|
||||
//Check value discountPercent
|
||||
float cost = 0;
|
||||
if(food.getDiscountPercent() > 0){
|
||||
|
||||
//Calculate final cost when apply discountPercent
|
||||
cost = food.getCost() - (food.getCost() * food.getDiscountPercent()/100);
|
||||
|
||||
//Show discountPercent value on screen
|
||||
holder.discount.setVisibility(View.VISIBLE);
|
||||
holder.discount.setText("-" + food.getDiscountPercent()+ "%");
|
||||
} else {
|
||||
cost = food.getCost();
|
||||
}
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(cost));
|
||||
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -80,7 +96,7 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
|
||||
public class FoodViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private ImageView image;
|
||||
private TextView name, price;
|
||||
private TextView name, price, discount;
|
||||
|
||||
public FoodViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@@ -88,7 +104,7 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
|
||||
image = itemView.findViewById(R.id.image_view);
|
||||
name = itemView.findViewById(R.id.title);
|
||||
price = itemView.findViewById(R.id.price);
|
||||
|
||||
discount = itemView.findViewById(R.id.discount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ public class FoodFavoriteAdapter extends RecyclerView.Adapter<FoodFavoriteAdapt
|
||||
if(food == null)
|
||||
return;
|
||||
|
||||
holder.foodName.setText(food.getName());
|
||||
holder.shopName.setText(food.getShopName());
|
||||
holder.price.setText(food.getPrice());
|
||||
Picasso.get().load(food.getImg()).into(holder.imageView);
|
||||
// holder.foodName.setText(food.getName());
|
||||
// holder.shopName.setText(food.getShopName());
|
||||
// holder.price.setText(food.getPrice());
|
||||
// Picasso.get().load(food.getImg()).into(holder.imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,10 +53,10 @@ public class FoodSearchAdapter extends RecyclerView.Adapter<FoodSearchAdapter.Fo
|
||||
} else {
|
||||
holder.name.setText(foodName);
|
||||
}
|
||||
Picasso.get().load(food.getImg()).into(holder.image);
|
||||
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(Float.parseFloat(food.getPrice())));
|
||||
// Picasso.get().load(food.getImg()).into(holder.image);
|
||||
//
|
||||
//
|
||||
// holder.price.setText(Common.changeCurrencyUnit(Float.parseFloat(food.getPrice())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,10 +40,10 @@ public class FoodShopAdapter extends RecyclerView.Adapter<FoodShopAdapter.FoodSh
|
||||
if(food == null)
|
||||
return;
|
||||
|
||||
Picasso.get().load(food.getImg()).into(holder.imageView);
|
||||
holder.foodName.setText(food.getName());
|
||||
holder.quantitySoldOut.setText("1.2k đã bán");
|
||||
holder.price.setText(food.getPrice());
|
||||
// Picasso.get().load(food.getImg()).into(holder.imageView);
|
||||
// holder.foodName.setText(food.getName());
|
||||
// holder.quantitySoldOut.setText("1.2k đã bán");
|
||||
// holder.price.setText(food.getPrice());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.capstone.foodify.Model.Food;
|
||||
|
||||
public class ImageFood {
|
||||
private String imageUrl;
|
||||
private String id;
|
||||
private String detailId;
|
||||
|
||||
public ImageFood(String imageUrl, String id, String detailId) {
|
||||
this.imageUrl = imageUrl;
|
||||
this.id = id;
|
||||
this.detailId = detailId;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDetailId() {
|
||||
return detailId;
|
||||
}
|
||||
|
||||
public void setDetailId(String detailId) {
|
||||
this.detailId = detailId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.capstone.foodify.Model;
|
||||
|
||||
public class Image {
|
||||
private int id;
|
||||
private String imageUrl;
|
||||
private int productId;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public int getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(int productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.capstone.foodify.Model;
|
||||
|
||||
public class Page {
|
||||
private int pageNo;
|
||||
private int pageSize;
|
||||
private int totalElements;
|
||||
private int totalPages;
|
||||
private boolean last;
|
||||
|
||||
public int getPageNo() {
|
||||
return pageNo;
|
||||
}
|
||||
|
||||
public void setPageNo(int pageNo) {
|
||||
this.pageNo = pageNo;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getTotalElements() {
|
||||
return totalElements;
|
||||
}
|
||||
|
||||
public void setTotalElements(int totalElements) {
|
||||
this.totalElements = totalElements;
|
||||
}
|
||||
|
||||
public int getTotalPages() {
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public void setTotalPages(int totalPages) {
|
||||
this.totalPages = totalPages;
|
||||
}
|
||||
|
||||
public boolean isLast() {
|
||||
return last;
|
||||
}
|
||||
|
||||
public void setLast(boolean last) {
|
||||
this.last = last;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.capstone.foodify.Model.Response;
|
||||
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.Model.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Foods {
|
||||
private List<Food> products;
|
||||
private Page page;
|
||||
|
||||
public List<Food> getProducts() {
|
||||
return products;
|
||||
}
|
||||
|
||||
public void setProducts(List<Food> products) {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
public Page getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Page page) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.capstone.foodify.Model.Response;
|
||||
|
||||
import com.capstone.foodify.Model.Page;
|
||||
import com.capstone.foodify.Model.Shop.Shop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Shops {
|
||||
private List<Shop> shops;
|
||||
private Page page;
|
||||
|
||||
public List<Shop> getShops() {
|
||||
return shops;
|
||||
}
|
||||
|
||||
public void setShops(List<Shop> shops) {
|
||||
this.shops = shops;
|
||||
}
|
||||
|
||||
public Page getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Page page) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,58 @@
|
||||
package com.capstone.foodify.Model.Shop;
|
||||
|
||||
public class Shop {
|
||||
private int resourceId;
|
||||
private int id;
|
||||
private String description;
|
||||
private String imageUrl;
|
||||
private boolean isEnabled;
|
||||
private boolean isStudent;
|
||||
private int userId;
|
||||
|
||||
public Shop(int resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getResourceId() {
|
||||
return resourceId;
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setResourceId(int resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isStudent() {
|
||||
return isStudent;
|
||||
}
|
||||
|
||||
public void setStudent(boolean student) {
|
||||
isStudent = student;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Activity.ShopDetailActivity;
|
||||
import com.capstone.foodify.R;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,7 +46,10 @@ public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewHolder
|
||||
if(shop == null)
|
||||
return;
|
||||
|
||||
holder.imgView.setImageResource(shop.getResourceId());
|
||||
//Init data
|
||||
Picasso.get().load(shop.getImageUrl()).into(holder.imageView);
|
||||
holder.shopName.setText("Shop Name");
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -62,12 +67,14 @@ public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewHolder
|
||||
|
||||
public class ShopViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private ImageView imgView;
|
||||
private ImageView imageView;
|
||||
private TextView shopName;
|
||||
|
||||
public ShopViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
imgView = itemView.findViewById(R.id.shopImage);
|
||||
imageView = itemView.findViewById(R.id.imageView);
|
||||
shopName = itemView.findViewById(R.id.shopName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB |
@@ -71,21 +71,9 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_menu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
tools:listitem="@layout/item_food"
|
||||
app:layout_constraintTop_toBottomOf="@id/recycler_view_restaurant"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/restaurant_text"
|
||||
android:text="@string/restaurant"
|
||||
android:text="Shop"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
@@ -100,7 +88,7 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_restaurant"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
android:contentDescription="@string/description"
|
||||
@@ -110,6 +98,19 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_menu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
tools:listitem="@layout/item_food"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/recycler_view_restaurant"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="221dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
@@ -64,11 +64,13 @@
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/discount"
|
||||
android:text="-59%"
|
||||
android:textSize="8sp"
|
||||
android:textColor="@color/red"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
@@ -1,35 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="151dp"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_margin="10dp">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="150dp"
|
||||
app:cardCornerRadius="10dp"
|
||||
android:layout_margin="2dp"
|
||||
>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.constraintlayout.utils.widget.ImageFilterView
|
||||
android:id="@+id/shopImage"
|
||||
android:src="@drawable/burgerking"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:src="@drawable/food"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="10dip"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<TextView
|
||||
android:id="@+id/shopName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Shop Name"
|
||||
android:layout_marginStart="3dp"
|
||||
android:layout_marginEnd="3dp"
|
||||
android:textSize="12sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/black"
|
||||
android:layout_marginTop="3dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/imageView"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user