use of com.google.firebase.firestore.QueryDocumentSnapshot 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;
}
use of com.google.firebase.firestore.QueryDocumentSnapshot 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;
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project M3 by iatharva.
the class SeeRanking method getUserList.
private void getUserList() {
db.collection("Users").get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
List<String> usersList = new ArrayList<>();
List<String> usersNameList = new ArrayList<>();
for (QueryDocumentSnapshot document : task.getResult()) {
usersList.add(document.getId());
usersNameList.add(document.getString("FName") + " " + document.getString("LName"));
}
getCounts(usersList, usersNameList);
Log.d(TAG, usersList.toString());
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project AlphaTour by Frank99DG.
the class CreateConstraintsWizard method saveObjects.
/*public boolean inputControl(String Prova){
Boolean errorFlag = false;
if (Prova.isEmpty()) {
prova.setError(getString(R.string.campo_obbligatorio));
prova.requestFocus();
errorFlag = true;
}
return errorFlag;
}*/
private void saveObjects(List<Element> elementlist) {
db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (int i = 0; i < elementlist.size(); i++) {
for (QueryDocumentSnapshot document : task.getResult()) {
Element newElement = elementlist.get(i);
Zone zon = document.toObject(Zone.class);
if (zon.getName().matches(newElement.getZoneRif())) {
newElement.setIdZone(document.getId());
id = generateidPhotoAndQrCode();
elm.put("idZone", newElement.getIdZone());
elm.put("title", newElement.getTitle());
elm.put("description", newElement.getDescription());
elm.put("photo", null);
elm.put("qrCode", null);
elm.put("idPhotoAndQrCode", id);
elm.put("idUser", user.getUid());
elm.put("qrData", newElement.getQrData());
db.collection("Elements").add(elm).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
success = true;
// String id=documentReference.getId();
}
});
savePhoto(newElement.getPhoto(), newElement, i, id);
saveQrCode(newElement.getQrCode(), newElement, i, id);
}
}
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
success = false;
Toast.makeText(getContext(), "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project AlphaTour by Frank99DG.
the class Step3 method setUserVisibleHint.
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
zone_selected.setText(DashboardActivity.getZona_scelta());
String scelta = DashboardActivity.getZona_scelta();
db.collection("Zones").whereEqualTo("name", scelta).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
String idZone = document.getId();
db.collection("Elements").whereEqualTo("idZone", idZone).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
ElementString element = document.toObject(ElementString.class);
View object = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
CheckableTextView textZone1 = (CheckableTextView) object.findViewById(R.id.textObjectss);
textZone1.setText(element.getTitle());
arrayStringElement.add(element.getTitle());
// arrayObjectElement.add(element);
arrayMonumenti.add(textZone1);
delete_view.add(object);
list_object.addView(object);
}
} else {
Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
}
}
});
}
} else {
Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
}
}
});
} else {
}
}
Aggregations