Search in sources :

Example 36 with QueryDocumentSnapshot

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());
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Example 37 with QueryDocumentSnapshot

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);
        }
    });
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) FirebaseUser(com.google.firebase.auth.FirebaseUser) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 38 with QueryDocumentSnapshot

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);
            }
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Category(com.example.app_restaurante.Model.Category) AdapterCategory(com.example.app_restaurante.Adapter.AdapterCategory) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) AdapterFood(com.example.app_restaurante.Adapter.AdapterFood) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) AdapterFood(com.example.app_restaurante.Adapter.AdapterFood) Food(com.example.app_restaurante.Model.Food)

Example 39 with QueryDocumentSnapshot

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();
        }
    });
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 40 with QueryDocumentSnapshot

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;
}
Also used : Query(com.google.firebase.firestore.Query) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PlayableQrCode(com.bigyoshi.qrhunt.qr.PlayableQrCode) Marker(org.osmdroid.views.overlay.Marker) View(android.view.View) MapView(org.osmdroid.views.MapView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) GeoPoint(org.osmdroid.util.GeoPoint) MapView(org.osmdroid.views.MapView) IConfigurationProvider(org.osmdroid.config.IConfigurationProvider) IMapController(org.osmdroid.api.IMapController) File(java.io.File) Location(android.location.Location) SuppressLint(android.annotation.SuppressLint)

Aggregations

QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)73 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)33 ArrayList (java.util.ArrayList)30 View (android.view.View)22 NonNull (androidx.annotation.NonNull)19 Task (com.google.android.gms.tasks.Task)18 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)17 Intent (android.content.Intent)16 CollectionReference (com.google.firebase.firestore.CollectionReference)13 AdapterView (android.widget.AdapterView)12 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)12 TextView (android.widget.TextView)10 Bundle (android.os.Bundle)9 ListView (android.widget.ListView)9 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)9 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)8 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 FirebaseUser (com.google.firebase.auth.FirebaseUser)6 DocumentReference (com.google.firebase.firestore.DocumentReference)6