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);
}
}
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) {
}
});
}
}
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);
}
}
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);
}
}
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;
}
Aggregations