@Override public void onClickTranslatePanelAddToFlashcardButton(DicItemListView.Data data) { final Card card; try { final Card duplicate = databaseHelper.getCardByDisplay(data.Index.toString()); if (duplicate != null) { activityHelper.onDuplicatedCardFound( duplicate, data.Trans.toString(), dictionaries.getDictionary(data.getDic()).getName()); return; } card = databaseHelper.createCard(data); } catch (SQLException e) { activityHelper.showError(e); return; } Resources resources = getResources(); String message = resources.getString( R.string.message_item_added_to, card.getShortDisplay(), resources.getString(R.string.title_activity_flashcard)); SnackbarManager.show( createSnackbar() .text(message) .type(SnackbarType.MULTI_LINE) .actionLabel(R.string.action_undo) .actionListener( new ActionClickListener() { @Override public void onActionClicked(Snackbar snackbar) { String message = getResources() .getString(R.string.message_item_removed, card.getShortDisplay()); try { databaseHelper.deleteCard(card); } catch (SQLException e) { activityHelper.showError(e); return; } SnackbarManager.show( createSnackbar() .text(message) .type(SnackbarType.MULTI_LINE) .duration(Snackbar.SnackbarDuration.LENGTH_SHORT), BrowserActivity.this); } }), this); }
@Override @UiThread public void onDictionaryServiceResult(String query, ArrayList<DicItemListView.Data> result) { String dictionaryName = ""; DicItemListView.Data firstWordData = null; for (DicItemListView.Data data : result) { if (dictionaryName.equals("") && data.getMode() == DicItemListView.Data.FOOTER) { dictionaryName = data.Index.toString(); } if (firstWordData == null && data.getMode() == DicItemListView.Data.WORD) { firstWordData = data; } } if (firstWordData == null) { activityHelper.showToast(R.string.message_no_result); return; } translatePanelFragment.setDictionaryName(dictionaryName); translatePanelFragment.setData(firstWordData); translatePanelFragment.show(); }