Example #1
0
  private void executeSendMagpieTask(
      int publisherID, String title, String content, List<String> imageUrls) {
    StringBuilder stringBuilder = new StringBuilder(content);
    if (imageUrls != null) {
      for (String url : imageUrls) {
        stringBuilder.append("@|").append(url);
      }
    }
    progressDialog.show(R.string.txt_sending);
    new SendMagpieJSONTask(
            publisherID,
            title,
            stringBuilder.toString(),
            new JSONReceiver() {
              @Override
              public void onFailure(JSONObject obj) {
                progressDialog.dismiss();
                Toast.makeText(NewMagpieActivity.this, R.string.error_network, Toast.LENGTH_SHORT)
                    .show();
              }

              @Override
              public void onSuccess(JSONObject obj) {
                progressDialog.dismiss();
                Toast.makeText(
                        NewMagpieActivity.this, R.string.txt_send_successfully, Toast.LENGTH_SHORT)
                    .show();
                NewMagpieActivity.this.finish();
              }
            })
        .execute();
  }
Example #2
0
  private void sendMagpie() {
    final int publisherID = 0; // TODO get publisher ID
    final String title = etTitle.getText().toString();
    final String basic = etBasic.getText().toString();
    final String hobby = etHobby.getText().toString();
    final String condition = etCondition.getText().toString();
    final String content = "基本情况\n" + basic + "\n兴趣爱好\n" + hobby + "\n心动条件\n" + condition;
    if (title.equals("") || basic.equals("") || hobby.equals("") || condition.equals("")) {
      Toast.makeText(NewMagpieActivity.this, R.string.error_empty_content, Toast.LENGTH_SHORT)
          .show();
      return;
    }

    // upload image
    if (localImageUrls != null && localImageUrls.length != 0) {
      List<String> urls = Arrays.asList(localImageUrls);
      final ImageUploader imageUploader = ImageUploader.getInstance();
      imageUploader.setOnUploadFinishListener(
          new ImageUploader.OnUploadFinishListener() {
            @Override
            public void onFailure() {
              progressDialog.dismiss();
              Toast.makeText(NewMagpieActivity.this, R.string.error_network, Toast.LENGTH_SHORT)
                  .show();
            }

            @Override
            public void onSuccess(List<String> receivedUrls) {
              executeSendMagpieTask(publisherID, title, content, receivedUrls);
            }
          });
      progressDialog.show(R.string.txt_uploading);
      imageUploader.execute(urls);
    } else {
      executeSendMagpieTask(publisherID, title, content, null);
    }
  }