示例#1
0
  /**
   * 获取推送消息
   *
   * @author wangshuaibo
   * @param mkey
   * @return
   */
  public static DataResult getMessage(String mkey) {
    DataResult result = new DataResult();
    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("mkey", mkey));
    String jsonString = null;
    try {
      jsonString = BabytreeHttp.get(MESSAGE_NET_URL, params);
      JSONObject jsonObject = new JSONObject(jsonString);
      if (jsonObject.has("succ")) {
        int status = jsonObject.getInt("succ");
        if (status == 0) {
          result.status = 0;
          if (jsonObject.has("data")) {
            ArrayList<PushMessage> data = new ArrayList<PushMessage>();
            JSONArray array = jsonObject.getJSONArray("data");
            int serial_number = 0;
            for (int i = 0; i < array.length(); i++) {
              PushMessage item = PushMessage.parse(array.getJSONObject(i));
              if (item.serial_number > serial_number) {
                serial_number = item.serial_number;
              }

              data.add(item);
            }
            result.totalSize = serial_number;
            result.data = data;
          } else if (jsonObject.has("list")) {
            ArrayList<PushMessage> data = new ArrayList<PushMessage>();

            JSONArray array = jsonObject.getJSONArray("list");
            int serial_number = 0;
            for (int i = 0; i < array.length(); i++) {
              PushMessage item = PushMessage.parse(array.getJSONObject(i));
              if (item.serial_number > serial_number) {
                serial_number = item.serial_number;
              }
              data.add(item);
            }
            result.totalSize = serial_number;
            result.data = data;
          }
        }
      }
    } catch (Exception e) {
      return ExceptionUtil.switchException(result, e, params, jsonString);
    }

    return result;
  }
示例#2
0
 @Override
 public void resultTopAvailable(int status, AbstractDataResult<Base> result) {
   if (status == REQUEST_SUCCESS) {
     MobclickAgent.onEvent(
         mActivity, EventContants.com, EventContants.communicate_topicListSuccess);
     mValues.clear();
     mCallback.clear();
     mValues.addAll(result.values);
     mCallback.refreshTop(result.values);
   } else if (status == REQUEST_FAILED) {
     MobclickAgent.onEvent(mActivity, EventContants.com, EventContants.communicate_topicListFail);
     // 错误处理
     mCallback.refreshTop(null);
     mTxtMessage.setText("");
     Toast.makeText(mActivity, result.message, Toast.LENGTH_SHORT).show();
     ExceptionUtil.catchException(result.error, mActivity);
   }
 }
示例#3
0
  @Override
  public void resultAvailable(int status, AbstractDataResult<Base> result) {
    if (status == REQUEST_SUCCESS) {
      MobclickAgent.onEvent(
          mActivity, EventContants.com, EventContants.communicate_topicListSuccess);
      mLoading = false;
      if (mMaxItems == 0) mMaxItems = result.maxItems;
      if (result.values.size() == 0) {
        mMaxItems = mValues.size();
        mCallback.showLoading(false);
        return;
      }
      // 去除重复内容
      mValues = com.babytree.apps.comm.util.BabytreeUtil.removeDuplicate(mValues, result.values);
      mCallback.dataLoadedDuplicate(result.values);
    } else if (status == REQUEST_FIRST_SUCCESS) {
      MobclickAgent.onEvent(
          mActivity, EventContants.com, EventContants.communicate_topicListSuccess);
      if (mMaxItems < 1) {
        mActivity.findViewById(R.id.load).setVisibility(View.GONE);
        mActivity.findViewById(R.id.list).setVisibility(View.GONE);
        mActivity.findViewById(R.id.layout_empty).setVisibility(View.VISIBLE);
        mActivity.findViewById(R.id.reload).setVisibility(View.GONE);
      } else {
        mActivity.findViewById(R.id.load).setVisibility(View.GONE);
        mActivity.findViewById(R.id.list).setVisibility(View.VISIBLE);
        mActivity.findViewById(R.id.layout_empty).setVisibility(View.GONE);
        mActivity.findViewById(R.id.reload).setVisibility(View.GONE);
        mLoading = false;
        if (mMaxItems == 0) mMaxItems = result.maxItems;
        if (result.values.size() == 0) {
          mMaxItems = mValues.size();
          mCallback.showLoading(false);
          return;
        }
        mValues.addAll(result.values);
        mCallback.dataLoaded(result.values);
        // mCallback.refreshTop(null);//一定要加,不然刷新后头上有个点击刷新
      }
    } else if (status == REQUEST_FIRST_FAILED) {
      MobclickAgent.onEvent(mActivity, EventContants.com, EventContants.communicate_topicListFail);

      mCallback.refreshTop(null);
      mTxtMessage.setText("");
      // 错误处理
      Toast.makeText(mActivity, result.message, Toast.LENGTH_SHORT).show();
      ExceptionUtil.catchException(result.error, mActivity);
      mActivity.findViewById(R.id.load).setVisibility(View.GONE);
      final View reloadView = mActivity.findViewById(R.id.reload);
      reloadView.setVisibility(View.VISIBLE);
      Button btnReload = (Button) reloadView.findViewById(R.id.btn_reload);
      btnReload.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              mActivity.findViewById(R.id.load).setVisibility(View.VISIBLE);
              reloadView.setVisibility(View.GONE);
              new FirstBackgroundTask(ForumHandler.this).execute();
            }
          });
    } else if (status == REQUEST_FAILED) {
      MobclickAgent.onEvent(mActivity, EventContants.com, EventContants.communicate_topicListFail);
      // 错误处理
      Toast.makeText(mActivity, result.message, Toast.LENGTH_SHORT).show();
      ExceptionUtil.catchException(result.error, mActivity);
      mCallback.showLoading(false);
      mCallback.showReloading(true);
      View reloadingView = mCallback.getReloadingView();
      Button btnReload = (Button) reloadingView.findViewById(R.id.btn_reload);
      btnReload.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              mCallback.showLoading(true);
              mCallback.showReloading(false);
              new BackgroundTask(ForumHandler.this).execute(mValues.size());
            }
          });
    }
  }
