Advertisement
Carelkat

ViewNote

Apr 7th, 2021
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. public class ViewProduct extends AppCompatActivity {
  2.  
  3.     private String edit_product_ID;
  4.     //private String edit_product_Product;
  5.     private String edit_product_Price;
  6.  
  7.     private EditText productView, priceView;
  8.     private TextView mSave, mDelete;
  9.     private FirebaseFirestore db = FirebaseFirestore.getInstance();
  10.  
  11.     private static final String KEY_PRODUCT = "product";
  12.     private static final String KEY_PRICE = "price";
  13.  
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.view_product);
  18.  
  19.         Intent intent = getIntent();
  20.         String product;
  21.         String price;
  22.         String id;
  23.  
  24.         id = String.valueOf(getIntent().getExtras().get("Id"));
  25.         product = String.valueOf(getIntent().getExtras().get("Product"));
  26.         price = String.valueOf(getIntent().getExtras().get("Price"));
  27.  
  28.         Toast.makeText(this, "The Product ID: " + id +
  29.                 " Product Name " + product + " Product Price " + price, Toast.LENGTH_LONG).show();
  30.  
  31.         EditText productView = findViewById(R.id.product);
  32.         productView.setText(product);
  33.         EditText priceView = findViewById(R.id.price);
  34.         priceView.setText(price);
  35.         mSave = (TextView) findViewById(R.id.save);
  36.         mDelete = (TextView) findViewById(R.id.delete);
  37.  
  38.     }
  39.  
  40.     public void saveProduct(View view) {
  41.         String product = productView.getText().toString();
  42.         String price = priceView.getText().toString();
  43.  
  44.         Map<String, Object> product_update = new HashMap<>();
  45.         product_update.put(KEY_PRODUCT, product);
  46.         product_update.put(KEY_PRICE, price);
  47.  
  48.         db.collection("ultra_liquors").document().set(product_update)
  49.                 .addOnSuccessListener(new OnSuccessListener<Void>() {
  50.                     @Override
  51.                     public void onSuccess(Void aVoid) {
  52.                         Toast.makeText(ViewProduct.this, "Product saved", Toast.LENGTH_SHORT).show();
  53.                     }
  54.                 })
  55.                 .addOnFailureListener(new OnFailureListener() {
  56.                     @Override
  57.                     public void onFailure(@NonNull Exception e) {
  58.                         Toast.makeText(ViewProduct.this, "Not saved", Toast.LENGTH_SHORT).show();
  59.                     }
  60.                 });
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement