Ejemplo n.º 1
0
  private boolean updateCurrentSolutionWords() {
    Tongue currentTongue = getCurrentTongue();
    SelectedBitmap currentBitmap = getCurrentBitmap();
    if (currentBitmap == null || currentTongue == null) {
      return false;
    }
    String solutionWords = mSolutionWords.getText().toString();
    List<Solution> solutions = currentBitmap.mBuilder.getSolutions();
    int currentSolutionIndex;
    Solution currentSolution = null;
    if (solutions == null) {
      currentSolutionIndex = -1;
    } else {
      for (currentSolutionIndex = 0;
          currentSolutionIndex < solutions.size();
          currentSolutionIndex++) {
        currentSolution = solutions.get(currentSolutionIndex);
        if (currentSolution.getTongue().equals(currentTongue)) {
          break;
        }
        currentSolution = null;
      }
    }
    boolean updateStatus = false;
    if (TextUtils.isEmpty(solutionWords)) {
      if (currentSolution != null) {
        solutions.remove(currentSolutionIndex);
        if (solutions.isEmpty()) {
          currentBitmap.mBuilder.setSolutions(null);
          currentBitmap.mImage = null;
          updateStatus = true;
        }
      }
    } else {
      Solution newSolution = Solution.makeSolution(currentTongue, solutionWords.split(","));
      if (newSolution != null && solutions == null) {
        solutions = new ArrayList<>(mTongues.length);
        updateStatus = true;
      } else if (solutions != null && currentSolution != null) {
        solutions.remove(currentSolutionIndex);
      }
      if (newSolution != null) {
        solutions.add(newSolution);

        currentBitmap.mBuilder.setSolutions(solutions);
        if (currentBitmap.checkedBuild()) {
          updateStatus = true;
        }
      } else if (solutions != null && solutions.isEmpty()) {
        currentBitmap.mBuilder.setSolutions(null);
        currentBitmap.mImage = null;
        updateStatus = true;
      }
    }
    return updateStatus;
  }
Ejemplo n.º 2
0
  private boolean updateCurrentAuthorData() {
    boolean updateStatus = false;
    SelectedBitmap current = getCurrentBitmap();
    if (current == null) {
      return false;
    }
    mSaveResult = ImageXmlWriter.RESULT_NONE;
    ImageAuthor author = current.mBuilder.getAuthor();
    String authorNameText = mAuthorName.getText().toString();
    if (author == null) {
      author = new ImageAuthor();
      current.mBuilder.setAuthor(author);
      updateApplyToOthersButton(current);
      updateStatus = true;
    } else {
      if (TextUtils.isEmpty(author.getName()) && !TextUtils.isEmpty(authorNameText)) {
        updateStatus = true;
      }
    }
    author.setName(authorNameText);
    author.setSource(mAuthorSource.getText().toString());
    author.setExtras(mAuthorExtras.getText().toString());
    if (updateStatus) {
      current.checkedBuild();
      synchronized (mSelectedBitmaps) {
        for (SelectedBitmap bitmap : mSelectedBitmaps) {
          if (bitmap.mBuilder.getAuthor() == author) {
            bitmap.checkedBuild();
          }
        }
      }
    }
    if (TextUtils.isEmpty(author.getName())) {
      boolean authorCleared =
          TextUtils.isEmpty(author.getSource()) && TextUtils.isEmpty(author.getExtras());
      // if author data cleared, remove author from this and connected bitmaps
      // in any case clear image as name is required
      synchronized (mSelectedBitmaps) {
        for (SelectedBitmap bitmap : mSelectedBitmaps) {
          if (bitmap.mBuilder.getAuthor() == author) {
            if (authorCleared) {
              bitmap.mBuilder.setAuthor(null);
            }
            bitmap.mImage = null;
          }
        }
      }
      updateApplyToOthersButton(current);

      updateStatus = true;
    }
    return updateStatus;
  }