Search in sources :

Example 16 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project firebase-android-sdk by firebase.

the class IntegrationTestUtil method testFirestore.

/**
 * Initializes a new Firestore instance that uses the default project, customized with the
 * provided settings.
 */
public static FirebaseFirestore testFirestore(FirebaseFirestoreSettings settings) {
    FirebaseFirestore firestore = testFirestore(provider.projectId(), Level.DEBUG, settings);
    primeBackend();
    return firestore;
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore)

Example 17 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project firebase-android-sdk by firebase.

the class IntegrationTestUtil method tearDown.

public static void tearDown() {
    try {
        for (FirebaseFirestore firestore : firestoreStatus.keySet()) {
            Task<Void> result = firestore.terminate();
            waitFor(result);
        }
    } finally {
        firestoreStatus.clear();
    }
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore)

Example 18 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project firebase-android-sdk by firebase.

the class FirestoreTest method setShouldTriggerListenerWithNewlySetData.

@Test
public void setShouldTriggerListenerWithNewlySetData() throws Exception {
    FirebaseAuth auth = FirebaseAuth.getInstance();
    FirebaseFirestore firestore = FirebaseFirestore.getInstance();
    auth.signOut();
    Task<?> signInTask = auth.signInWithEmailAndPassword("test@mailinator.com", "password");
    Tasks2.waitForSuccess(signInTask);
    DocumentReference doc = firestore.collection("restaurants").document(TestId.create());
    SnapshotListener listener = new SnapshotListener();
    ListenerRegistration registration = doc.addSnapshotListener(listener);
    try {
        HashMap<String, Object> data = new HashMap<>();
        data.put("location", "Google NYC");
        Task<?> setTask = doc.set(new HashMap<>(data));
        Task<DocumentSnapshot> snapshotTask = listener.toTask();
        Tasks2.waitForSuccess(setTask);
        Tasks2.waitForSuccess(snapshotTask);
        DocumentSnapshot result = snapshotTask.getResult();
        assertThat(result.getData()).isEqualTo(data);
    } finally {
        registration.remove();
        Tasks2.waitBestEffort(doc.delete());
    }
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) HashMap(java.util.HashMap) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) DocumentReference(com.google.firebase.firestore.DocumentReference) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) Test(org.junit.Test)

Example 19 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore 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 20 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project QRHunt by CMPUT301W22T00.

the class QrCodeProcessor method processQRCode.

/**
 * Processes QR code to be added
 */
public void processQRCode() {
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    // todo check here: is this an internal code
    computeHash();
    computeScore();
    PlayableQrCode qrCode = new PlayableQrCode(playerId, hash, score);
    getLocation().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            Location location = task.getResult();
            if (location != null) {
                qrCode.setLocation(new QrLocation(location));
            }
            /* this stops listening to the updates that
                                we didn't actually care about in the first place for; see startPollingLocation
                                 */
            LocationServices.getFusedLocationProviderClient(activity).removeLocationUpdates(hackyLocationCallback);
            FragmentAddQrCode addQrCode = FragmentAddQrCode.newInstance(qrCode);
            addQrCode.show(frag.getChildFragmentManager(), FragmentAddQrCode.TAG);
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Location(android.location.Location)

Aggregations

FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)21 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)6 HashMap (java.util.HashMap)6 Intent (android.content.Intent)5 Log (android.util.Log)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 View (android.view.View)3 NonNull (androidx.annotation.NonNull)3 DocumentReference (com.google.firebase.firestore.DocumentReference)3 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)3 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)3 Constant (com.group1.swepproject.user.nochange.data.Constant)3 Test (org.junit.Test)3 Application (android.app.Application)2 Bitmap (android.graphics.Bitmap)2 Location (android.location.Location)2 Bundle (android.os.Bundle)2 MediaStore (android.provider.MediaStore)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2