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);
});
}
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();
}
}
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;
}
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();
}
});
}
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;
}
Aggregations