コード例 #1
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
  /**
   * Delete the given {@code tag}.
   *
   * @param realm Instance of Realm to use.
   * @param tag {@link RTag} to delete.
   */
  public static void deleteTag(Realm realm, RTag tag) {
    TaggingHelper th = TaggingHelper.get();
    // Indicate that we might need an explicit update.
    th.markForExplicitUpdateIfNecessary();

    // Delete the tag from Realm.
    String tagName = tag.name;
    realm.executeTransaction(tRealm -> tag.deleteFromRealm());

    // If this was one of the new/updated book tags, be sure that we null that preference's value.
    String prefVal = Minerva.prefs().getNewBookTag(null);
    if (prefVal != null && prefVal.equals(tagName)) Minerva.prefs().putNewBookTag(null);
    prefVal = Minerva.prefs().getUpdatedBookTag(null);
    if (prefVal != null && prefVal.equals(tagName)) Minerva.prefs().putUpdatedBookTag(null);

    // Remove tag name from the lists (if present).
    th.oldCheckedItems.remove(tagName);
    th.oldPartiallyCheckedItems.remove(tagName);
    th.newCheckedItems.remove(tagName);
    th.newPartiallyCheckedItems.remove(tagName);
  }
コード例 #2
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
  /**
   * Rename the given {@code tag}.
   *
   * @param realm Instance of Realm to use.
   * @param tag {@link RTag} to rename.
   * @param newName New tag name.
   */
  public static void renameTag(Realm realm, RTag tag, String newName) {
    String oldName = tag.name;
    // Name is available; rename the RTag.
    realm.executeTransaction(
        tRealm -> {
          tag.name = newName;
          tag.sortName = newName.toLowerCase();
        });

    // Now make sure that we swap the old name for the new one in the old/new lists.
    TaggingHelper th = TaggingHelper.get();
    if (th.oldCheckedItems.remove(oldName)) th.oldCheckedItems.add(newName);
    if (th.oldPartiallyCheckedItems.remove(oldName)) th.oldPartiallyCheckedItems.add(newName);
    if (th.newCheckedItems.remove(oldName)) th.newCheckedItems.add(newName);
    if (th.newPartiallyCheckedItems.remove(oldName)) th.newPartiallyCheckedItems.add(newName);
  }