public ProductDetailViewController(Product product) { this.currentProduct = product; this.order = new Order(product); setTitle(currentProduct.getName()); loadProductData(); getTableView().setTableFooterView(new UIView(new CGRect(0, 0, 0, BottomButtonView.HEIGHT))); tshirtIcon = UIImage.getImage("t-shirt"); bottomView = new BottomButtonView(); bottomView.setButtonText("Add to Basket"); bottomView.setButtonTapListener((b, e) -> addToBasket()); getView().addSubview(bottomView); }
@Override public void viewDidLayoutSubviews() { super.viewDidLayoutSubviews(); CGRect bounds = getView().getBounds(); bounds.setY(bounds.getY() + bounds.getHeight() - BottomButtonView.HEIGHT); bounds.setHeight(BottomButtonView.HEIGHT); bottomView.setFrame(bounds); }
private void addToBasket() { UINavigationController navigation = getNavigationController(); CGPoint center = bottomView .getButton() .convertPointToView( bottomView.getButton().getImageView().getCenter(), navigation.getView()); UIImageView imageView = new UIImageView(tshirtIcon); imageView.setCenter(center); imageView.setContentMode(UIViewContentMode.ScaleAspectFill); UIImageView backgroundView = new UIImageView(UIImage.getImage("circle")); backgroundView.setCenter(center); navigation.getView().addSubviews(backgroundView, imageView); UIView targetView = (UIView) getNavigationItem().getRightBarButtonItem().getKeyValueCoder().getValue("view"); CGPoint targetPosition = new CGPoint( targetView.getCenter().getX() + targetView.getFrame().getWidth() / 3, targetView.getCenter().getY() + targetView.getFrame().getHeight() / 2); animateView(imageView, targetPosition, null); animateView( backgroundView, targetPosition, () -> { getNavigationItem().setRightBarButtonItem(StoreApp.getInstance().createBasketButton()); }); if (addedToBasket != null) { addedToBasket.invoke(new Order(order)); } }