private void initVars() {
    mDialog = new ProgressDialog(this);

    mProductAddNew =
        new Product() {
          {
            set_id(ProductAdapter.ACTION_ID_ADD);
            setName(getString(R.string.action_add_product));
          }
        };

    // --- Product ---
    spinner_Product_init();

    // khởi tạo giá trị qua Intent
    mAssignId = getIntent().getLongExtra(EXTRA_ASSIGN_ID, -1);

    long mPSId = getIntent().getLongExtra(EXTRA_PRODUCT_SHOWN_ID, -1);
    if (mPSId == -1) {
      isAddNew = true;
    } else {
      // Hiển thị Cập nhật
      updateUIAddOrEdit(false);
      isAddNew = false;

      mProductShown = ProductShownData.getById(this, mPSId);
      spinner_Product_setSelection(mProductShown.getProductId());
      mInputLayout_Number.getEditText().setText(mProductShown.getNumber() + "");
      mInputLayout_RetailPrice.getEditText().setText(mProductShown.getRetailPrice() + "");
    }
  }
  /**
   * Post và Update lại Product Shown Image
   *
   * @param listProductShownImg
   * @return
   */
  public static BatchActionResult postAndUpdate(
      Context context, ArrayList<ProductShownImg> listProductShownImg) {
    BatchActionResult batchResult = new BatchActionResult(0, 0); // tính thành công, thất bại

    for (ProductShownImg psi : listProductShownImg) {

      boolean isSuccess = false; // đánh dấu đã thành công, không thêm thất bại

      // kiểm tra Product Shown vs Image đã Upload
      ProductShown productShown = psi.getProductShow(context);
      Image image = psi.getImage(context);
      if (productShown.getUploadStatus() == UploadStatus.UPLOADED
          && image.getUploadStatus() == UploadStatus.UPLOADED) {

        PostProductShownImgWSResult ppsiResult =
            ProductShownImgWS.post(psi, productShown.getServerId(), image.getServerId());
        if (ppsiResult.getStatus() == BaseWSResult.STATUS_SUCCESS
            || ppsiResult.getStatus() == BaseWSResult.STATUS_DUPLICATE) {

          ProductShownImgData.update_UploadStatus_ServerId_byId(
              context, psi.get_id(), UploadStatus.UPLOADED, ppsiResult.getProductShown_ImageID());

          isSuccess = true;
        }
      }

      if (isSuccess) batchResult.addSuccess(1);
      else batchResult.addFail(1);
    }
    return batchResult;
  }
  private long addProductShown() {
    // lấy giá trị
    Product product = (Product) mSpinner_Product.getSelectedItem();
    long productId = product.get_id();
    int number = Integer.valueOf(mInputLayout_Number.getEditText().getText() + "");
    long retailPrice = Long.valueOf(mInputLayout_RetailPrice.getEditText().getText() + "");

    // gán giá trị
    mProductShown = new ProductShown();

    mProductShown.setAssignId(mAssignId);
    mProductShown.setProductId(productId);
    mProductShown.setNumber(number);
    mProductShown.setRetailPrice(retailPrice);

    mProductShown.setSessionCode(DatabaseUtil.getCodeGenerationByTime());
    mProductShown.setCreateBy(UserPref.getUserPrefId(this));
    mProductShown.setCreateAt(Calendar.getInstance());
    mProductShown.setUploadStatus(UploadStatus.WAITING_UPLOAD);

    long id = ProductShownData.add(this, mProductShown);
    mProductShown.set_id(id);

    return id;
  }
  private long savePSImage() {

    String latitude = new LocationService(this).getLatitude() + "";
    String longitude = new LocationService(this).getLongitude() + "";

    // -----save image------
    Image image = new Image();

    String filePath = mUriImage.getPath();
    image.setFileName(FileUtil.getFileName(filePath));
    image.setFilePath(filePath);
    image.setLatitude(latitude);
    image.setLongitude(longitude);

    image.setSessionCode(DatabaseUtil.getCodeGenerationByTime());
    image.setCreateBy(UserPref.getUserPrefId(this));
    image.setCreateAt(Calendar.getInstance());
    image.setUploadStatus(UploadStatus.WAITING_UPLOAD);

    // -----save Attendance image------
    ProductShownImg psi = new ProductShownImg();

    psi.setProductShownId(mProductShown.get_id());

    psi.setSessionCode(DatabaseUtil.getCodeGenerationByTime());
    psi.setCreateBy(UserPref.getUserPrefId(this));
    psi.setCreateAt(Calendar.getInstance());
    psi.setUploadStatus(UploadStatus.WAITING_UPLOAD);

    return ProductShownImgData.add(this, image, psi);
  }
  // region Sự kiện
  private void saveProductShownHandle() {
    AppAlertDialog.showWaitingDialog(this, mDialog);

    if (validateViews()) {
      if (isAddNew) {
        // save add new

        long productId = addProductShown();

        if (productId > -1) {
          // Thành công
          Toast.makeText(this, getString(R.string.message_success), Toast.LENGTH_LONG).show();
          AssignData.changeStatus(this, mAssignId, Assign.WorkStatus.DOING);
          finishWithResultOK(productId);

        } else {
          // Thất bại
          Toast.makeText(this, getString(R.string.message_error_unknown), Toast.LENGTH_LONG).show();
        }
      } else {
        // save Update

        long row = updateProductShown();

        if (row > 0) {
          // Thành công
          Toast.makeText(this, getString(R.string.message_success), Toast.LENGTH_LONG).show();
          finishWithResultOK(mProductShown.get_id());

        } else {
          // Thất bại
          Toast.makeText(this, getString(R.string.message_error_unknown), Toast.LENGTH_LONG).show();
        }
      }
    }

    mDialog.cancel();
  }