private void fireItemConsumedEvent() { ItemConsumedEvent event = new ItemConsumedEvent(readyToDraggableItem); playerServices.getEventBus().fireEventFromSource(event, this); if (isCorrect()) { sendEventCode(model.getEventCode(ImageGapModule.EVENT_CORRECT)); } else { sendEventCode(model.getEventCode(ImageGapModule.EVENT_WRONG)); } }
@Override public void reset() { readyToDraggableItem = null; consumedItem = null; view.setImageUrl(""); view.setDisabled(model.isDisabled()); if (model.isVisible()) { view.show(); } else { view.hide(); } }
private void hideAnswers() { if(!model.isActivity() && isConnectedWithMath){ this.isShowAnswersActive = false; view.setDisabled(false); } if ((!model.isActivity() || !this.isShowAnswersActive)) { return; } this.isShowAnswersActive = false; reset(); view.resetStyles(); view.setDisabled(false); setState(currentState); readyToDraggableItem = userReadyToDraggableItem; userReadyToDraggableItem = null; }
private void removeItem() { if (consumedItem != null) { view.setImageUrl(""); fireItemReturnedEvent(consumedItem); consumedItem = null; ValueChangedEvent valueEvent = new ValueChangedEvent(model.getId(), "", "", "0"); playerServices.getEventBus().fireEvent(valueEvent); } }
private void insertItem() { if (readyToDraggableItem != null) { view.setImageUrl(readyToDraggableItem.getValue()); consumedItem = readyToDraggableItem; fireItemConsumedEvent(); String score = Integer.toString(getScore()); ValueChangedEvent valueEvent = new ValueChangedEvent(model.getId(), "", consumedItem.getId(), score); playerServices.getEventBus().fireEvent(valueEvent); view.makeDraggable(this); } }
public boolean isCorrect() { if (consumedItem != null) { String[] answers = model.getAnswerId().split(";"); for (int i = 0; i < answers.length; i++) { String answer = answers[i]; if (consumedItem.getId().compareTo(answer) == 0) { return true; } } } return false; }
@Override public void addView(IModuleView display) { if (display instanceof IDisplay) { view = (IDisplay) display; view.addListener(new IViewListener() { @Override public void onClicked() { viewClicked(); } }); view.makeDroppable(this); view.setDisabled(model.isDisabled()); } }
private void showAnswers() { if(!model.isActivity() && isConnectedWithMath){ this.isShowAnswersActive = true; if(!isSetGapAnswers){ view.resetStyles(); } view.setDisabled(true); view.removeClass("ui-state-disabled"); } if (!model.isActivity() || this.isShowAnswersActive) { return; } this.isShowAnswersActive = true; userReadyToDraggableItem = readyToDraggableItem; showAnswersModeDisabled = view.getDisabled(); this.currentState = getState(); view.resetStyles(); view.setDisabled(true); setCorrectImage(); view.showCorrectAnswers(); view.removeClass("ui-state-disabled"); }
@Override public void setShowErrorsMode() { if (this.isShowAnswersActive) hideAnswers(); isShowErrorsMode = true; workModeDisabled = view.getDisabled(); view.setDisabled(true); if (model.isActivity()) { if (getScore() > 0) { view.showAsCorrect(); } else { view.showAsError(); } } view.removeClass("ui-state-disabled"); }
public ImageGapPresenter(ImageGapModule model, IPlayerServices services) { this.model = model; this.playerServices = services; isVisible = model.isVisible(); connectHandlers(); }
private boolean isActivity() { return model.isActivity(); }
@Override public String getName() { return model.getId(); }
@Override public int getScore() { return model.isActivity() && isCorrect() ? 1 : 0; }
@Override public int getMaxScore() { return model.isActivity() ? 1 : 0; }
@Override public int getErrorCount() { return consumedItem != null && getScore() == 0 && model.isActivity() ? 1 : 0; }
@Override public String getSerialId() { return model.getId(); }
private void setCorrectImage() { String[] answers = model.getAnswerId().split(";"); ImageSourcePresenter igp = (ImageSourcePresenter) playerServices.getModule(answers[0]); view.setImageUrl(igp.getImageUrl()); }
private void fireItemReturnedEvent(DraggableItem previouslyConsumedItem) { ItemReturnedEvent event = new ItemReturnedEvent(previouslyConsumedItem); playerServices.getEventBus().fireEvent(event); sendEventCode(model.getEventCode(ImageGapModule.EVENT_EMPTY)); }