use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirebaseUI-Android by firebase.
the class FirestoreArray method onDocumentModified.
private void onDocumentModified(DocumentChange change) {
QueryDocumentSnapshot snapshot = change.getDocument();
if (change.getOldIndex() == change.getNewIndex()) {
// Document modified only
mSnapshots.set(change.getNewIndex(), snapshot);
notifyOnChildChanged(ChangeEventType.CHANGED, snapshot, change.getNewIndex(), change.getNewIndex());
} else {
// Document moved and possibly also modified
mSnapshots.remove(change.getOldIndex());
mSnapshots.add(change.getNewIndex(), snapshot);
notifyOnChildChanged(ChangeEventType.MOVED, snapshot, change.getNewIndex(), change.getOldIndex());
notifyOnChildChanged(ChangeEventType.CHANGED, snapshot, change.getNewIndex(), change.getNewIndex());
}
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project Chat-app by TuTuanLe.
the class ChatFragment method getUSer.
private void getUSer() {
loading(true);
FirebaseFirestore database = FirebaseFirestore.getInstance();
database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
loading(false);
String currentUserId = preferenceManager.getString(Constants.KEY_USER_ID);
if (task.isSuccessful() && task.getResult() != null) {
List<User> users = new ArrayList<>();
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (currentUserId.equals(queryDocumentSnapshot.getId())) {
continue;
}
User user = new User();
user.setName(queryDocumentSnapshot.getString(Constants.KEY_NAME));
user.setEmail(queryDocumentSnapshot.getString(Constants.KEY_EMAIL));
user.setProfileImage(queryDocumentSnapshot.getString(Constants.KEY_IMAGE));
user.setToken(queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN));
user.setUid(queryDocumentSnapshot.getId());
user.setAvailability(queryDocumentSnapshot.getLong(Constants.KEY_AVAILABILITY));
users.add(user);
}
if (users.size() > 0) {
Users_Adapter users_adapter = new Users_Adapter(users, mainScreenActivity);
RecyclerView temp = view.findViewById(R.id.userRecyclerView);
temp.setAdapter(users_adapter);
temp.setVisibility(View.VISIBLE);
} else {
showErrorMessage();
}
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project Chat-app by TuTuanLe.
the class SearchActivity method getUSer.
private void getUSer() {
loading(true);
FirebaseFirestore database = FirebaseFirestore.getInstance();
database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
loading(false);
String currentUserId = preferenceManager.getString(Constants.KEY_USER_ID);
if (task.isSuccessful() && task.getResult() != null) {
users = new ArrayList<>();
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (currentUserId.equals(queryDocumentSnapshot.getId())) {
continue;
}
User user = new User();
user.setName(queryDocumentSnapshot.getString(Constants.KEY_NAME));
user.setEmail(queryDocumentSnapshot.getString(Constants.KEY_EMAIL));
user.setProfileImage(queryDocumentSnapshot.getString(Constants.KEY_IMAGE));
user.setToken(queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN));
user.setUid(queryDocumentSnapshot.getId());
user.setAvailability(queryDocumentSnapshot.getLong(Constants.KEY_AVAILABILITY));
users.add(user);
}
if (users.size() > 0) {
searchAdapter = new SearchAdapter(users, SearchActivity.this);
binding.userRecyclerView.setAdapter(searchAdapter);
binding.userRecyclerView.setVisibility(View.VISIBLE);
} else {
showToast("Error");
}
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project AlphaTour by Frank99DG.
the class ImportPhotoObjectActivity method saveObjects.
private void saveObjects(List<Element> elmlist) {
db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (int i = 0; i < elmlist.size(); i++) {
for (QueryDocumentSnapshot document : task.getResult()) {
Element newElement = elmlist.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", newElement.getPhoto().toString());
elm.put("qrCode", null);
elm.put("idPhotoAndQrCode", Long.parseLong(newElement.getIdPhotoAndQrCodeString()));
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();
}
});
saveQrCode(newElement.getQrData(), newElement, i, id);
}
}
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
success = false;
Toast.makeText(ImportPhotoObjectActivity.this, "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 ModifyObjectActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify_object);
db = FirebaseFirestore.getInstance();
storegeProfilePick = FirebaseStorage.getInstance().getReference();
// riferimenti alle view
title = findViewById(R.id.titleQr);
description = findViewById(R.id.descriptionQr);
photo = findViewById(R.id.changePhotoObjectQr);
qrCode = findViewById(R.id.changeQr);
imagePhoto = findViewById(R.id.photoQr);
imageQrCode = findViewById(R.id.qr);
typology = findViewById(R.id.inputTypeZoneQr);
loadingBar = findViewById(R.id.modifyLoadingBar);
loadingBar.setVisibility(View.VISIBLE);
adapterItems = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, zoneList);
Intent intent = getIntent();
myQrData = intent.getStringExtra("data");
Place = intent.getStringExtra("Place");
idPlace = intent.getStringExtra("idPlace");
Zone = intent.getStringExtra("Zone");
idZone = intent.getStringExtra("idZone");
Element = intent.getStringExtra("Element");
dashboardFlag = intent.getStringExtra("dashboardFlag");
// settaggio idPlace,idZone se si arriva da dashboard
if (dashboardFlag.equals("1")) {
getIdPlaceAndIdZone(myQrData);
}
// settaggio dati elemento
db.collection("Elements").whereEqualTo("qrData", myQrData).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
if (task.getResult() != null) {
for (QueryDocumentSnapshot document : task.getResult()) {
ElementString element = document.toObject(ElementString.class);
idElement = document.getId();
db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
i++;
for (QueryDocumentSnapshot document : task.getResult()) {
Zone zone = document.toObject(Zone.class);
if (i == 1 && zone.getIdPlace().equals(idPlace)) {
zoneList.add(zone.getName());
zoneMap.put(document.getId(), zone.getName());
}
if (document.getId().matches(element.getIdZone())) {
zone = document.toObject(Zone.class);
title.setText(element.getTitle());
description.setText(element.getDescription());
idPhotoAndQrCode = element.getIdPhotoAndQrCode();
Qrdata = element.getQrData();
showPhoto();
showQrCode();
typology.setAdapter(adapterItems);
Zone = zone.getName();
typology.setHint(Zone);
typology.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
typology.setError(null);
item = parent.getItemAtPosition(position).toString();
}
});
}
}
} else {
Toast.makeText(ModifyObjectActivity.this, "Non è stato possibile caricare i dati dell'oggetto !!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
}
}
});
}
} else {
Toast.makeText(ModifyObjectActivity.this, "Oggetto non trovato !!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
Intent intent = new Intent(ModifyObjectActivity.this, DashboardActivity.class);
startActivity(intent);
}
} else {
Toast.makeText(ModifyObjectActivity.this, "Non è stato possibile caricare i dati dell'oggetto", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
Intent intent = new Intent(ModifyObjectActivity.this, DashboardActivity.class);
startActivity(intent);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(ModifyObjectActivity.this, "Oggetto non trovato !!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
}
});
}
Aggregations