Пример #1
0
  @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);
  }
Пример #2
0
  @OptionsItem(R.id.action_add_to_bookmarks)
  void onActionAddToBookmarks() {
    Log.d(TAG, "onActionAddToBookmarks");
    Bookmark bookmark;

    String title = getTitle().toString();
    if (title == null) {
      title = "";
    }

    CharSequence descriptionCharSequence = webView.getContentDescription();
    String description = "";
    if (descriptionCharSequence != null) {
      description = descriptionCharSequence.toString();
    }
    String url = webView.getUrl();
    if (url == null || url.isEmpty()) {
      return;
    }

    try {
      bookmark = databaseHelper.createBookmark(url, title, description);
    } catch (SQLException e) {
      activityHelper.showError(e);
      return;
    }
    Resources resources = getResources();
    String message =
        resources.getString(
            R.string.message_item_added_to,
            bookmark.getTitle(),
            resources.getString(R.string.title_activity_browser_bookmarks));
    SnackbarManager.show(createSnackbar().text(message), this);
  }