use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirebaseUI-Android by firebase.
the class FirestoreArray method onDocumentRemoved.
private void onDocumentRemoved(DocumentChange change) {
mSnapshots.remove(change.getOldIndex());
QueryDocumentSnapshot snapshot = change.getDocument();
notifyOnChildChanged(ChangeEventType.REMOVED, snapshot, -1, change.getOldIndex());
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project KDU-Attendance_and_Medical_Tracking_app by Sandul-Jayakody.
the class med2 method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_med2);
editTextTitle = findViewById(R.id.edit_text_title);
editTextDescription = findViewById(R.id.edit_text_description);
editTextPriority = findViewById(R.id.edit_text_priority);
editTextTags = findViewById(R.id.edit_text_tags);
textViewData = findViewById(R.id.text_view_data);
// fauth= FirebaseAuth.getInstance();
// fstore=FirebaseFirestore.getInstance();
// subject=fauth.getCurrentUser().getUid();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String currentuid = user.getUid();
/* public void addNote(View v) {
String title = editTextTitle.getText().toString();
String description = editTextDescription.getText().toString();
if (editTextPriority.length() == 0) {
editTextPriority.setText("0");
}
int priority = Integer.parseInt(editTextPriority.getText().toString());
String tagInput = editTextTags.getText().toString();
String[] tagArray = tagInput.split("\\s*,\\s*");
Map<String, String> tags = new HashMap<>();
for (String tag : tagArray) {
tags.put(tag, "");
}
Note note = new Note(title, description,HOD,Dean, priority, tags);
notebookRef.document("14g7Y5YjuaRcmGAiikUi")
.collection("Child Notes").add(note);
}*/
notebookRef.document(currentuid).collection("Child Notes").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
String data = "";
// String data2 = "";
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Note note = documentSnapshot.toObject(Note.class);
note.setDocumentId(documentSnapshot.getId());
String documentId = note.getDean();
data += "\n\n" + "HOD: " + documentId;
// note.setDocumentId(documentSnapshot.getId());
String documentId2 = note.getHOD();
data += "\n\n" + "Dean: " + documentId2;
/* for (String tag : note.getTags().keySet()) {
data += "\n-" + tag;
}
data += "\n\n";*/
}
textViewData.setText(data);
// textViewData.setText(data2);
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project MDA_APP_RESTAURANTE by karlaogh99.
the class FoodListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_list);
FirebaseFirestore db = FirebaseFirestore.getInstance();
// Read from the database
listFood = new ArrayList<>();
recycler_menu = (RecyclerView) findViewById(R.id.recycler_food);
recycler_menu.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);
db.collection("Food").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful() && getIntent() != null) {
Category catId = (Category) getIntent().getSerializableExtra("Categoria");
for (QueryDocumentSnapshot document : task.getResult()) {
if (catId.getName().equals((String) document.get("IdCategoria"))) {
Food food = new Food("", "", "", "", "");
food.setName((String) document.get("Nombre"));
food.setDescripcion((String) document.get("Descripcion"));
food.setId((String) document.get("IdCategoria"));
food.setPrice((String) document.get("Precio"));
food.setImage((String) document.get("Image"));
listFood.add(food);
}
}
AdapterFood adapter = new AdapterFood(listFood);
recycler_menu.setAdapter(adapter);
}
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project House-Organizer by House-Organizer.
the class MainScreenActivity method loadHousehold.
private void loadHousehold(String householdId) {
db.collection("households").whereArrayContains("residents", mUser.getEmail()).get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
ArrayList<String> households = new ArrayList<String>();
for (QueryDocumentSnapshot document : task.getResult()) {
if (householdId.equals(document.getId())) {
households.add(document.getId());
currentHouse = db.collection("households").document(householdId);
break;
}
}
if (currentHouse == null) {
if (!households.isEmpty()) {
currentHouse = db.collection("households").document(households.get(0));
saveData(households.get(0));
} else {
saveData("");
hideButtons();
}
}
refreshCalendar(findViewById(R.id.calendar));
} else {
Toast.makeText(getApplicationContext(), "Could not get a house.", Toast.LENGTH_SHORT).show();
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project QRHunt by CMPUT301W22T00.
the class FragmentMap method onCreateView.
/**
* Sets up fragment to be loaded in, finds all views, sets onClickListener for buttons
* @param inflater inflater
* @param container Where the fragment is contained
* @param savedInstanceState SavedInstanceState
* @return root
*/
@SuppressLint("ResourceType")
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Load/Initialize osmdroid configuration, database, and location
db = FirebaseFirestore.getInstance();
ctx = getActivity().getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
client = LocationServices.getFusedLocationProviderClient(this.getActivity());
startPollingLocation();
// Makes the map load faster via caching
IConfigurationProvider osmConf = Configuration.getInstance();
File basePath = new File(this.getActivity().getCacheDir().getAbsolutePath(), "osmdroid");
basePath.mkdirs();
osmConf.setOsmdroidBasePath(basePath);
File tileCache = new File(osmConf.getOsmdroidBasePath().getAbsolutePath(), "tile");
tileCache.mkdirs();
osmConf.setOsmdroidTileCache(tileCache);
osmConf.setUserAgentValue("QRHunt");
binding = FragmentMapBinding.inflate(inflater, container, false);
View root = binding.getRoot();
/* Inflate and create the map
setContentView(R.layout.fragment_map); */
map = binding.mapView;
map.setTileSource(TileSourceFactory.MAPNIK);
// Map Zoom Controls
map.setBuiltInZoomControls(false);
map.setMultiTouchControls(true);
IMapController mapController = map.getController();
mapController.setZoom(20);
// Creates user location
this.mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(ctx), map);
// This gets the current user location
getLocation().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Location location = task.getResult();
if (location != null) {
currentLocation = new Location(location);
}
/* this stops listening to the updates that
we didn't actually care about in the first place for; see startPollingLocation
*/
LocationServices.getFusedLocationProviderClient(ctx).removeLocationUpdates(hackyLocationCallback);
}
});
// Change person and directional icon
Drawable directionIcon = ContextCompat.getDrawable(getActivity(), R.drawable.ic_player_nav);
Drawable personIcon = ContextCompat.getDrawable(getActivity(), R.drawable.ic_person_icon);
this.mLocationOverlay.setDirectionArrow(drawableToBitmap(personIcon), drawableToBitmap(directionIcon));
// Enables and follows user location
this.mLocationOverlay.enableMyLocation();
this.mLocationOverlay.enableFollowLocation();
this.mLocationOverlay.setPersonHotspot(30.0f, 30.0f);
// Recenters the map onto the user
btnRecenter = (ImageButton) root.findViewById(R.id.map_recenter);
btnRecenter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GeoPoint myLocation = new GeoPoint(currentLocation.getLatitude(), currentLocation.getLongitude());
map.getController().animateTo(myLocation);
map.getController().setZoom(20);
}
});
// Adding the overlays
map.getOverlays().add(this.mLocationOverlay);
Drawable pinIcon = ContextCompat.getDrawable(getActivity(), R.drawable.ic_qr_pin);
Query qrLocation = db.collectionGroup("qrCodes");
qrLocation.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot doc : task.getResult()) {
if (doc.exists()) {
PlayableQrCode qrCode = doc.toObject(PlayableQrCode.class);
if (qrCode.getLocation() != null) {
lat = qrCode.getLocation().getLatitude();
lng = qrCode.getLocation().getLongitude();
if (lat != null && lng != null) {
Log.d(TAG, String.format("lat %f long %f", lat, lng));
// Creates marker on map
geoPin = new Marker(map);
geoPin.setPosition(new GeoPoint(lat, lng));
geoPin.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
// Stuff for distance
Location markerLocation = new Location("");
markerLocation.setLatitude(lat);
markerLocation.setLongitude(lng);
float distance = currentLocation.distanceTo(markerLocation);
String d = formatDistance(distance);
Log.d(TAG, String.format("Distance: %s", d));
// Creates custom info window for the marker
CustomInfoWindow blurb = new CustomInfoWindow(map, d, qrCode);
geoPin.setInfoWindow(blurb);
geoPin.setIcon(pinIcon);
// Shows/Hides info window on click
// From: https://stackoverflow.com/a/45043472
// Author: https://stackoverflow.com/users/6889839/fregomene
geoPin.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker, MapView mapView) {
if (!isInfoWindowShown) {
marker.showInfoWindow();
isInfoWindowShown = true;
} else {
marker.closeInfoWindow();
isInfoWindowShown = false;
}
return true;
}
});
// Adds the pins on the map
map.getOverlays().add(geoPin);
}
}
} else {
Log.d(TAG, "No such document");
}
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
return root;
}
Aggregations