Search in sources :

Example 16 with Product

use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.

the class DeleteProductFragment 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);
                if (merchant.getUid().equals(product.getTokoId()))
                    deleteAdapter.addProductList(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);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Product(com.example.asus.onlinecanteen.model.Product) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 17 with Product

use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.

the class UserProductListFragment method attachProductDatabaseListener.

// ----------------  FIREBASE CHILD EVENT LISTENER -----------------//
private void attachProductDatabaseListener() {
    if (productsEventListener == null) {
        productsEventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                Product product = dataSnapshot.getValue(Product.class);
                userProductItemAdapter.addProduct(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) {
            }
        };
        productsQuery.addChildEventListener(productsEventListener);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Product(com.example.asus.onlinecanteen.model.Product) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 18 with Product

use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.

the class UserOrderProductAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    // Get product and cart
    Cart cart = orders.get(position);
    Product product = products.get(position);
    // Set on view
    holder.userOrderProductNameTextView.setText(cart.getProductName());
    holder.userOrderProductPriceTextView.setText("Rp " + String.valueOf(cart.getProductPrice()));
    holder.userOrderProductQuantityTextView.setText(String.valueOf(cart.getQuantity()));
    // Get image
    if (product.getImageUrl() != null) {
        Glide.with(holder.userOrderProductImageView.getContext()).load(product.getImageUrl()).into(holder.userOrderProductImageView);
    }
    if (product.getStock() <= 0) {
        holder.userOrderProductIncreaseButton.setEnabled(false);
        holder.userOrderProductDecreaseButton.setEnabled(false);
        holder.userOrderProductIncreaseButton.setBackgroundColor(ContextCompat.getColor(holder.itemView.getContext(), R.color.gray));
        holder.userOrderProductDecreaseButton.setBackgroundColor(ContextCompat.getColor(holder.itemView.getContext(), R.color.gray));
        holder.outOfStockLayout.setVisibility(View.VISIBLE);
    } else {
        holder.outOfStockLayout.setVisibility(View.GONE);
    }
}
Also used : Product(com.example.asus.onlinecanteen.model.Product) Cart(com.example.asus.onlinecanteen.model.Cart)

Example 19 with Product

use of com.example.asus.onlinecanteen.model.Product in project OnlineCanteen by josephgunawan97.

the class MerchantProductListFragment 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);
                if (merchant.getUid().equals(product.getTokoId()))
                    menuListAdapter.add(product);
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                Product product = dataSnapshot.getValue(Product.class);
                if (merchant.getUid().equals(product.getTokoId()))
                    menuListAdapter.add(product);
            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        };
        databaseProducts.addChildEventListener(productEventListener);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Product(com.example.asus.onlinecanteen.model.Product) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Aggregations

Product (com.example.asus.onlinecanteen.model.Product)19 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)12 ValueEventListener (com.google.firebase.database.ValueEventListener)7 ChildEventListener (com.google.firebase.database.ChildEventListener)6 DatabaseReference (com.google.firebase.database.DatabaseReference)4 Query (com.google.firebase.database.Query)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Activity (android.app.Activity)2 View (android.view.View)2 ListView (android.widget.ListView)2 Cart (com.example.asus.onlinecanteen.model.Cart)2 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)2 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)2 StorageReference (com.google.firebase.storage.StorageReference)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1