use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class EditProductActivity method submitData.
// To submit data
private void submitData() {
Log.i(TAG, "TEXT2 MASUK");
if (validateRegisterInfo()) {
Log.i(TAG, "TEXT2 MASUK LAGI");
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
final DatabaseReference reference = firebaseDatabase.getReference();
Query query = reference.child("products").orderByChild("tokoId").equalTo(merchant.getUid());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot productSnapshot : dataSnapshot.getChildren()) {
// DataSnapshot nodeDataSnapshot = dataSnapshot.getChildren().iterator().next();
Product product = productSnapshot.getValue(Product.class);
if (merchant.getUid().equals(product.getTokoId()) && product.getName().equals(choose.toString())) {
Log.i(TAG, "TEXT2 test " + productSnapshot.getValue().toString());
// Log.i(TAG, "TEXT2 test " + nodeDataSnapshot.getValue().toString());
// String key = nodeDataSnapshot.getKey();
// String path = "/" + dataSnapshot.getKey() + "/" + key;
HashMap<String, Object> result = new HashMap<>();
// result.put("imageUrl", );
result.put("name", productName.getText().toString());
// HashMap<Integer, Object> result2 = new HashMap<>();
result.put("price", Integer.parseInt(productPrice.getText().toString()));
result.put("stock", Integer.parseInt(productQty.getText().toString()));
result.put("imageUrl", profPicUrl);
if (product.getImageUrl() != null) {
StorageReference photoRef = FirebaseStorage.getInstance().getReferenceFromUrl(product.getImageUrl());
photoRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// File deleted successfully
Log.d(TAG, "onSuccess: deleted file");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
Log.d(TAG, "onFailure: did not delete file");
}
});
}
// if(!product.getImageUrl().equals())
reference.child("products").child(productSnapshot.getKey()).updateChildren(result);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Logger.error(TAG, ">>> Error:" + "find onCancelled:" + databaseError);
}
});
backToScreen();
}
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class EditProductActivity method getDataContent.
private void getDataContent() {
// Log.i(TAG,"TEST@@");
DatabaseReference productDatabase = FirebaseDatabase.getInstance().getReference();
productDatabase.child("products").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Log.i(TAG,"TEST@3");
for (DataSnapshot productSnapshot : dataSnapshot.getChildren()) {
Product product = productSnapshot.getValue(Product.class);
// Log.i(TAG,"TEST PRD "+ product.toString());
if (merchant.getUid().equals(product.getTokoId()) && product.getName().equals(choose.toString())) {
Log.i(TAG, "TEST " + product.getName() + " " + product.getPrice() + " " + product.getStock());
productName.setText(product.getName().toString());
productQty.setText(product.getStock().toString());
productPrice.setText(product.getPrice().toString());
if (product.getImageUrl() != null) {
Glide.with(imageView.getContext()).load(product.getImageUrl()).into(imageView);
} else
imageView.setImageResource(R.drawable.logo3);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class EditProductActivity method submitDatawithoutImage.
private void submitDatawithoutImage() {
Log.i(TAG, "TEXT2 MASUK");
if (validateRegisterInfo()) {
Log.i(TAG, "TEXT2 MASUK LAGI");
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
final DatabaseReference reference = firebaseDatabase.getReference();
Query query = reference.child("products").orderByChild("tokoId").equalTo(merchant.getUid());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot productSnapshot : dataSnapshot.getChildren()) {
// DataSnapshot nodeDataSnapshot = dataSnapshot.getChildren().iterator().next();
Product product = productSnapshot.getValue(Product.class);
if (merchant.getUid().equals(product.getTokoId()) && product.getName().equals(choose.toString())) {
Log.i(TAG, "TEXT2 test " + productSnapshot.getValue().toString());
// String key = nodeDataSnapshot.getKey();
// String path = "/" + dataSnapshot.getKey() + "/" + key;
HashMap<String, Object> result = new HashMap<>();
// result.put("imageUrl", );
result.put("name", productName.getText().toString());
// HashMap<Integer, Object> result2 = new HashMap<>();
result.put("price", Integer.parseInt(productPrice.getText().toString()));
result.put("stock", Integer.parseInt(productQty.getText().toString()));
// if(!product.getImageUrl().equals())
reference.child("products").child(productSnapshot.getKey()).updateChildren(result);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Logger.error(TAG, ">>> Error:" + "find onCancelled:" + databaseError);
}
});
backToScreen();
}
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class ProductListAdapter method getView.
public View getView(int position, View view, ViewGroup parent) {
final OrderHolder holder;
if (view == null) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
view = inflater.inflate(R.layout.product_adapter_list, parent, false);
holder = new OrderHolder();
// Initialize views
holder.txtTitle = view.findViewById(R.id.itemName);
holder.imageView = view.findViewById(R.id.icon);
holder.extratxt = view.findViewById(R.id.price);
holder.seller = view.findViewById(R.id.seller);
holder.quantityOrder = view.findViewById(R.id.quantityOrder);
view.setTag(holder);
} else {
holder = (OrderHolder) view.getTag();
}
// Get product
Product product = getItem(position);
// Initialize HashMap for Order Quantity
if (Order.get(product.getName()) == null) {
Order.put(product.getName(), product.getStock());
}
// Set Texts
holder.txtTitle.setText(product.getName());
holder.extratxt.setText("Rp " + product.getPrice());
holder.quantityOrder.setText(String.valueOf(Order.get(holder.txtTitle.getText().toString())));
// Get image
if (product.getImageUrl() != null) {
Glide.with(holder.imageView.getContext()).load(product.getImageUrl()).into(holder.imageView);
}
return view;
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class UserProductItemAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// Get product
Product product = products.get(position);
// Set on view
holder.productNameTextView.setText(product.getName());
holder.productPriceTextView.setText("Rp " + String.valueOf(product.getPrice()));
holder.productStockTextView.setText("Stock: " + String.valueOf(product.getStock()));
// Get image
if (product.getImageUrl() != null) {
Glide.with(holder.productImageView.getContext()).load(product.getImageUrl()).into(holder.productImageView);
}
}
Aggregations