Search in sources :

Example 1 with HomShopAdapter

use of fcu.app.unknownfooddelivery.adapter.HomShopAdapter 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

Bundle (android.os.Bundle)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)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 HomeShopItem (fcu.app.unknownfooddelivery.item.HomeShopItem)1 ArrayList (java.util.ArrayList)1