protected void refreshUI() {
    if (isDetached()) {
      BLog.d(TAG, "fragment is detached!");
      return;
    }
    if (mData == null) {
      getProductDetail(true);
      return;
    }
    if (mAdapter == null) {
      mAdapter = new WallPapercreenShotAdapter(getFragmentManager(), mData);
      mPager.setAdapter(mAdapter);
    } else {
      mAdapter.notifyDataSetChanged();
    }
    BLog.d(TAG, "page count = " + mAdapter.getCount());
    refreshProductStatus(queryProductStatus(product_id));

    mPage.removeAllViews();
    for (int i = 0; i < mAdapter.getCount(); i++) {
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      ImageView dot = new ImageView(getActivity());
      if (i == 0) {
        dot.setBackgroundResource(R.drawable.indicator_focus);
      } else {
        dot.setBackgroundResource(R.drawable.indicator_normal);
      }
      mPage.addView(dot, params);
    }
  }
  private void purchase() {
    if (isLoading) {
      BLog.v(TAG, "is Loading ...");
      return;
    }

    if (!MarketUtils.hasSDcard()) {
      Toast.makeText(mActivity, R.string.msg_no_sdcard, Toast.LENGTH_SHORT).show();
      return;
    }

    if (!DataConnectionUtils.testValidConnection(mActivity)) {
      Toast.makeText(mActivity, R.string.dlg_msg_no_active_connectivity, Toast.LENGTH_SHORT).show();
      //            showLoadMessage(R.string.dlg_msg_no_active_connectivity);
      return;
    }
    if (!AccountSession.isLogin() && !mData.isFree) {
      BasicActivity bac = (BasicActivity) getActivity();
      bac.login();
      return;
    }
    synchronized (mLocked) {
      isLoading = true;
    }

    if (mData.isFree || mData.purchased) {
      onPayed(null);
    } else {
      doPaying();
    }
  }
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case LOAD_END:
          {
            end();
            if (getActivity() == null) return;
            boolean suc = msg.getData().getBoolean(RESULT);
            if (suc) {
              refreshUI();
            } else {
              showLoadMessage(R.string.msg_loadi_failed);
            }
            break;
          }
        case DELETE_END:
          {
            // end();
            dismissProgress();
            if (getActivity() == null) return;
            boolean suc = msg.getData().getBoolean(RESULT);
            if (suc) {
              if (!TextUtils.isEmpty(mData.localUrl)) {
                File f = new File(mData.localUrl);
                f.delete();
              }
              downLoadHelper.deleteFile(product_id, version_code);
              refreshProductStatus(PRODUCT_STATUS_DOWNLOAD);
            } else {

            }
            break;
          }
        case MSG_ON_CHANGE:
          {
            if ((PRODUCT_STATUS == PRODUCT_STATUS_DOWNLOADING) && downLoadID != -1) {
              int[] bytesAndStatus = DownloadUtils.getBytesAndStatus(mActivity, downLoadID);
              updateView(bytesAndStatus[0], bytesAndStatus[1], bytesAndStatus[2]);
            }
            break;
          }
        case PURCHASE_END:
          {
            if (getActivity() == null) return;
            boolean suc = msg.getData().getBoolean(RESULT);
            if (suc) {
              if (mActivity != null && BasicActivity.class.isInstance(mActivity)) {
                ((BasicActivity) mActivity).consumeAsync();
              }
              String url = msg.getData().getString(URL);
              if (TextUtils.isEmpty(url)) {
                BLog.e("url is null");
              } else {
                mData.purchased = true;
                DownloadUtils downloadUtils = new DownloadUtils(mActivity.getApplicationContext());
                downLoadID = downloadUtils.download(url, mData.name, mData.product_id);
                if (downLoadID != -1) {
                  int[] bytesAndStatus = DownloadUtils.getBytesAndStatus(mActivity, downLoadID);
                  updateView(bytesAndStatus[0], bytesAndStatus[1], bytesAndStatus[2]);
                  refreshProductStatus(PRODUCT_STATUS_DOWNLOADING);
                  //
                  downLoadHelper.insert(mData, null, downLoadID, jsonString);
                  mDownloadOrDeleteButton.setText(R.string.action_downloading);
                } else {
                  Toast.makeText(mActivity, R.string.download_failed, Toast.LENGTH_SHORT).show();
                }
              }
            } else {
              //                    Toast.makeText(mActivity, R.string.purchase_failed,
              //                            Toast.LENGTH_SHORT).show();

            }
            break;
          }
        case PAYING_FAILED:
          {
            if (getActivity() == null) return;
            String respone = msg.getData().getString(MESSAGE);
            Toast.makeText(mActivity, respone, Toast.LENGTH_LONG).show();
            refreshProductStatus(PRODUCT_STATUS_PURCHASE);
            break;
          }
      }
    }
  private void getProductDetail(boolean isVisbleLoadingUI) {
    if (isLoading) {
      BLog.v(TAG, "is Loading ...");
      return;
    }

    BLog.v(TAG, "begin getProductDetail");
    if (isVisbleLoadingUI) begin();
    if (!DataConnectionUtils.testValidConnection(mActivity)) {
      //            Toast.makeText(mActivity, R.string.dlg_msg_no_active_connectivity,
      //                    Toast.LENGTH_SHORT).show();
      mHandler.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              showLoadMessage(
                  R.string.dlg_msg_no_active_connectivity, R.drawable.biz_pic_empty_view, true);
            }
          },
          500);
      return;
    }
    synchronized (mLocked) {
      isLoading = true;
    }

    mApiUtil = ApiUtil.getInstance();
    mApiUtil.getProductDetail(
        mActivity,
        product_id,
        version_code,
        supported_mod,
        new RequestListener() {

          @Override
          public void onIOException(IOException e) {
            BLog.v(TAG, "getProductDetail onIOException  " + e.getMessage());
            synchronized (mLocked) {
              isLoading = false;
            }

            Message mds = mHandler.obtainMessage(LOAD_END);
            mds.getData().putBoolean(RESULT, false);
            mHandler.sendMessage(mds);
          }

          @Override
          public void onError(WutongException e) {
            BLog.d(TAG, "onError  " + e.getMessage());
            synchronized (mLocked) {
              isLoading = false;
            }

            Message mds = mHandler.obtainMessage(LOAD_END);
            mds.getData().putBoolean(RESULT, false);
            mHandler.sendMessage(mds);
          }

          @Override
          public void onComplete(String response) {
            JSONObject obj;
            try {
              obj = new JSONObject(response);
              if (!obj.has("data")) return;
              jsonString = obj.optJSONObject("data").toString();
              mData = new ProductJSONImpl(obj.optJSONObject("data"));

            } catch (JSONException e) {
              e.printStackTrace();
            }

            synchronized (mLocked) {
              isLoading = false;
            }

            Message mds = mHandler.obtainMessage(LOAD_END);
            mds.getData().putBoolean(RESULT, true);
            mHandler.sendMessage(mds);
          }
        });
  }
  private void editComment() {
    if (isLoading) {
      BLog.v(TAG, "is Loading ...");
      return;
    }

    if (!DataConnectionUtils.testValidConnection(mActivity)) {
      Toast.makeText(mActivity, R.string.dlg_msg_no_active_connectivity, Toast.LENGTH_SHORT).show();
      return;
    }

    if (sendDialog == null) {
      sendDialog = LightProgressDialog.create(getActivity(), R.string.label_comment_sending);
      sendDialog.setCanceledOnTouchOutside(false);
    }
    sendDialog.show();

    synchronized (mLocked) {
      isLoading = true;
    }

    if (mApiUtil == null) {
      mApiUtil = new ApiUtil();
    }
    mApiUtil.createComment(
        mActivity.getApplicationContext(),
        version,
        product_id,
        message,
        rating,
        new RequestListener() {

          @Override
          public void onIOException(IOException e) {
            BLog.e(TAG, "getCommentList onIOException  " + e.getMessage());
            synchronized (mLocked) {
              isLoading = false;
            }

            Message mds = mHandler.obtainMessage(SEND_END);
            mds.getData().putBoolean(RESULT, false);
            mHandler.sendMessage(mds);
          }

          @Override
          public void onError(WutongException e) {
            BLog.e(TAG, "onError  " + e.getMessage());
            synchronized (mLocked) {
              isLoading = false;
            }

            Message mds = mHandler.obtainMessage(SEND_END);
            mds.getData().putBoolean(RESULT, false);
            mHandler.sendMessage(mds);
          }

          @Override
          public void onComplete(String response) {
            JSONObject obj;
            try {
              obj = new JSONObject(response);
              if (!obj.has("data")) return;
              mData = new CommentJSONImpl(obj.optJSONObject("data"));
            } catch (JSONException e) {
              e.printStackTrace();
            }

            synchronized (mLocked) {
              isLoading = false;
            }

            Message mds = mHandler.obtainMessage(SEND_END);
            mds.getData().putBoolean(RESULT, true);
            mHandler.sendMessage(mds);
          }
        });
  }