Search in sources :

Example 1 with MealItem

use of fcu.app.unknownfooddelivery.item.MealItem in project Unknown-food-delivery by a47894785.

the class MenuAdapter method getView.

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(this.context);
    LinearLayout itemLayout = null;
    if (convertView == null) {
        itemLayout = (LinearLayout) inflater.inflate(R.layout.listitem_shop_page, null);
    } else {
        itemLayout = (LinearLayout) convertView;
    }
    MealItem item = mealItems.get(position);
    TextView tvMealName = itemLayout.findViewById(R.id.tv_menu_meal_name);
    tvMealName.setText(item.getMealName());
    TextView tvMealPrice = itemLayout.findViewById(R.id.tv_menu_meal_price);
    tvMealPrice.setText("$ " + item.getMealPrice());
    ImageView imMealImg = itemLayout.findViewById(R.id.im_menu_meal_img);
    Picasso.get().load(item.getMealImg()).into(imMealImg);
    return itemLayout;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) MealItem(fcu.app.unknownfooddelivery.item.MealItem) LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull)

Example 2 with MealItem

use of fcu.app.unknownfooddelivery.item.MealItem in project Unknown-food-delivery by a47894785.

the class ShopInfoFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_shop_info, container, false);
    if (getArguments() != null) {
        shopId = this.getArguments().getString("shopId");
    }
    db = FirebaseFirestore.getInstance();
    imShopImage = view.findViewById(R.id.im_shop_image);
    tvShopName = view.findViewById(R.id.tv_shop_info_name);
    tvShopPhone = view.findViewById(R.id.tv_shop_info_phone);
    lvMenu = view.findViewById(R.id.lv_show_menu);
    DocumentReference documentReference = db.collection("shops").document(shopId);
    documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {

        @Override
        public void onSuccess(DocumentSnapshot documentSnapshot) {
            if (documentSnapshot.exists()) {
                shopName = documentSnapshot.getString("shopName");
                shopPhone = documentSnapshot.getString("shopPhone");
                shopImgUrl = documentSnapshot.getString("shopImage");
                Picasso.get().load(shopImgUrl).into(imShopImage);
                tvShopName.setText(shopName);
                tvShopPhone.setText(shopPhone);
            }
        }
    });
    db.collection("shops").document(shopId).collection("menu").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            ArrayList<MealItem> mealList = new ArrayList<>();
            for (QueryDocumentSnapshot document : task.getResult()) {
                Log.d("menuInfo", document.getId());
                String mealName = String.valueOf(document.getData().get("mealName"));
                String mealPrice = String.valueOf(document.getData().get("mealPrice"));
                String photoName = String.valueOf(document.getData().get("photoName"));
                mealList.add(new MealItem(mealName, mealPrice, photoName));
            }
            MenuAdapter adapter = new MenuAdapter(getContext(), R.layout.listitem_shop_page, mealList);
            lvMenu.setAdapter(adapter);
        }
    });
    return view;
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) MenuAdapter(fcu.app.unknownfooddelivery.adapter.MenuAdapter) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) MealItem(fcu.app.unknownfooddelivery.item.MealItem) DocumentReference(com.google.firebase.firestore.DocumentReference)

Aggregations

ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MealItem (fcu.app.unknownfooddelivery.item.MealItem)2 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 NonNull (androidx.annotation.NonNull)1 DocumentReference (com.google.firebase.firestore.DocumentReference)1 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1 MenuAdapter (fcu.app.unknownfooddelivery.adapter.MenuAdapter)1 ArrayList (java.util.ArrayList)1