Ejemplo n.º 1
0
 @Override
 public QueryResult<LibraryBook> findAllByLastAdded() {
   QueryResult<LibraryBook> result =
       helper.findAllOrderedBy(
           LibraryDatabaseHelper.Field.date_added, LibraryDatabaseHelper.Order.DESC);
   result.setLimit(LIMIT);
   return result;
 }
Ejemplo n.º 2
0
 @Override
 public QueryResult<LibraryBook> findUnread() {
   return helper.findByField(
       LibraryDatabaseHelper.Field.date_last_read,
       null,
       LibraryDatabaseHelper.Field.title,
       LibraryDatabaseHelper.Order.ASC);
 }
Ejemplo n.º 3
0
  @Override
  public LibraryBook getBook(String fileName) {
    QueryResult<LibraryBook> booksByFile =
        helper.findByField(LibraryDatabaseHelper.Field.file_name, fileName, null, Order.ASC);

    switch (booksByFile.getSize()) {
      case 0:
        return null;
      case 1:
        return booksByFile.getItemAt(0);
      default:
        throw new IllegalStateException("Non unique file-name: " + fileName);
    }
  }
Ejemplo n.º 4
0
  @Override
  public void storeBook(String fileName, Book book, boolean updateLastRead, boolean copyFile)
      throws IOException {

    File bookFile = new File(fileName);

    boolean hasBook = hasBook(bookFile.getName());

    if (hasBook && !updateLastRead) {
      return;
    } else if (hasBook) {
      helper.updateLastRead(bookFile.getName(), -1);
      return;
    }

    Metadata metaData = book.getMetadata();

    String authorFirstName = "Unknown author";
    String authorLastName = "";

    if (metaData.getAuthors().size() > 0) {
      authorFirstName = metaData.getAuthors().get(0).getFirstname();
      authorLastName = metaData.getAuthors().get(0).getLastname();
    }

    byte[] thumbNail = null;

    try {
      if (book.getCoverImage() != null && book.getCoverImage().getSize() < MAX_COVER_SIZE) {
        thumbNail = resizeImage(book.getCoverImage().getData());
        book.getCoverImage().close();
      }
    } catch (IOException io) {

    } catch (OutOfMemoryError err) {
      // If the image resource is too big, just import without a cover.
    }

    String description = "";

    if (!metaData.getDescriptions().isEmpty()) {
      description = metaData.getDescriptions().get(0);
    }

    String title = book.getTitle();

    if (title.trim().length() == 0) {
      title = fileName.substring(fileName.lastIndexOf('/') + 1);
    }

    if (copyFile) {
      bookFile = copyToLibrary(fileName, authorLastName + ", " + authorFirstName, title);
    }

    this.helper.storeNewBook(
        bookFile.getAbsolutePath(),
        authorFirstName,
        authorLastName,
        title,
        description,
        thumbNail,
        updateLastRead);
  }
Ejemplo n.º 5
0
 @Override
 public void updateReadingProgress(String fileName, int progress) {
   helper.updateLastRead(new File(fileName).getName(), progress);
 }
Ejemplo n.º 6
0
 @Override
 public boolean hasBook(String fileName) {
   return helper.hasBook(fileName);
 }
Ejemplo n.º 7
0
 public void close() {
   helper.close();
 }
Ejemplo n.º 8
0
 @Override
 public KeyedQueryResult<LibraryBook> findAllByTitle() {
   return helper.findAllKeyedBy(
       LibraryDatabaseHelper.Field.title, LibraryDatabaseHelper.Order.ASC);
 }
Ejemplo n.º 9
0
 @Override
 public QueryResult<LibraryBook> findAllByAuthor() {
   return helper.findAllKeyedBy(
       LibraryDatabaseHelper.Field.a_last_name, LibraryDatabaseHelper.Order.ASC);
 }