コード例 #1
0
ファイル: RecentFragment.java プロジェクト: bkromhout/Minerva
  /**
   * Called when we wish to take some action.
   *
   * @param event {@link ActionEvent}.
   */
  @Subscribe
  public void onActionEvent(ActionEvent event) {
    //noinspection unchecked
    List<RBook> selectedItems = adapter.getSelectedRealmObjects();

    switch (event.getActionId()) {
      case R.id.action_clear:
        realm.executeTransaction(
            tRealm -> {
              // Set isInRecents to false for all RBooks which currently have it set to true.
              RealmResults<RBook> recentBooks =
                  tRealm.where(RBook.class).equalTo("isInRecents", true).findAll();
              for (int i = recentBooks.size() - 1; i >= 0; i--)
                recentBooks.get(i).isInRecents = false;
            });
        break;
      case R.id.action_rate:
        ActionHelper.rateBooks(realm, selectedItems, (Integer) event.getData());
        break;
      case R.id.action_read:
        // Save the position to update so we can refresh the list correctly when resuming.
        this.moveToTop = event.getPosToUpdate();
        break;
      case R.id.action_mark_as:
        int whichMark = (int) event.getData();
        ActionHelper.markBooks(
            realm,
            selectedItems,
            whichMark < 2 ? MarkType.NEW : MarkType.UPDATED,
            whichMark % 2 == 0);
        break;
      case R.id.action_add_to_list:
        ActionHelper.addBooksToList(realm, selectedItems, (String) event.getData());
        break;
      case R.id.action_re_import:
        ActionHelper.reImportBooks(selectedItems);
        break;
      case R.id.action_remove:
        realm.executeTransaction(
            tRealm -> {
              // Set isInRecents to false for all selected RBooks.
              for (RBook book : selectedItems) book.isInRecents = false;
            });
        break;
      case R.id.action_delete:
        ActionHelper.deleteBooks(realm, selectedItems, (boolean) event.getData());
        break;
    }
    if (actionMode != null) actionMode.finish();
  }