@Override
  public void onTextSet(String tag, String actualText) {

    if (ACTION_UPDATE_TAG.equals(tag)) {
      final ActionsManager actionsManager = new ActionsManager(this);
      final String timeStamp = TimeStampUtils.dateToTimeStamp(new Date());
      final UsersManager usersManager = new UsersManager(this);
      final UsersEntity currentUser = usersManager.getCurrentUser();

      ActionsEntity entity =
          new ActionsEntity(
              null,
              mIssuesEntity.getId(),
              timeStamp,
              "Atualização",
              actualText,
              currentUser.getId());
      actionsManager.refresh(entity);

    } else if (ACTION_CLOSE_TAG.equals(tag)) {
      final IssuesManager issuesManager = new IssuesManager(this);
      final ActionsManager actionsManager = new ActionsManager(this);
      final UsersManager usersManager = new UsersManager(this);
      final UsersEntity currentUser = usersManager.getCurrentUser();

      mIssuesEntity.setState(IssueUtils.STATE_CLOSED);
      issuesManager.refresh(mIssuesEntity);
      mImgFlagAndClockType.setImageResource(
          DashboardUtils.getImageResourceIdForStateFlagTypeAndClockType(
              mIssuesEntity.getState(),
              mIssuesEntity.getFlagType(),
              mIssuesEntity.getClockType(),
              true));

      final String timeStamp = TimeStampUtils.dateToTimeStamp(new Date());
      ActionsEntity entity =
          new ActionsEntity(
              null,
              mIssuesEntity.getId(),
              timeStamp,
              "Fechamento",
              actualText,
              currentUser.getId());
      actionsManager.refresh(entity);

    } else {
      throw new IllegalArgumentException("Invalid tag=" + tag);
    }
  }
 private void refreshScreen() {
   mImgFlagAndClockType.setImageResource(
       DashboardUtils.getImageResourceIdForStateFlagTypeAndClockType(
           mIssuesEntity.getState(),
           mIssuesEntity.getFlagType(),
           mIssuesEntity.getClockType(),
           true));
   mTxtSummary.setText(mIssuesEntity.getSummary());
   mTxtAcronymId.setText(mIssuesEntity.getAcronymId());
   mTxtDescription.setText(mIssuesEntity.getDescription());
   final UsersManager usersManager = new UsersManager(this);
   final String reportPhrase =
       "por "
           + usersManager.userFromId(mIssuesEntity.getReporterId()).getShortName()
           + " em "
           + TimeStampUtils.timeStampToFormattedString(mIssuesEntity.getTimeStamp());
   mTxtReporter.setText(reportPhrase);
   mTxtOwner.setText(
       mIssuesEntity.getOwnerId() == null
           ? "(não atribuído)"
           : usersManager.userFromId(mIssuesEntity.getOwnerId()).getShortName());
   final FollowersManager followersManager = new FollowersManager(this);
   mTxtFollowers.setText(
       followersManager.humanPhraseFromIssueId(
           mIssuesEntity.getId(), new UsersManager(this).getCurrentUser().getId()));
 }
 public void newComment(View view) {
   final String newCommentString = mEdtNewComment.getText().toString().trim();
   if (!TextUtils.isEmpty(newCommentString)) {
     CommentsEntity entity =
         new CommentsEntity(
             null,
             mCurrentAction.getId(),
             TimeStampUtils.dateToTimeStamp(new Date()),
             newCommentString,
             mCurrentUser.getId());
     new CommentsManager(this).refresh(entity);
     finish();
   }
 }
 private void addActionAssignToMe() {
   final UsersManager usersManager = new UsersManager(this);
   final UsersEntity currentUser = usersManager.getCurrentUser();
   if (!currentUser.getId().equals(mIssuesEntity.getOwnerId())) {
     final IssuesManager issuesManager = new IssuesManager(this);
     mIssuesEntity.setOwnerId(currentUser.getId());
     issuesManager.refresh(mIssuesEntity);
     mTxtOwner.setText(currentUser.getShortName());
     final String timeStamp = TimeStampUtils.dateToTimeStamp(new Date());
     ActionsManager actionsManager = new ActionsManager(this);
     ActionsEntity actionsEntity =
         new ActionsEntity(
             null,
             mIssuesEntity.getId(),
             timeStamp,
             "Atribuição",
             currentUser.getShortName() + " assumiu o incidente",
             currentUser.getId());
     actionsManager.refresh(actionsEntity);
   }
 }
  @Override
  public void onStringSelected(String tag, int chosenIndex) {
    if (ACTION_TYPE_DIALOG.equals(tag)) {
      addNewAction(chosenIndex);
    } else if (CHANGE_FLAG_DIALOG.equals(tag)) {
      final IssuesManager issuesManager = new IssuesManager(this);
      final ActionsManager actionsManager = new ActionsManager(this);
      final UsersManager usersManager = new UsersManager(this);
      final int oldFlagType = mIssuesEntity.getFlagType();
      mIssuesEntity.setFlagType(chosenIndex);
      issuesManager.refresh(mIssuesEntity);
      mImgFlagAndClockType.setImageResource(
          DashboardUtils.getImageResourceIdForStateFlagTypeAndClockType(
              mIssuesEntity.getState(),
              mIssuesEntity.getFlagType(),
              mIssuesEntity.getClockType(),
              true));

      final String timeStamp = TimeStampUtils.dateToTimeStamp(new Date());
      final String[] flagMeaningArray = getResources().getStringArray(R.array.flags_meaning_list);
      ActionsEntity actionsEntity =
          new ActionsEntity(
              null,
              mIssuesEntity.getId(),
              timeStamp,
              "Mudança de importância",
              "Incidente mudou de '"
                  + flagMeaningArray[oldFlagType]
                  + "' para '"
                  + flagMeaningArray[mIssuesEntity.getFlagType()]
                  + "'",
              usersManager.getCurrentUser().getId());
      actionsManager.refresh(actionsEntity);
    } else {
      throw new IllegalArgumentException("Invalid tag=" + tag);
    }
  }