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); }
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 Book getRecentBook(int index) { List<Long> recentIds = myDatabase.loadRecentBookIds(); return recentIds.size() > index ? getBookById(recentIds.get(index)) : null; }
public List<Book> recentBooks() { return books(myDatabase.loadRecentBookIds()); }