Search in sources :

Example 1 with Payment

use of com.group1.swepproject.user.nochange.models.Payment in project noChange by Khalidtoak.

the class AddChangeOrDebt method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_change_or_debt);
    // find all the views
    customerName = findViewById(R.id.edit_text_name);
    ItemBought = findViewById(R.id.itemBought);
    HowMuch = findViewById(R.id.edit_text_Amount);
    save = findViewById(R.id.fab_for_save);
    addImage = findViewById(R.id.add_profileImage);
    AddPhoneNumber = findViewById(R.id.phone_no);
    progressBar = findViewById(R.id.progress_circular);
    ChangeradButton = findViewById(R.id.radButton1);
    creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(this);
    DebtRadButton = findViewById(R.id.radButton2);
    // set default checked rad button to the one for change
    ChangeradButton.setChecked(true);
    ChangeOrDebit = "Change";
    // when you click on the floating action button for taking a picture
    addImage.setOnClickListener(view -> {
        // use an implicit intent to launch camera
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // startActivity
        startActivityForResult(intent, REQUEST_CAPTURE_IMAGE);
    });
    // when we click save
    save.setOnClickListener(view -> {
        progressBar.setVisibility(View.VISIBLE);
        save.setEnabled(false);
        // we get the text from each of the edit Text
        String customersname = customerName.getText().toString();
        String boughtStuff = ItemBought.getText().toString();
        String howMuch = HowMuch.getText().toString();
        // get the change or debt rad button
        String debtOrChange = ChangeOrDebit;
        // get the text of the phone number editText
        phoneNumber = AddPhoneNumber.getText().toString();
        // editText length is not 11
        if (phoneNumber.length() != 0) {
            if (!(phoneNumber.substring(0, 2).equals("080") || phoneNumber.substring(0, 2).equals("090") || phoneNumber.substring(0, 2).equals("070") || phoneNumber.length() == 11 || phoneNumber.substring(0, 2).equals("081"))) {
                // you tell the user his phone number is invalid and don't go futher by calling return
                progressBar.setVisibility(View.INVISIBLE);
                save.setEnabled(true);
                Toast.makeText(getApplicationContext(), "Invalid phone Number", Toast.LENGTH_LONG).show();
                return;
            }
        }
        // if any of the editTexts are empty... we also tell the user and do not go further
        if (customersname.length() == 0 || boughtStuff.length() == 0 || howMuch.length() == 0 || debtOrChange.length() == 0 || phoneNumber.length() == 0) {
            progressBar.setVisibility(View.INVISIBLE);
            save.setEnabled(true);
            Toast.makeText(getApplicationContext(), "please fill in all fields", Toast.LENGTH_LONG).show();
            return;
        }
        // now we save the customer's details
        // public Payment(String customerName, String item, String amount, String type, String imageUrl, String ohoneNumber) {
        Payment payment = new Payment(customersname, boughtStuff, howMuch, debtOrChange, getPathForImage(), phoneNumber, FirebaseAuth.getInstance().getCurrentUser().getUid());
        saveNewRecordOnline(payment);
    // creditorsAndDebtorsDataBase.SaveLecturesAdded(customersname, boughtStuff, howMuch, debtOrChange,
    // getPathForImage(), phoneNumber);
    // Log.d("ContentVals: ", "onClick: " + customersname + boughtStuff + howMuch + debtOrChange);
    // Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_LONG).show();
    // //start the DashBoard Activity
    // Intent intent = new Intent(AddChangeOrDebt.this, DashBoard.class);
    // startActivity(intent);
    });
}
Also used : CreditorsAndDebtorsDataBase(com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase) Payment(com.group1.swepproject.user.nochange.models.Payment) Intent(android.content.Intent)

Example 2 with Payment

use of com.group1.swepproject.user.nochange.models.Payment 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 Payment

use of com.group1.swepproject.user.nochange.models.Payment 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 Payment

use of com.group1.swepproject.user.nochange.models.Payment in project noChange by Khalidtoak.

the class Adapters method onBindViewHolder.

@Override
public void onBindViewHolder(final AdapterViewHolder holder, int position) {
    // get the values in our table that we have queried
    // by calling get column Index
    // and passing the column name
    List<DocumentSnapshot> paymentSnapShots = getSnapshots();
    Payment payment = paymentSnapShots.get(position).toObject(Payment.class);
    final String customerName = payment.getCustomerName();
    String boughtStuff = payment.getItem();
    String howMuch = payment.getAmount();
    String Time = payment.getTimestamp().toString();
    String DebtOrChange = payment.getType();
    final String phoneNo = payment.getPhoneNumber();
    Log.d("customerName", customerName + " = ");
    // display this data on our recyclerview
    holder.CustomerName.setText(customerName);
    holder.ItemBought.setText("bought Item: " + boughtStuff);
    holder.amount.setText(howMuch + "Naira");
    holder.time.setText(Time);
    // holder.itemView.setTag());
    // for the Image ..we made use of glide Image loading library and using the Circle transform class created
    // in the utils package... we display the circuilar version of the image
    Glide.with(context).load(payment.getImageUrl()).crossFade().into(holder.imageProfile);
    // an image button is a clickable image
    // we create a pop up menu and set a listener for it so that we click it...
    // we will bw able to perform a certain action
    holder.callOrTextessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            PopupMenu popupMenu = new PopupMenu(context, holder.callOrTextessage);
            // we always inflate menus in android or else the menu won't show
            // A menu resource defines an application menu
            // (Options Menu, Context Menu, or submenu) that can be inflated with MenuInflater
            popupMenu.inflate(R.menu.menu);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                popupMenu.setGravity(Gravity.CENTER);
            }
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    // get the id of the item that was clicked in the menu
                    switch(menuItem.getItemId()) {
                        // if call is clicked
                        case R.id.call:
                            // open the dialer using an implicit intent
                            /**
                             * An intent is an abstract description of an operation to be performed.
                             * It can be used with startActivity to launch an Activity,
                             * broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent)
                             * or bindService(Intent, ServiceConnection, int) to communicate with a Background Service.
                             * Explicit intent launches an intent in your app while implicit intents launches another app
                             * from your app
                             * here we are launching the dialer app from our app *
                             */
                            openDialer(phoneNo);
                            break;
                        case R.id.send_text_message:
                            // here we will launch the sms app from our app
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNo));
                            context.startActivity(intent);
                            break;
                    }
                    return false;
                }
            });
            // show the popup menu
            popupMenu.show();
        }
    });
}
Also used : DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) Payment(com.group1.swepproject.user.nochange.models.Payment) MenuItem(android.view.MenuItem) Intent(android.content.Intent) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) PopupMenu(android.widget.PopupMenu)

Example 5 with Payment

use of com.group1.swepproject.user.nochange.models.Payment in project noChange by Khalidtoak.

the class AppViewModel method getAllPayment.

public LiveData<ArrayList<Payment>> getAllPayment(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)

Aggregations

Intent (android.content.Intent)3 Log (android.util.Log)3 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)3 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)3 Constant (com.group1.swepproject.user.nochange.data.Constant)3 Payment (com.group1.swepproject.user.nochange.models.Payment)3 Application (android.app.Application)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 NonNull (androidx.annotation.NonNull)2 AndroidViewModel (androidx.lifecycle.AndroidViewModel)2 LiveData (androidx.lifecycle.LiveData)2 MutableLiveData (androidx.lifecycle.MutableLiveData)2 CreditorsAndDebtorsDataBase (com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 ArrayList (java.util.ArrayList)2 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 MediaStore (android.provider.MediaStore)1