Search in sources :

Example 1 with FirebaseFirestoreSettings

use of com.google.firebase.firestore.FirebaseFirestoreSettings in project snippets-android by firebase.

the class DocSnippets method setupCacheSize.

public void setupCacheSize() {
    // [START fs_setup_cache]
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED).build();
    db.setFirestoreSettings(settings);
// [END fs_setup_cache]
}
Also used : FirebaseFirestoreSettings(com.google.firebase.firestore.FirebaseFirestoreSettings)

Example 2 with FirebaseFirestoreSettings

use of com.google.firebase.firestore.FirebaseFirestoreSettings in project snippets-android by firebase.

the class DocSnippets method setup.

public void setup() {
    // [START get_firestore_instance]
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    // [END get_firestore_instance]
    // [START set_firestore_settings]
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).build();
    db.setFirestoreSettings(settings);
// [END set_firestore_settings]
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) FirebaseFirestoreSettings(com.google.firebase.firestore.FirebaseFirestoreSettings)

Example 3 with FirebaseFirestoreSettings

use of com.google.firebase.firestore.FirebaseFirestoreSettings in project AlphaTour by Frank99DG.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    db = FirebaseFirestore.getInstance();
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).build();
    db.setFirestoreSettings(settings);
    auth = FirebaseAuth.getInstance();
    email = findViewById(R.id.loginInputEmail);
    password = findViewById(R.id.loginInputPassword);
    loadingBar = findViewById(R.id.loginLoadingBar);
}
Also used : FirebaseFirestoreSettings(com.google.firebase.firestore.FirebaseFirestoreSettings)

Example 4 with FirebaseFirestoreSettings

use of com.google.firebase.firestore.FirebaseFirestoreSettings in project spacecraft-android by JamesfChen.

the class FirebaseDatabaseActivity method onCreate.

// @AddTrace(name = "FirebaseDatabaseActivity_onCreateTrace", enabled = true /* optional */)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    database.setPersistenceEnabled(true);
    database.setPersistenceCacheSizeBytes(50 * 1024 * 1024);
    database.setLogLevel(Logger.Level.DEBUG);
    DatabaseReference myRef = database.getReference();
    myRef.child("user");
    myRef.setValue("Hello, World!");
    myRef.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // This method is called once with the initial value and again
            // whenever data at this location is updated.
            String value = dataSnapshot.getValue(String.class);
            Log.d("hawks", "Value is: " + value);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w("hawks", "Failed to read value.", error.toException());
        }
    });
    FirebaseFirestoreSettings build = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).setCacheSizeBytes(50 * 10241024).build();
    databasev2.setFirestoreSettings(build);
    // Create a new user with a first and last name
    Map<String, Object> user = new HashMap<>();
    user.put("first", "Ada");
    user.put("last", "Lovelace");
    user.put("born", 1815);
    // Add a new document with a generated ID
    databasev2.collection("users").add(user).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

        @Override
        public void onSuccess(DocumentReference documentReference) {
            Log.d("hawks", "DocumentSnapshot added with ID: " + documentReference.getId());
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w("hawks", "Error adding document", e);
        }
    });
    // Create a new user with a first, middle, and last name
    Map<String, Object> user2 = new HashMap<>();
    user.put("first", "Alan");
    user.put("middle", "Mathison");
    user.put("last", "Turing");
    user.put("born", 1912);
    // Add a new document with a generated ID
    databasev2.collection("users").add(user2).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

        @Override
        public void onSuccess(DocumentReference documentReference) {
            Log.d("hawks", "DocumentSnapshot added with ID: " + documentReference.getId());
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w("hawks", "Error adding document", e);
        }
    });
    // Log.d("hawks", "enableNetwork : " + databasev2.enableNetwork().isSuccessful());
    databasev2.collection("users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot document : task.getResult()) {
                    Log.d("hawks", document.getId() + " => " + document.getData());
                }
            } else {
                Log.w("hawks", "Error getting documents.", task.getException());
            }
        }
    });
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) HashMap(java.util.HashMap) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DataSnapshot(com.google.firebase.database.DataSnapshot) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) FirebaseFirestoreSettings(com.google.firebase.firestore.FirebaseFirestoreSettings) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) DocumentReference(com.google.firebase.firestore.DocumentReference) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 5 with FirebaseFirestoreSettings

use of com.google.firebase.firestore.FirebaseFirestoreSettings in project snippets-android by firebase.

the class EmulatorSuite method emulatorSettings.

public void emulatorSettings() {
    // [START fs_emulator_connect]
    // 10.0.2.2 is the special IP address to connect to the 'localhost' of
    // the host computer from an Android emulator.
    FirebaseFirestore firestore = FirebaseFirestore.getInstance();
    firestore.useEmulator("10.0.2.2", 8080);
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build();
    firestore.setFirestoreSettings(settings);
// [END fs_emulator_connect]
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) FirebaseFirestoreSettings(com.google.firebase.firestore.FirebaseFirestoreSettings)

Aggregations

FirebaseFirestoreSettings (com.google.firebase.firestore.FirebaseFirestoreSettings)5 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)2 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1 DocumentReference (com.google.firebase.firestore.DocumentReference)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1 HashMap (java.util.HashMap)1