Ejemplo n.º 1
0
  private void postCallendar(Table table) {

    String time = table.getData("time");
    // 2013-11-09
    StringTokenizer stringTokenizer = new StringTokenizer(time, "-");
    int year = Integer.parseInt(stringTokenizer.nextToken());
    int month = Integer.parseInt(stringTokenizer.nextToken());
    int day = Integer.parseInt(stringTokenizer.nextToken());
    Calendar cal = Calendar.getInstance();
    cal.set(year, month - 1, day, 0, 0, 0);
    // cal.getTimeInMillis();
    long getTime = cal.getTimeInMillis();
    long beginTime = getTime;
    long endTime = getTime;

    if (getTime > System.currentTimeMillis()) {
      addCalendar(beginTime, endTime, table.getData("title"), table.getData("message"));
    } else {
      CommonAndroid.showDialog(getActivity(), getString(R.string.error_event_calendar), null);
    }
  }
  @Override
  public void onClick(View v) {
    String name = getTextStr(R.id.registerfacebooktwitter_edt1);
    final String email = getTextStr(R.id.registerfacebooktwitter_edt2);
    final String password = getTextStr(R.id.registerfacebooktwitter_edt3);
    String repassword = getTextStr(R.id.registerfacebooktwitter_edt3);

    String message = null;

    if (ByUtils.isBlank(name)) {
      message = getContext().getResources().getString(R.string.error_message_input_name);
    }

    if (ByUtils.isBlank(email)) {
      message = getContext().getResources().getString(R.string.error_message_input_email);
    }

    if (ByUtils.isBlank(password)) {
      message = getContext().getResources().getString(R.string.error_message_input_password);
    }

    if (!password.equals(repassword)) {
      message =
          getContext().getResources().getString(R.string.error_message_check_passwordandrepassword);
    }

    if (message != null) {
      CommonAndroid.showDialog(getContext(), message, null);
      return;
    }

    Map<String, String> sendData = new HashMap<String, String>();
    if (user != null) {
      sendData.put("type", "2");
      sendData.put("id", user.getId());
    } else {
      sendData.put("type", "1");
      sendData.put("id", id);
    }

    sendData.put("user", name);
    sendData.put("email", email);
    sendData.put("name", name);
    sendData.put("password", password);
    sendData.put("repassword", repassword);

    APICaller apiCaller = new APICaller(getContext());
    ICallbackAPI callbackAPI =
        new ICallbackAPI() {

          @Override
          public void onSuccess(String response) {
            try {
              JSONObject jsonObject = new JSONObject(response);
              if (jsonObject.getString("status").equals("1")) {
                AccountDB accountDB = new AccountDB(getContext());
                accountDB.save("email", email);
                accountDB.save("password", password);
                accountDB.save(response);
                GcmBroadcastReceiver.register(getContext());
                clickListener.onClick(null, 0);
                dismiss();
              } else {
                CommonAndroid.showDialog(getContext(), jsonObject.getString("message"), null);
              }
            } catch (Exception e) {
              CommonAndroid.showDialog(
                  getContext(),
                  getContext().getResources().getString(R.string.error_message_register_fail),
                  null);
            }
          }

          @Override
          public void onError(String message) {
            CommonAndroid.showDialog(
                getContext(),
                getContext().getResources().getString(R.string.error_message_register_fail),
                null);
          }
        };
    apiCaller.callApi("/user/register", true, callbackAPI, sendData);
  }