public List<String> titles() { synchronized (myBooksByFile) { final List<String> titles = new ArrayList<String>(myBooksByFile.size()); for (Book book : myBooksByFile.values()) { titles.add(book.getTitle()); } return titles; } }
public void addBookToRecentList(Book book) { final List<Long> ids = myDatabase.loadRecentBookIds(); final Long bookId = book.getId(); ids.remove(bookId); ids.add(0, bookId); if (ids.size() > 12) { ids.remove(12); } myDatabase.saveRecentBookIds(ids); }
private List<Book> books(List<Long> ids) { final List<Book> bookList = new ArrayList<Book>(ids.size()); for (long id : ids) { final Book book = getBookById(id); if (book != null) { bookList.add(book); } } return bookList; }
public List<Book> booksForTag(Tag tag) { final boolean isNull = Tag.NULL.equals(tag); final LinkedList<Book> filtered = new LinkedList<Book>(); for (Book b : books()) { final List<Tag> bookTags = b.tags(); if (isNull && bookTags.isEmpty() || bookTags.contains(tag)) { filtered.add(b); } } return filtered; }
public List<Book> booksForAuthor(Author author) { final boolean isNull = Author.NULL.equals(author); final LinkedList<Book> filtered = new LinkedList<Book>(); for (Book b : books()) { final List<Author> bookAuthors = b.authors(); if (isNull && bookAuthors.isEmpty() || bookAuthors.contains(author)) { filtered.add(b); } } return filtered; }
public void addTag(Tag tag) { if (tag != null) { if (myTags == null) { myTags = new ArrayList<Tag>(); } if (!myTags.contains(tag)) { myTags.add(tag); myIsSaved = false; } } }
private void addAuthor(Author author) { if (author == null) { return; } if (myAuthors == null) { myAuthors = new ArrayList<Author>(); myAuthors.add(author); myIsSaved = false; } else if (!myAuthors.contains(author)) { myAuthors.add(author); myIsSaved = false; } }
public List<Author> authors() { final Set<Author> authors = new TreeSet<Author>(); synchronized (myBooksByFile) { for (Book book : myBooksByFile.values()) { final List<Author> bookAuthors = book.authors(); if (bookAuthors.isEmpty()) { authors.add(Author.NULL); } else { authors.addAll(bookAuthors); } } } return new ArrayList<Author>(authors); }
public List<Book> booksForSeriesAndAuthor(String series, Author author) { final boolean isNull = Author.NULL.equals(author); final LinkedList<Book> filtered = new LinkedList<Book>(); for (Book b : books()) { final List<Author> bookAuthors = b.authors(); final SeriesInfo info = b.getSeriesInfo(); if (info != null && series.equals(info.Title) && (isNull && bookAuthors.isEmpty() || bookAuthors.contains(author))) { filtered.add(b); } } return filtered; }
public void removeBook(Book book, boolean deleteFromDisk) { synchronized (myBooksByFile) { myBooksByFile.remove(book.File); myBooksById.remove(book.getId()); final List<Long> ids = myDatabase.loadRecentBookIds(); if (ids.remove(book.getId())) { myDatabase.saveRecentBookIds(ids); } if (deleteFromDisk) { book.File.getPhysicalFile().delete(); } } fireBookEvent(BookEvent.Removed, book); }
public List<Tag> tags() { final Set<Tag> tags = new HashSet<Tag>(); synchronized (myBooksByFile) { for (Book book : myBooksByFile.values()) { final List<Tag> bookTags = book.tags(); if (bookTags.isEmpty()) { tags.add(Tag.NULL); } else { for (Tag t : bookTags) { for (; t != null; t = t.Parent) { tags.add(t); } } } } } return new ArrayList<Tag>(tags); }
public List<String> titlesForSeriesAndAuthor(String series, Author author, int limit) { if (limit <= 0) { return Collections.emptyList(); } final boolean isNull = Author.NULL.equals(author); final ArrayList<String> titles = new ArrayList<String>(limit); synchronized (myBooksByFile) { for (Book b : myBooksByFile.values()) { final List<Author> bookAuthors = b.authors(); final SeriesInfo info = b.getSeriesInfo(); if (info != null && series.equals(info.Title) && (isNull && bookAuthors.isEmpty() || bookAuthors.contains(author))) { titles.add(b.getTitle()); if (--limit == 0) { break; } } } } return titles; }
private void processFilesQueue() { synchronized (myFilesToRescan) { if (!myStatus.IsCompleted) { return; } final Set<ZLFile> filesToRemove = new HashSet<ZLFile>(); for (String path : myFilesToRescan) { path = new ZLPhysicalFile(new File(path)).getPath(); synchronized (myBooksByFile) { for (ZLFile f : myBooksByFile.keySet()) { if (f.getPath().startsWith(path)) { filesToRemove.add(f); } } } } for (ZLFile file : collectPhysicalFiles(myFilesToRescan)) { // TODO: // collect books from archives // rescan files and check book id filesToRemove.remove(file); final Book book = getBookByFile(file); if (book != null) { saveBook(book, false); } } for (ZLFile f : filesToRemove) { synchronized (myBooksByFile) { final Book book = myBooksByFile.remove(f); if (book != null) { myBooksById.remove(book.getId()); fireBookEvent(BookEvent.Removed, book); } } } myFilesToRescan.clear(); } }
void addAuthorWithNoCheck(Author author) { if (myAuthors == null) { myAuthors = new ArrayList<Author>(); } myAuthors.add(author); }
void addTagWithNoCheck(Tag tag) { if (myTags == null) { myTags = new ArrayList<Tag>(); } myTags.add(tag); }
public void rescan(String path) { synchronized (myFilesToRescan) { myFilesToRescan.add(path); processFilesQueue(); } }
public Book getRecentBook(int index) { List<Long> recentIds = myDatabase.loadRecentBookIds(); return recentIds.size() > index ? getBookById(recentIds.get(index)) : null; }