Search in sources :

Example 6 with Product

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

the class RegisterProductActivity method uploadImage.

// To upload image
private void uploadImage() {
    Log.d(TAG, "Uploading...");
    final StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("product/" + System.currentTimeMillis() + ".jpg");
    if (imageUri != null) {
        profileImageRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                @SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();
                profPicUrl = downloadUrl.toString();
                Product productInfo = new Product(user.getUid(), productnameET.getText().toString(), Integer.parseInt(quantityET.getText().toString()), Integer.parseInt(priceET.getText().toString()), profPicUrl);
                databaseProducts.push().setValue(productInfo);
                // profPicUrl = profileImageRef.toString();
                // Toast.makeText(getApplicationContext(),profPicUrl,Toast.LENGTH_LONG).show();
                Log.d(TAG, "Success in uploading");
            // backToScreen();
            }
        }).addOnFailureListener(new OnFailureListener() {

            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getApplicationContext(), "Image failed to upload", Toast.LENGTH_LONG).show();
            // backToScreen();
            }
        });
    } else {
        Product productInfo = new Product(user.getUid(), productnameET.getText().toString(), Integer.parseInt(quantityET.getText().toString()), Integer.parseInt(priceET.getText().toString()), null);
        databaseProducts.push().setValue(productInfo);
    }
}
Also used : UploadTask(com.google.firebase.storage.UploadTask) StorageReference(com.google.firebase.storage.StorageReference) Product(com.example.asus.onlinecanteen.model.Product) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) Uri(android.net.Uri) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 7 with Product

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

the class DeleteProductFragment method deleteProduct.

public void deleteProduct() {
    Query data;
    for (int i = 0; i < deleteAdapter.getItemCount(); i++) {
        data = databaseProducts.orderByChild("name").equalTo(productArrayList.get(i).getName());
        final Product product2 = productArrayList.get(i);
        data.addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot productSnapshot : dataSnapshot.getChildren()) {
                    if (merchant.getUid().equals(product2.getTokoId()) && product2.isChecked())
                        productSnapshot.getRef().removeValue();
                }
            }

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

Example 8 with Product

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

the class FeaturedProductAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    // Get Product Featured Item
    final Product product = featuredProducts.get(position);
    FirebaseDatabase.getInstance().getReference("store").child(product.getTokoId()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            holder.featuredProductSellerTextView.setText(dataSnapshot.child("storeName").getValue().toString());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    // Set information
    holder.featuredProductNameTextView.setText(product.getName());
    if (product.getImageUrl() != null) {
        Glide.with(holder.featuredProductImageView.getContext()).load(product.getImageUrl()).into(holder.featuredProductImageView);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Product(com.example.asus.onlinecanteen.model.Product) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 9 with Product

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

the class MainUserFragment method attachFeaturedDatabaseListener.

private void attachFeaturedDatabaseListener() {
    if (featuredProductEventListener == null) {
        featuredProductEventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                String productId = dataSnapshot.child("productId").getValue().toString();
                DatabaseReference ref = FirebaseDatabase.getInstance().getReference("products").child(productId);
                ref.addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot snapshot) {
                        Product product = snapshot.getValue(Product.class);
                        featuredProductAdapter.addProduct(product);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                    }
                });
            }

            @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) {
            }
        };
        featuredQuery.addChildEventListener(featuredProductEventListener);
    }
}
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) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 10 with Product

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

the class MerchantProductListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main_activity_merchant, container, false);
    // Inflate the layout for this fragment
    ArrayList<Product> productArrayList = new ArrayList<>();
    menuListAdapter = new ProductListAdapter((Activity) container.getContext(), productArrayList);
    swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimaryDark, R.color.colorPrimaryLight);
    firebaseAuth = FirebaseAuth.getInstance();
    merchant = firebaseAuth.getCurrentUser();
    // Initialize References
    databaseUsers = FirebaseDatabase.getInstance().getReference("users");
    databaseProducts = FirebaseDatabase.getInstance().getReference("products");
    databaseStore = FirebaseDatabase.getInstance().getReference("store");
    // Initialize ListView
    productListView = view.findViewById(R.id.gridview);
    productListView.setAdapter(menuListAdapter);
    return view;
}
Also used : ProductListAdapter(com.example.asus.onlinecanteen.adapter.ProductListAdapter) ArrayList(java.util.ArrayList) Product(com.example.asus.onlinecanteen.model.Product) Activity(android.app.Activity) GridView(android.widget.GridView) View(android.view.View) ListView(android.widget.ListView)

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