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;
}
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;
}
Aggregations