Search in sources :

Example 1 with HomeShopItem

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

the class HomShopAdapter 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.layout_home, null);
    } else {
        itemLayout = (LinearLayout) convertView;
    }
    HomeShopItem item = homeShopItem.get(position);
    TextView tvShopName = itemLayout.findViewById(R.id.tv_shop_name);
    tvShopName.setText(item.getShopName());
    TextView tvShopAddress = itemLayout.findViewById(R.id.tv_shop_address);
    tvShopAddress.setText(item.getShopAddress());
    ImageView imShopImg = itemLayout.findViewById(R.id.im_shopImg);
    Picasso.get().load(item.getImgName()).into(imShopImg);
    return itemLayout;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) HomeShopItem(fcu.app.unknownfooddelivery.item.HomeShopItem) LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull)

Example 2 with HomeShopItem

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

the class HomeFragment 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_home, container, false);
    tvCurrentAddress = view.findViewById(R.id.home_frag_address);
    lvShop = view.findViewById(R.id.lv_shop);
    if (getArguments() != null) {
        String currentAddress = this.getArguments().getString("address");
        tvCurrentAddress.setText(currentAddress);
    }
    fAuth = FirebaseAuth.getInstance();
    db = FirebaseFirestore.getInstance();
    userId = fAuth.getCurrentUser().getUid();
    ArrayList<String> shopIdList = new ArrayList<>();
    // 
    db.collection("shops").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            count = String.valueOf(task.getResult().size());
            ArrayList<HomeShopItem> homeShopLists = new ArrayList<>();
            for (QueryDocumentSnapshot document : task.getResult()) {
                Log.d("documents", document.getId() + " => " + document.getData());
                if (document.getData().get("shopName") != "") {
                    shopIdList.add(document.getId());
                    Log.d("documents", String.valueOf(document.getData().get("shopName")));
                    String shopName = String.valueOf(document.getData().get("shopName"));
                    String shopAddress = String.valueOf(document.getData().get("shopAddress"));
                    String shopImgName = String.valueOf(document.getData().get("shopImage"));
                    homeShopLists.add(new HomeShopItem(shopName, shopAddress, shopImgName));
                }
            }
            HomShopAdapter adapter = new HomShopAdapter(getContext(), R.layout.layout_home, homeShopLists);
            lvShop.setAdapter(adapter);
            for (int i = 0; i < shopIdList.size(); i++) {
                Log.d("ShopInfo", shopIdList.get(i));
            }
        }
    });
    lvShop.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int index, long l) {
            String selectedId = shopIdList.get(index);
            ShopInfoFragment shopInfoFragment = new ShopInfoFragment();
            Bundle bundle = new Bundle();
            bundle.putString("shopId", selectedId);
            shopInfoFragment.setArguments(bundle);
            ImageView imBack = getActivity().findViewById(R.id.im_back_arrow);
            EditText etSearch = getActivity().findViewById(R.id.et_search);
            etSearch.setVisibility(View.GONE);
            // imBack.setVisibility(View.VISIBLE);
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.btn_nav_container, shopInfoFragment).commit();
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) HomeShopItem(fcu.app.unknownfooddelivery.item.HomeShopItem) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) HomShopAdapter(fcu.app.unknownfooddelivery.adapter.HomShopAdapter) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView)

Aggregations

ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 HomeShopItem (fcu.app.unknownfooddelivery.item.HomeShopItem)2 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 NonNull (androidx.annotation.NonNull)1 FragmentManager (androidx.fragment.app.FragmentManager)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1 HomShopAdapter (fcu.app.unknownfooddelivery.adapter.HomShopAdapter)1 ArrayList (java.util.ArrayList)1