Example #1
0
 @Override
 public void onErrorResponse(VolleyError error) {
   Logger.e(error);
   Toast.makeText(mCtx, VolleyHelper.getErrorReason(error), Toast.LENGTH_LONG).show();
   synchronized (mLocker) {
     mRsp = null;
     mLocker.notify();
   }
 }
Example #2
0
  private void fetchForumList() {
    Message msg = Message.obtain();
    msg.what = ThreadListFragment.STAGE_GET_WEBPAGE;
    mHandler.sendMessage(msg);

    mUrl = HiUtils.ThreadListUrl + mForumId + "&page=" + mPage;
    if (HiSettingsHelper.getInstance().isSortByPostTime(mForumId)) {
      mUrl += "&orderby=dateline";
    }
    StringRequest sReq =
        new HiStringRequest(mUrl, new ThreadListListener(), new ThreadListErrorListener());
    VolleyHelper.getInstance().add(sReq);
  }
Example #3
0
    @Override
    public void onErrorResponse(VolleyError error) {
      Logger.e(error);

      Message msg = Message.obtain();
      msg.what = ThreadListFragment.STAGE_ERROR;
      Bundle b = new Bundle();
      String text = "无法访问HiPDA, " + VolleyHelper.getErrorReason(error);
      b.putString(ThreadListFragment.STAGE_ERROR_KEY, text);
      msg.setData(b);
      mHandler.sendMessage(msg);

      if (HiSettingsHelper.getInstance().isErrorReportMode())
        ACRAUtils.acraReport(error, "url=" + mUrl);

      synchronized (mLocker) {
        mRsp = null;
        mLocker.notify();
      }
    }
Example #4
0
  private void doPost(String url, String replyText, String subject, String typeid) {

    String formhash = mInfo != null ? mInfo.getFormhash() : null;

    if (TextUtils.isEmpty(formhash)) {
      mResult = "发表失败,无法获取必要信息 !";
      mStatus = Constants.STATUS_FAIL;
      return;
    }

    Map<String, String> post_param = new HashMap<>();
    post_param.put("formhash", formhash);
    post_param.put("posttime", String.valueOf(System.currentTimeMillis()));
    post_param.put("wysiwyg", "0");
    post_param.put("checkbox", "0");
    post_param.put("message", replyText);
    for (String attach : mInfo.getAttaches()) {
      post_param.put("attachnew[" + attach + "][description]", attach);
    }
    for (String attach : mInfo.getAttachdel()) {
      post_param.put("attachdel[" + attach + "]", attach);
    }
    for (String attach : mInfo.getUnusedImages()) {
      post_param.put("attachdel[" + attach + "]", attach);
    }
    if (mMode == MODE_NEW_THREAD) {
      post_param.put("subject", subject);
      post_param.put("attention_add", "1");
      mTitle = subject;
    } else if (mMode == MODE_EDIT_POST) {
      if (!TextUtils.isEmpty(subject)) {
        post_param.put("subject", subject);
        mTitle = subject;
        if (!TextUtils.isEmpty(typeid)) {
          post_param.put("typeid", typeid);
        }
      }
    }

    SimpleErrorListener errorListener = VolleyHelper.getInstance().getErrorListener();
    String rsp_str = VolleyHelper.getInstance().synchronousPost(url, post_param, errorListener);

    // when success, volley will follow 302 redirect get the page content
    if (!TextUtils.isEmpty(rsp_str)) {
      String tid = "";
      if (rsp_str.contains("tid = parseInt('")) {
        tid = HttpUtils.getMiddleString(rsp_str, "tid = parseInt('", "'");
      }
      if (!TextUtils.isEmpty(tid)
          && TextUtils.isDigitsOnly(tid)
          && Integer.parseInt(tid) > 0
          && !rsp_str.contains("alert_info")) {
        mTid = tid;
        mResult = "发表成功!";
        mStatus = Constants.STATUS_SUCCESS;
      } else {
        Logger.e(rsp_str);
        mResult = "发表失败! ";
        mStatus = Constants.STATUS_FAIL;

        Document doc = Jsoup.parse(rsp_str);
        Elements error = doc.select("div.alert_info");
        if (error != null && error.size() > 0) {
          mResult += error.text();
        } else {
          if (HiSettingsHelper.getInstance().isErrorReportMode())
            ACRAUtils.acraReport("Error when posting but with response", rsp_str);
        }
      }
    } else {
      Logger.e(errorListener.getError());

      mResult = "发表失败,无返回结果! " + errorListener.getErrorText();
      mStatus = Constants.STATUS_FAIL;

      if (HiSettingsHelper.getInstance().isErrorReportMode())
        ACRAUtils.acraReport(errorListener.getError(), "no response");
    }
  }
Example #5
0
  private void fetchSimpleList(int type) {
    String url = null;
    switch (type) {
      case TYPE_MYREPLY:
        url = HiUtils.MyReplyUrl + "&page=" + mPage;
        break;
      case TYPE_MYPOST:
        url = HiUtils.MyPostUrl + "&page=" + mPage;
        break;
      case TYPE_SMS:
        url = HiUtils.SMSUrl;
        break;
      case TYPE_THREADNOTIFY:
        url = HiUtils.ThreadNotifyUrl;
        break;
      case TYPE_SMSDETAIL:
        url = HiUtils.SMSDetailUrl + mExtra;
        break;
      case TYPE_SEARCH:
        try {
          String prefixsft = mCtx.getResources().getString(R.string.prefix_search_fulltext);
          if (mExtra.startsWith(prefixsft)) {
            url =
                HiUtils.SearchFullText
                    + URLEncoder.encode(mExtra.substring(prefixsft.length()), "GBK");
            if (mPage > 1) url += "&page=" + mPage;
          } else {
            url = HiUtils.SearchTitle + URLEncoder.encode(mExtra, "GBK");
            if (mPage > 1) url += "&page=" + mPage;
          }
        } catch (UnsupportedEncodingException e) {
          Logger.e("Encoding error", e);
        }
        break;
      case TYPE_SEARCH_USER_THREADS:
        if (TextUtils.isDigitsOnly(mExtra)) {
          // first search, use uid
          url = HiUtils.SearchUserThreads + mExtra + "&page=" + mPage;
        } else {
          // after first seach, searchId is generated
          url = HiUtils.BaseUrl + mExtra;
          // replace page number in url
          int pageIndex = url.indexOf("page=");
          int pageEndIndex = url.indexOf("&", pageIndex + "page=".length());
          if (pageIndex > 0 && pageEndIndex > pageIndex) {
            url = url.substring(0, pageIndex) + "page=" + mPage + url.substring(pageEndIndex);
          } else if (pageEndIndex == -1) {
            url = url.substring(0, pageIndex) + "page=" + mPage;
          }
        }
        break;
      case TYPE_FAVORITES:
        url = HiUtils.FavoritesUrl;
        if (mPage > 1) url += "&page=" + mPage;
        break;
      default:
        break;
    }

    StringRequest sReq =
        new HiStringRequest(url, new ThreadListListener(), new ThreadListErrorListener());
    VolleyHelper.getInstance().add(sReq);
  }