예제 #1
0
  public void testIsValid() {
    final RealmResults<AllTypes> results = testRealm.where(AllTypes.class).findAll();

    assertTrue(results.isValid());
    populateTestRealm(1);
    // still valid if result changed
    assertTrue(results.isValid());

    testRealm.close();
    assertFalse(results.isValid());
  }
예제 #2
0
  /**
   * Create a {@link RealmRecyclerViewAdapter} based on the current view options and return it.
   *
   * @return New {@link RealmRecyclerViewAdapter}. Will return null if we cannot get the activity
   *     context, if {@link #books} is null or invalid, or if the current value of {@link #cardType}
   *     is not valid.
   */
  private BaseBookCardAdapter makeAdapter() {
    if (books == null || !books.isValid()) return null;

    BaseBookCardAdapter adapter = null;

    // Create a new adapter based on the card type.
    switch (cardType) {
      case NORMAL:
        adapter = new BookCardAdapter(getActivity(), books);
        break;
      case NO_COVER:
        adapter = new BookCardNoCoverAdapter(getActivity(), books);
        break;
      case COMPACT:
        adapter = new BookCardCompactAdapter(getActivity(), books);
        break;
    }

    adapter.setSwipeHandler(this);
    return adapter;
  }
예제 #3
0
 /** Open the most recently read book when the FAB is clicked. */
 @OnClick(R.id.fab)
 void onFabClick() {
   if (books != null && books.isValid() && !books.isEmpty())
     ActionHelper.openBookUsingIntent(realm, books.first());
 }