Search in sources :

Example 11 with Product

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();
    }
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) Query(com.google.firebase.database.Query) StorageReference(com.google.firebase.storage.StorageReference) DatabaseReference(com.google.firebase.database.DatabaseReference) HashMap(java.util.HashMap) Product(com.example.asus.onlinecanteen.model.Product) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseError(com.google.firebase.database.DatabaseError) NonNull(android.support.annotation.NonNull) ValueEventListener(com.google.firebase.database.ValueEventListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 12 with Product

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) {
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) Product(com.example.asus.onlinecanteen.model.Product) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 13 with Product

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();
    }
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseError(com.google.firebase.database.DatabaseError) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) HashMap(java.util.HashMap) Product(com.example.asus.onlinecanteen.model.Product) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 14 with Product

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;
}
Also used : LayoutInflater(android.view.LayoutInflater) Activity(android.app.Activity) Product(com.example.asus.onlinecanteen.model.Product)

Example 15 with Product

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);
    }
}
Also used : Product(com.example.asus.onlinecanteen.model.Product)

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