Add list data for restaurant

This commit is contained in:
Nezumi
2023-02-13 22:16:50 +07:00
parent 8b010e9709
commit fd3b73bbec
5 changed files with 104 additions and 5 deletions
@@ -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<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);
// 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);
}
@@ -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;
}
}
@@ -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<ShopAdapter.ShopViewHolder>{
private List<Shop> shopList;
private Context context;
public ShopAdapter(Context context){
this.context = context;
}
public void setData(List<Shop> 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);
}
}
}
+2 -2
View File
@@ -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"
/>
@@ -17,6 +17,7 @@
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"