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