@Override
  public void viewDidLoad() {
    super.viewDidLoad();

    getTableView().setSeparatorStyle(UITableViewCellSeparatorStyle.None);
    getTableView().setBackgroundColor(UIColor.black());

    getNavigationItem().setTitleView(new UIImageView(UIImage.getImage("TitleFindFriends")));

    if (getNavigationController().getViewControllers().first() == this) {
      UIBarButtonItem dismissLeftBarButtonItem =
          new UIBarButtonItem(
              "Back",
              UIBarButtonItemStyle.Plain,
              new UIBarButtonItem.OnClickListener() {
                @Override
                public void onClick(UIBarButtonItem barButtonItem) {
                  getNavigationController().dismissViewController(true, null);
                }
              });
      getNavigationItem().setLeftBarButtonItem(dismissLeftBarButtonItem);
    } else {
      getNavigationItem().setLeftBarButtonItem(null);
    }

    if (MFMailComposeViewController.canSendMail() || MFMessageComposeViewController.canSendText()) {
      headerView = new UIView(new CGRect(0, 0, 320, 67));
      headerView.setBackgroundColor(UIColor.black());
      UIButton clearButton = new UIButton(UIButtonType.Custom);
      clearButton.setBackgroundColor(UIColor.clear());
      clearButton.addOnTouchUpInsideListener(inviteFriendsButtonAction);
      clearButton.setFrame(headerView.getFrame());
      headerView.addSubview(clearButton);
      String inviteString = "Invite friends";
      CGRect boundingRect =
          NSString.getBoundingRect(
              inviteString,
              new CGSize(310, Float.MAX_VALUE),
              NSStringDrawingOptions.with(
                  NSStringDrawingOptions.TruncatesLastVisibleLine,
                  NSStringDrawingOptions.UsesLineFragmentOrigin),
              new NSAttributedStringAttributes().setFont(UIFont.getBoldSystemFont(18)),
              null);
      CGSize inviteStringSize = boundingRect.getSize();

      UILabel inviteLabel =
          new UILabel(
              new CGRect(
                  10,
                  (headerView.getFrame().getSize().getHeight() - inviteStringSize.getHeight()) / 2,
                  inviteStringSize.getWidth(),
                  inviteStringSize.getHeight()));
      inviteLabel.setText(inviteString);
      inviteLabel.setFont(UIFont.getBoldSystemFont(18));
      inviteLabel.setTextColor(UIColor.white());
      inviteLabel.setBackgroundColor(UIColor.clear());
      headerView.addSubview(inviteLabel);
      getTableView().setTableHeaderView(headerView);
    }
  }
 private void configureVideoPreviewLayer() {
   AVCaptureVideoPreviewLayer previewLayer = new AVCaptureVideoPreviewLayer(captureSession);
   previewLayer.setVideoGravity(AVLayerVideoGravity.ResizeAspectFill);
   CALayer rootLayer = getView().getLayer();
   rootLayer.setMasksToBounds(true);
   CGRect frame = previewView.getFrame();
   previewLayer.setFrame(frame);
   rootLayer.insertSublayerAt(previewLayer, 0);
 }
  private void animateView(UIView view, CGPoint targetPosition, Runnable completion) {
    CGSize size = view.getFrame().getSize();
    CGSize grow = new CGSize(size.getWidth() * 1.7, size.getHeight() * 1.7);
    CGSize shrink = new CGSize(size.getWidth() * .4, size.getHeight() * .4);

    CAKeyframeAnimation pathAnimation = new CAKeyframeAnimation("position");
    pathAnimation.setCalculationMode(CAAnimationCalculationMode.Paced);
    pathAnimation.setFillMode(CAFillMode.Forwards);
    pathAnimation.setRemovedOnCompletion(false);
    pathAnimation.setDuration(.5);

    UIBezierPath path = new UIBezierPath();
    path.move(view.getCenter());
    path.addQuadCurve(
        targetPosition, new CGPoint(view.getCenter().getX(), view.getCenter().getY()));
    pathAnimation.setPath(path.getCGPath());

    CABasicAnimation growAnimation = new CABasicAnimation("bounds.size");
    growAnimation.setToValue(NSValue.valueOf(grow));
    growAnimation.setFillMode(CAFillMode.Forwards);
    growAnimation.setRemovedOnCompletion(false);
    growAnimation.setDuration(.1);

    CABasicAnimation shrinkAnimation = new CABasicAnimation("bounds.size");
    shrinkAnimation.setToValue(NSValue.valueOf(shrink));
    shrinkAnimation.setFillMode(CAFillMode.Forwards);
    shrinkAnimation.setRemovedOnCompletion(false);
    shrinkAnimation.setDuration(.4);
    shrinkAnimation.setBeginTime(.1);

    CAAnimationGroup animations = new CAAnimationGroup();
    animations.setAnimations(new NSArray<>(pathAnimation, growAnimation, shrinkAnimation));
    animations.setFillMode(CAFillMode.Forwards);
    animations.setRemovedOnCompletion(false);
    animations.setDuration(.5);
    animations.setDelegate(
        new CAAnimationDelegateAdapter() {
          @Override
          public void didStop(CAAnimation anim, boolean flag) {
            view.removeFromSuperview();

            if (completion != null) {
              completion.run();
            }
          }
        });
    view.getLayer().addAnimation(animations, "movetocart");
  }
  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));
    }
  }