use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class DeleteProductAdapter method onBindViewHolder.
/**
* Bind the view with data at the specified position
* @param holder ViewHolder which should be updated
* @param position position of items in the adapter
*/
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// Get Transaction Item
Product product = productList.get(position);
// Set Information on View
holder.userNameTextView.setText(product.getName());
holder.priceTextView.setText("Rp." + String.valueOf(product.getPrice()));
if (holder.checkBox.isChecked())
product.setChecked(true);
else
product.setChecked(false);
if (product.getImageUrl() != null) {
Glide.with(holder.imageView.getContext()).load(product.getImageUrl()).into(holder.imageView);
}
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class MainActivity method attachDatabaseReadListener.
private void attachDatabaseReadListener() {
if (productEventListener == null) {
productEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Product product = dataSnapshot.getValue(Product.class);
menuListAdapter.add(product);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
databaseProducts.addChildEventListener(productEventListener);
}
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize Navigation View
DrawerLayout drawerLayout = findViewById(R.id.main_drawer_layout);
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_open, R.string.navigation_close);
drawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState();
NavigationView navigationView = findViewById(R.id.main_navigation_view);
navigationView.setNavigationItemSelectedListener(new MainNavigationListener());
// Get User
firebaseAuth = FirebaseAuth.getInstance();
user = firebaseAuth.getCurrentUser();
// Initialize References
databaseUsers = FirebaseDatabase.getInstance().getReference("users");
databaseProducts = FirebaseDatabase.getInstance().getReference("products");
databaseStore = FirebaseDatabase.getInstance().getReference("store");
databaseWallet = FirebaseDatabase.getInstance().getReference("wallet");
// Product List
ArrayList<Product> productArrayList = new ArrayList<>();
menuListAdapter = new MenuListAdapter(this, productArrayList);
// Initialize ListView
productListView = findViewById(R.id.list);
productListView.setAdapter(menuListAdapter);
// Cart Button and Click Handler
placeOrder = findViewById(R.id.OrderButton);
placeOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cart = menuListAdapter.getList();
// Check empty cart
boolean emptyCart = true;
for (Cart c : cart) {
if (c.getQuantity() != 0) {
emptyCart = false;
break;
}
}
if (emptyCart == true) {
// Alert dialog if there are no items in cart
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("You don't have any items in your cart!").setCancelable(false).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.setTitle("Error");
alert.show();
} else {
// Remove item if qty is 0
ArrayList<Cart> toRemove = new ArrayList<>();
for (Cart c : cart) {
if (c.getQuantity() == 0) {
toRemove.add(c);
}
}
cart.removeAll(toRemove);
// Go to cart
Intent intent = new Intent(MainActivity.this, CartActivity.class);
intent.putExtra("Cart", cart);
intent.putExtra("Seller", menuListAdapter.getSeller());
startActivity(intent);
}
}
});
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class MerchantOrderDetailActivity method decreaseStock.
private void decreaseStock(final HashMap<String, HashMap<String, Integer>> details) {
final ArrayList<Object> keys = new ArrayList<>(Arrays.asList(details.keySet().toArray()));
final HashMap<String, Product> products = new HashMap<>();
Query productQuery = ProductsUtil.query("tokoId", transaction.getSid());
productQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Product product = snapshot.getValue(Product.class);
for (Object keyObject : keys) {
String key = (String) keyObject;
if (product.getName().equals(key)) {
snapshot.child("stock").getRef().setValue(product.getStock() - details.get(key).get("quantity"));
keys.remove(key);
}
}
}
if (keys.size() == 0) {
Toast.makeText(MerchantOrderDetailActivity.this, "Order Accepted", Toast.LENGTH_SHORT).show();
findViewById(R.id.progress_bar_layout).setVisibility(View.GONE);
finish();
} else {
Toast.makeText(MerchantOrderDetailActivity.this, "Not all stock updated", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.
the class EditProductActivity method getProduct.
public void getProduct() {
if (productEventListener == null) {
productEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Product product = dataSnapshot.getValue(Product.class);
if (merchant.getUid().equals(product.getTokoId())) {
productArrayList.add(product.getName().toString());
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, productArrayList);
spinner.setAdapter(dataAdapter);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
databaseProducts.addChildEventListener(productEventListener);
}
}
Aggregations