コード例 #1
0
ファイル: RecentFragment.java プロジェクト: bkromhout/Minerva
  /**
   * Called when one of the cards is clicked.
   *
   * @param event {@link BookCardClickEvent}.
   */
  @Subscribe
  public void onCardClicked(BookCardClickEvent event) {
    // Get the associated RBook.
    RBook book = books.where().equalTo("relPath", event.getRelPath()).findFirst();

    if (actionMode != null) {
      if (event.getType() == BookCardClickEvent.Type.LONG)
        adapter.extendSelectionTo(event.getAdapterPosition());
      else adapter.toggleSelected(event.getAdapterPosition());
      return;
    }
    // Do something based on the click type.
    switch (event.getType()) {
      case NORMAL:
        // Open the book file.
        ActionHelper.openBookUsingIntent(realm, book, event.getLayoutPosition());
        break;
      case LONG:
        // Start multi-select.
        adapter.toggleSelected(event.getAdapterPosition());
        startActionMode();
        break;
      case QUICK_TAG:
        TaggingActivity.start(this, book);
        break;
    }
  }
コード例 #2
0
ファイル: RecentFragment.java プロジェクト: bkromhout/Minerva
  @Override
  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    // Handle select all/none first, and if it isn't those then don't do anything if we haven't
    // selected any items.
    if (item.getItemId() == R.id.action_select_all) {
      adapter.selectAll();
      return true;
    } else if (item.getItemId() == R.id.action_select_none) {
      adapter.clearSelections();
      return true;
    } else if (adapter.getSelectedItemCount() == 0) return true;

    // Handle actions.
    switch (item.getItemId()) {
      case R.id.action_tag:
        //noinspection unchecked
        TaggingActivity.start(this, adapter.getSelectedRealmObjects());
        return true;
      case R.id.action_rate:
        int initialRating =
            adapter.getSelectedItemCount() == 1
                ? ((RBook) adapter.getSelectedRealmObjects().get(0)).rating
                : 0;
        Dialogs.ratingDialog(getContext(), initialRating);
        return true;
      case R.id.action_mark_as:
        Dialogs.markAsDialog(getActivity());
        return true;
      case R.id.action_add_to_list:
        Dialogs.addToListDialogOrSnack(getActivity(), realm);
        return true;
      case R.id.action_re_import:
        Dialogs.simpleConfirmDialog(
            getContext(),
            R.string.title_re_import_books,
            R.string.prompt_re_import_books,
            R.string.action_re_import,
            R.id.action_re_import);
        return true;
      case R.id.action_remove:
        Dialogs.simpleConfirmDialog(
            getContext(),
            R.string.title_remove_books,
            R.string.prompt_remove_from_recents,
            R.string.action_remove,
            R.id.action_remove);
        return true;
      case R.id.action_delete:
        Dialogs.confirmCheckBoxDialog(
            getContext(),
            R.string.title_delete_books,
            R.string.prompt_delete_books,
            R.string.prompt_delete_from_device_too,
            R.string.action_delete,
            R.id.action_delete);
        return true;
      default:
        return false;
    }
  }