示例#4
0
  @Override
  public void resultAvailable(int status, AbstractDataResult<Base> result) {
    if (status == REQUEST_SUCCESS) {
      MobclickAgent.onEvent(
          mActivity, EventContants.com, EventContants.communicate_topicListSuccess);
      mLoading = false;
      if (mMaxItems == 0) mMaxItems = result.maxItems;
      if (result.values.size() == 0) {
        mMaxItems = mValues.size();
        mCallback.showLoading(false);
        return;
      }
      mValues.addAll(result.values);
      mCallback.dataLoaded(result.values);
    } else if (status == REQUEST_FIRST_SUCCESS) {
      MobclickAgent.onEvent(
          mActivity, EventContants.com, EventContants.communicate_topicListSuccess);
      mTxtMessage.setText(mName + "(" + mMaxItems + "贴)");
      if (mMaxItems < 1) {
        mActivity.findViewById(R.id.load).setVisibility(View.GONE);
        mActivity.findViewById(R.id.list).setVisibility(View.GONE);
        mActivity.findViewById(R.id.layout_empty).setVisibility(View.VISIBLE);
        mActivity.findViewById(R.id.reload).setVisibility(View.GONE);
      } else {
        mActivity.findViewById(R.id.load).setVisibility(View.GONE);
        mActivity.findViewById(R.id.list).setVisibility(View.VISIBLE);
        mActivity.findViewById(R.id.layout_empty).setVisibility(View.GONE);
        mActivity.findViewById(R.id.reload).setVisibility(View.GONE);
        mLoading = false;
        if (mMaxItems == 0) mMaxItems = result.maxItems;
        if (result.values.size() == 0) {
          mMaxItems = mValues.size();
          mCallback.showLoading(false);
          return;
        }
        mValues.addAll(result.values);
        mCallback.dataLoaded(result.values);
      }
    } else if (status == REQUEST_FIRST_FAILED) {
      MobclickAgent.onEvent(mActivity, EventContants.com, EventContants.communicate_topicListFail);
      // 错误处理
      Toast.makeText(mActivity, result.message, Toast.LENGTH_SHORT).show();
      ExceptionUtil.catchException(result.error, mActivity);
      mActivity.findViewById(R.id.load).setVisibility(View.GONE);

      final View reloadView = mActivity.findViewById(R.id.reload);
      reloadView.setVisibility(View.VISIBLE);
      Button btnReload = (Button) reloadView.findViewById(R.id.btn_reload);
      btnReload.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              mActivity.findViewById(R.id.load).setVisibility(View.VISIBLE);
              reloadView.setVisibility(View.GONE);
              new FirstBackgroundTask(DoctorTopicListHandler.this).execute();
            }
          });
    } else if (status == REQUEST_FAILED) {
      MobclickAgent.onEvent(mActivity, EventContants.com, EventContants.communicate_topicListFail);
      // 错误处理
      Toast.makeText(mActivity, result.message, Toast.LENGTH_SHORT).show();
      ExceptionUtil.catchException(result.error, mActivity);
      mCallback.showLoading(false);
      mCallback.showReloading(true);
      View reloadingView = mCallback.getReloadingView();
      // if(!mActivity.isFinishing()){
      // showReloadDialogForBack();
      // }

      Button btnReload = (Button) reloadingView.findViewById(R.id.btn_reload);
      btnReload.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              mCallback.showLoading(true);
              mCallback.showReloading(false);
              new BackgroundTask(DoctorTopicListHandler.this).execute(mValues.size());
            }
          });
    }
  }