I am trying to persist a custom object using the following code:
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
Databas
//this will recreate your Object list by the constructor
private void handleData(){
orderList = Db.getCarts();
orders = new ArrayList<>();
Double totalPrice = 0.0;
for (Order order : orderList){
// totalPrice = totalPrice + ( price * quantity )
totalPrice += (Double.valueOf(order.getPrice())* Integer.valueOf(order.getQuantity()));
orders.add(new Order(order.getProductId(),order.getProductName(),order.getQuantity(),order.getPrice(),order.getDiscount(),order.getImage()));
}
}
private void alertDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle("One more step!");
alert.setMessage("Enter your address");
final EditText edtaddress = new EditText(getContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
edtaddress.setLayoutParams(layoutParams);
alert.setView(edtaddress);
alert.setIcon(R.drawable.ic_shopping_cart_black_24dp);
alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Request request = new Request(
Common.currentUser.getPhone(),
Common.currentUser.getName(),
edtaddress.getText().toString(),
textTotal.getText().toString(),
orders
);
// Submit to firebase
// We will using system.currentMillis to key
requestReference.child(String.valueOf(System.currentTimeMillis()))
.setValue(request);
//Delete cart
Db.deleteCart();
Toast.makeText(getContext(), "Thank you , Order Place", Toast.LENGTH_SHORT).show();
getActivity().finish();
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}