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; }
/** Fills all image data of the currently selected bitmap if any. */ private void fillImageData() { boolean wasFilling = mFillingImageData; mFillingImageData = true; mDisplayedImageIndex = Math.max(mDisplayedImageIndex, 0); mDisplayedImageIndex = Math.min(mDisplayedImageIndex, mSelectedBitmaps.size() - 1); if (mDisplayedImageIndex < 0) { return; } final SelectedBitmap selected = getCurrentBitmap(); if (selected == null) { return; } mNextImage.setVisibility( mDisplayedImageIndex < mSelectedBitmaps.size() - 1 ? View.VISIBLE : View.INVISIBLE); mPreviousImage.setVisibility(mDisplayedImageIndex > 0 ? View.VISIBLE : View.INVISIBLE); mSaveResult = ImageXmlWriter.RESULT_NONE; if (selected.mSnapshot != null) { mBitmapSnapshot.setImageBitmap(selected.mSnapshot); selected.mLoadSnapshotTask = null; } else { mBitmapSnapshot.setImageResource(REFUSE_RESOURCE); selected.mLoadSnapshotTask = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { ImageUtil.CACHE.makeReusable(selected.mSnapshot); selected.mSnapshot = ImageUtil.loadBitmap( selected.mPathInTemp, SNAPSHOT_WIDTH, SNAPSHOT_HEIGHT, BitmapUtil.MODE_FIT_INSIDE); return null; } @Override public void onPostExecute(Void result) { fillImageData(); } }.execute(); } fillImageDataSolution(); fillImageDataAuthor(); mFillingImageData = wasFilling; updateCurrentImageStatus(); }
private void applyAuthorInfoToOthers() { mSaveResult = ImageXmlWriter.RESULT_NONE; boolean updateStatus = false; boolean updateApplyToOthers = false; synchronized (mSelectedBitmaps) { SelectedBitmap current = getCurrentBitmap(); if (current == null) { return; } ImageAuthor author = current.mBuilder.getAuthor(); if (author == null) { return; // should not be clickable if there is not an author for current } if (mApplyToOthersStateRemoveConnection) { ImageAuthor copy = new ImageAuthor( author.getName(), author.getSource(), author.getLicense(), author.getTitle(), author.getExtras()); current.mBuilder.setAuthor(copy); updateApplyToOthers = true; } else { for (SelectedBitmap curr : mSelectedBitmaps) { if (curr.mBuilder.getAuthor() == null) { curr.mBuilder.setAuthor(author); updateApplyToOthers = true; if (curr.checkedBuild()) { updateStatus = true; } } } } if (updateApplyToOthers) { updateApplyToOthersButton(current); } } if (updateStatus) { updateStatus(); } }
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; }