diff --git a/app/src/main/java/com/capstone/foodify/Fragment/HomeFragment.java b/app/src/main/java/com/capstone/foodify/Fragment/HomeFragment.java index 05e1742..4ec093e 100644 --- a/app/src/main/java/com/capstone/foodify/Fragment/HomeFragment.java +++ b/app/src/main/java/com/capstone/foodify/Fragment/HomeFragment.java @@ -14,6 +14,8 @@ import com.capstone.foodify.API.FoodApi; 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.Shop.Shop; +import com.capstone.foodify.Model.Shop.ShopAdapter; import com.capstone.foodify.R; import com.denzcoskun.imageslider.ImageSlider; import com.denzcoskun.imageslider.constants.ScaleTypes; @@ -34,8 +36,9 @@ public class HomeFragment extends Fragment { private ImageSlider imageSlider; - private RecyclerView rcvMenu; + private RecyclerView rcvMenu, recyclerView_restaurant; private MenuAdapter menuAdapter; + private ShopAdapter shopAdapter; @Override @@ -47,9 +50,11 @@ public class HomeFragment extends Fragment { imageSlider = (ImageSlider) view.findViewById(R.id.slider); rcvMenu = view.findViewById(R.id.recycler_view_menu); menuAdapter = new MenuAdapter(getContext()); + recyclerView_restaurant = view.findViewById(R.id.recycler_view_restaurant); + shopAdapter = new ShopAdapter(getContext()); + getListFood(); - drinkListFood(); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false); rcvMenu.setLayoutManager(linearLayoutManager); @@ -63,6 +68,17 @@ public class HomeFragment extends Fragment { imageSlider.setImageList(slideModels, ScaleTypes.FIT); + //Restaurant + List 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); + // Inflate the layout for this fragment return view; } @@ -106,7 +122,6 @@ public class HomeFragment extends Fragment { drinkFood.add(tempFood); } - menuAdapter.setData(getListMenu()); rcvMenu.setAdapter(menuAdapter); } diff --git a/app/src/main/java/com/capstone/foodify/Model/Shop/Shop.java b/app/src/main/java/com/capstone/foodify/Model/Shop/Shop.java new file mode 100644 index 0000000..6002599 --- /dev/null +++ b/app/src/main/java/com/capstone/foodify/Model/Shop/Shop.java @@ -0,0 +1,17 @@ +package com.capstone.foodify.Model.Shop; + +public class Shop { + private int resourceId; + + public Shop(int resourceId) { + this.resourceId = resourceId; + } + + public int getResourceId() { + return resourceId; + } + + public void setResourceId(int resourceId) { + this.resourceId = resourceId; + } +} diff --git a/app/src/main/java/com/capstone/foodify/Model/Shop/ShopAdapter.java b/app/src/main/java/com/capstone/foodify/Model/Shop/ShopAdapter.java new file mode 100644 index 0000000..5e29f66 --- /dev/null +++ b/app/src/main/java/com/capstone/foodify/Model/Shop/ShopAdapter.java @@ -0,0 +1,66 @@ +package com.capstone.foodify.Model.Shop; + +import android.content.Context; +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.R; + +import java.util.List; + +public class ShopAdapter extends RecyclerView.Adapter{ + + private List shopList; + + private Context context; + + public ShopAdapter(Context context){ + this.context = context; + } + + public void setData(List list) { + this.shopList = list; + notifyDataSetChanged(); + } + + @NonNull + @Override + public ShopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_restaurant, parent, false); + return new ShopViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ShopViewHolder holder, int position) { + Shop shop = shopList.get(position); + + if(shop == null) + return; + + holder.imgView.setImageResource(shop.getResourceId()); + } + + @Override + public int getItemCount() { + if(shopList != null) + return shopList.size(); + return 0; + } + + public class ShopViewHolder extends RecyclerView.ViewHolder{ + + private ImageView imgView; + + public ShopViewHolder(@NonNull View itemView) { + super(itemView); + + imgView = itemView.findViewById(R.id.shopImage); + } + } +} diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 82fc115..0efc82f 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -81,7 +81,7 @@ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" android:orientation="horizontal" tools:listitem="@layout/list_foods" - app:layout_constraintTop_toBottomOf="@id/slider" + app:layout_constraintTop_toBottomOf="@id/recycler_view_restaurant" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" /> @@ -96,7 +96,7 @@ android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" - app:layout_constraintTop_toBottomOf="@id/recycler_view_menu" + app:layout_constraintTop_toBottomOf="@id/slider" app:layout_constraintStart_toStartOf="parent" /> diff --git a/app/src/main/res/layout/list_restaurant.xml b/app/src/main/res/layout/list_restaurant.xml index 43555e9..e637cfd 100644 --- a/app/src/main/res/layout/list_restaurant.xml +++ b/app/src/main/res/layout/list_restaurant.xml @@ -17,6 +17,7 @@ android:layout_height="match_parent">