コード例 #1
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
 /**
  * Rename the {@code list} to {@code newName}, which is assumed to not already be in use.
  *
  * @param realm Instance of Realm to use.
  * @param list List to rename.
  * @param newName New name for {@code list}.
  */
 public static void renameList(Realm realm, RBookList list, String newName) {
   if (newName == null || newName.isEmpty())
     throw new IllegalArgumentException("newName must be non-null and non-empty.");
   realm.executeTransaction(
       tRealm -> {
         list.name = newName;
         list.sortName = newName.toLowerCase();
       });
 }
コード例 #2
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
 /**
  * Deletes the {@code lists}, and all of their {@link RBookListItem}s, from Realm.
  *
  * @param realm Instance of Realm to use.
  * @param lists Lists to delete.
  */
 public static void deleteLists(Realm realm, Collection<RBookList> lists) {
   if (lists != null && !lists.isEmpty()) {
     realm.executeTransaction(
         tRealm -> {
           for (RBookList list : lists) {
             // First, delete the list items (unless this is a smart list).
             if (!list.isSmartList) list.listItems.deleteAllFromRealm();
             // Then, delete the book list.
             list.deleteFromRealm();
           }
         });
   }
 }
コード例 #3
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
  /**
   * Moves the given {@link RBookListItem}s to the end of {@code bookList}.
   *
   * @param realm Instance of Realm to use.
   * @param bookList Book list which owns {@code itemsToMove}.
   * @param itemsToMove Items to move. Items must already exist in Realm and be owned by {@code
   *     bookList}.
   */
  public static void moveItemsToEnd(
      Realm realm, RBookList bookList, List<RBookListItem> itemsToMove) {
    bookList.throwIfSmartList();
    if (itemsToMove == null || itemsToMove.isEmpty()) return;

    realm.executeTransaction(
        tRealm -> {
          // Get the next last open position.
          Long nextLastPos = bookList.nextPos;
          // Loop through itemsToMove and move those items to the end of this list.
          for (RBookListItem item : itemsToMove) {
            item.pos = nextLastPos;
            nextLastPos += C.LIST_ITEM_GAP;
          }
          // Set bookList's nextPos.
          bookList.nextPos = nextLastPos;
        });
  }
コード例 #4
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
  /**
   * Moves the given {@link RBookListItem}s to the start of {@code bookList}.
   *
   * @param realm Instance of Realm to use.
   * @param bookList Book list which owns {@code itemsToMove}.
   * @param itemsToMove Items to move. Items must already exist in Realm and be owned by {@code
   *     bookList}.
   */
  public static void moveItemsToStart(
      Realm realm, RBookList bookList, List<RBookListItem> itemsToMove) {
    bookList.throwIfSmartList();
    if (itemsToMove == null || itemsToMove.isEmpty()) return;

    realm.executeTransaction(
        tRealm -> {
          // Get the next first open position.
          Long nextFirstPos = bookList.listItems.where().min("pos").longValue() - C.LIST_ITEM_GAP;
          // Loop through itemsToMove backwards and move those items to the start of this list.
          for (int i = itemsToMove.size() - 1; i >= 0; i--) {
            itemsToMove.get(i).pos = nextFirstPos;
            nextFirstPos -= C.LIST_ITEM_GAP;
          }
        });
  }
コード例 #5
0
ファイル: ActionHelper.java プロジェクト: bkromhout/Minerva
 /**
  * Update the RealmUserQuery string in a smart list.
  *
  * @param realm Instance of Realm to use.
  * @param list List to update {@link RBookList#smartListRuqString} for. Must be configured as a
  *     smart list.
  * @param ruqString RealmUserQuery string to put into {@code list}. Can be empty or null.
  * @throws IllegalStateException if {@code list} isn't a smart list.
  */
 public static void updateSmartList(Realm realm, RBookList list, String ruqString) {
   if (list == null) return;
   if (!list.isSmartList) throw new IllegalStateException("list is not a smart list.");
   realm.executeTransaction(tRealm -> list.smartListRuqString = ruqString);
 }