Ejemplo n.º 1
0
 /**
  * Button click event handler. Whether New event is created or event is edited it starts proper
  * method.
  *
  * @param view
  */
 public void SaveEventClick(View view) {
   if (!ValidateForm()) // there were errors
   {
     ModalService.ShowErrorModal("Unknown error occured!", AddEventActivity.this);
     return;
   }
   if (loadedEvent != null) // editing event
   {
     EditEvent();
   } else // creating new one
   {
     CreateEvent();
   }
 }
Ejemplo n.º 2
0
  /**
   * Validate input. Only description can be empty. Start date can not be after end date. Method
   * shows proper error message.
   *
   * @return true if input is proper, false otherwise
   */
  public boolean ValidateForm() {
    String errorMsg = "";
    StringValidator validator = new StringValidator();
    errorMsg += validator.isEmpty("Title", tbTitle.getText().toString());
    errorMsg += validator.isEmpty("Place", tbPlace.getText().toString());
    errorMsg += validator.isEmpty("Start date", tbStartDate.getText().toString());
    errorMsg += validator.isEmpty("End date", tbEndDate.getText().toString());
    errorMsg += validator.isEmpty("Start time", tbStartTime.getText().toString());
    errorMsg += validator.isEmpty("End time", tbEndTime.getText().toString());

    LocalDateTime startFinalDate = startDate.toLocalDateTime(startTime);
    LocalDateTime endFinalDate = endDate.toLocalDateTime(endTime);

    if (startFinalDate.isAfter(endFinalDate))
      errorMsg += "End date can not be before start date!\n";

    if (errorMsg.length() == 0) return true;
    else {
      ModalService.ShowErrorModal(errorMsg, AddEventActivity.this);
      return false;
    }
  }
Ejemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_event);

    InternetConnectionService service = new InternetConnectionService(AddEventActivity.this);
    if (!service.isInternetConnection()) {
      ModalService.ShowNoConnetionError(AddEventActivity.this);
      return;
    }

    tbStartDate = (TextView) findViewById(R.id.tbStartDate);
    tbEndDate = (TextView) findViewById(R.id.tbEndDate);
    tbStartTime = (TextView) findViewById(R.id.tbStartTime);
    tbEndTime = (TextView) findViewById(R.id.tbEndTime);
    btnAddFriends = (TextView) findViewById(R.id.btnFriends);
    btnSaveEvent = (TextView) findViewById(R.id.btnSave);
    tbTitle = (TextView) findViewById(R.id.tbEventTitle);
    tbPlace = (TextView) findViewById(R.id.tbPlace);
    tbDesc = (TextView) findViewById(R.id.tbDesc);

    addedUsers = new ArrayList<>();
    endDate = new LocalDate();
    startDate = new LocalDate();
    startTime = new LocalTime();
    endTime = new LocalTime();

    String eventId = getIntent().getStringExtra("eventId");
    if (eventId != null) {
      final ProgressDialog dlg = new ProgressDialog(AddEventActivity.this);
      dlg.setTitle("Please wait.");
      dlg.setMessage("Searching event.  Please wait.");
      dlg.show();

      ParseQuery<ParseEvent> query = ParseQuery.getQuery("Event");
      query.getInBackground(
          eventId,
          new GetCallback<ParseEvent>() {
            @Override
            public void done(ParseEvent object, ParseException e) {
              if (e == null) {
                loadedEvent = object;

                tbTitle.setText(loadedEvent.getTitle());
                tbPlace.setText(loadedEvent.getPlace());
                tbDesc.setText(loadedEvent.getDescription());

                endDate = loadedEvent.getEndDate().toLocalDate();
                startDate = loadedEvent.getStartDate().toLocalDate();
                startTime = loadedEvent.getEndDate().toLocalTime();
                endTime = loadedEvent.getEndDate().toLocalTime();

                btnSaveEvent.setText("SAVE EVENT");

                try {
                  addedUsers = loadedEvent.getUsers();
                } catch (ParseException e1) {
                  ModalService.ShowErrorModal(
                      "Error occured while proceding users!", AddEventActivity.this);
                  finish();
                }
                dlg.dismiss();
              } else {
                dlg.dismiss();
                ModalService.ShowErrorModal("There is no such event!", AddEventActivity.this);
                finish();
              }
            }
          });
    }

    tbStartDate.setText(startDate.toString("dd/MM/yyyy"));
    tbEndDate.setText(endDate.toString("dd/MM/yyyy"));
    tbStartTime.setText(startTime.toString("HH:mm"));
    tbEndTime.setText(endTime.toString("HH:mm"));

    setOnClickListeners();
  }