Search in sources :

Example 1 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project startup-os by google.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FirebaseFirestore db = FirebaseFirestore.getInstance();
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore)

Example 2 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project noChange by Khalidtoak.

the class AddChangeOrDebt method saveNewRecordOnline.

private void saveNewRecordOnline(Payment payment) {
    if (pathForImage != null) {
        Uri imageUri = Uri.fromFile(new File(pathForImage));
        StorageReference storageRef = FirebaseStorage.getInstance().getReference();
        StorageReference imageRef = storageRef.child(Constant.IMAGE_COLLECTION).child(String.format(Locale.getDefault(), "payment_%s.jpg", String.valueOf(System.currentTimeMillis())));
        imageRef.putFile(imageUri).continueWithTask(task -> {
            if (!task.isSuccessful()) {
                showError(Objects.requireNonNull(task.getException()));
            }
            // Continue with the task to get the download URL
            return imageRef.getDownloadUrl();
        }).addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                Uri downloadUri = task.getResult();
                assert downloadUri != null;
                setPathForImage(downloadUri.toString());
                FirebaseFirestore firestore = FirebaseFirestore.getInstance();
                firestore.collection(Constant.USER_COLLECTION).document(FirebaseAuth.getInstance().getCurrentUser().getUid()).collection(Constant.PAYMENT_COLLECTION).document(phoneNumber).set(payment, SetOptions.merge()).addOnSuccessListener(aVoid -> {
                    progressBar.setVisibility(View.INVISIBLE);
                    save.setEnabled(true);
                    showToast("Successfully saved!");
                    // start the DashBoard Activity
                    Intent intent = new Intent(getApplicationContext(), DashBoard.class);
                    startActivity(intent);
                    finish();
                }).addOnFailureListener(error -> {
                    showError(error);
                    progressBar.setVisibility(View.INVISIBLE);
                    save.setEnabled(true);
                });
            } else {
                return;
            }
        });
    } else {
        progressBar.setVisibility(View.INVISIBLE);
        save.setEnabled(true);
        (Toast.makeText(this, "Please upload an image to recognize user before continuing", Toast.LENGTH_LONG)).show();
    }
}
Also used : Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Date(java.util.Date) Uri(android.net.Uri) RadioButton(android.widget.RadioButton) SimpleDateFormat(java.text.SimpleDateFormat) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) Intent(android.content.Intent) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) MenuItem(android.view.MenuItem) Locale(java.util.Locale) MediaStore(android.provider.MediaStore) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Toast(android.widget.Toast) View(android.view.View) SetOptions(com.google.firebase.firestore.SetOptions) Log(android.util.Log) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) FirebaseStorage(com.google.firebase.storage.FirebaseStorage) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Objects(java.util.Objects) Constant(com.group1.swepproject.user.nochange.data.Constant) Payment(com.group1.swepproject.user.nochange.models.Payment) Glide(com.bumptech.glide.Glide) CreditorsAndDebtorsDataBase(com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase) Bitmap(android.graphics.Bitmap) StorageReference(com.google.firebase.storage.StorageReference) EditText(android.widget.EditText) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) StorageReference(com.google.firebase.storage.StorageReference) Intent(android.content.Intent) Uri(android.net.Uri) File(java.io.File)

Example 3 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project noChange by Khalidtoak.

the class AppViewModel method getPayment.

public LiveData<ArrayList<Payment>> getPayment(String type, String searchWord) {
    FirebaseFirestore firestore = FirebaseFirestore.getInstance();
    MutableLiveData<ArrayList<Payment>> response = new MutableLiveData<>();
    firestore.collection(Constant.USER_COLLECTION).document(FirebaseAuth.getInstance().getCurrentUser().getUid()).collection(Constant.PAYMENT_COLLECTION).orderBy("timestamp").whereEqualTo("type", type).whereGreaterThanOrEqualTo("name", searchWord).get().addOnSuccessListener(res -> {
        response.postValue((ArrayList<Payment>) res.toObjects(Payment.class));
    }).addOnFailureListener(e -> {
        e.printStackTrace();
        Log.i("Could not fetch data", "Could not fetch data");
        response.postValue(null);
    });
    return response;
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) LiveData(androidx.lifecycle.LiveData) Constant(com.group1.swepproject.user.nochange.data.Constant) Application(android.app.Application) NonNull(androidx.annotation.NonNull) AndroidViewModel(androidx.lifecycle.AndroidViewModel) Log(android.util.Log) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) ArrayList(java.util.ArrayList) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) ArrayList(java.util.ArrayList) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 4 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project startup-os by google.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FirebaseFirestore db = FirebaseFirestore.getInstance();
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore)

Example 5 with FirebaseFirestore

use of com.google.firebase.firestore.FirebaseFirestore in project DisasterApp by cutmail.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    FirebaseFirestore firestore = FirebaseFirestore.getInstance();
    collectionReference = firestore.collection("entries");
    setupLayout();
    setupRateDialog();
    AppRate.showRateDialogIfMeetsConditions(this);
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore)

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