public List<String> titlesForAuthor(Author author, int limit) { if (limit <= 0) { return Collections.emptyList(); } final ArrayList<String> titles = new ArrayList<String>(limit); final boolean isNull = Author.NULL.equals(author); synchronized (myBooksByFile) { for (Book b : myBooksByFile.values()) { if (isNull ? b.authors().isEmpty() : b.authors().contains(author)) { titles.add(b.getTitle()); if (--limit == 0) { break; } } } } return titles; }
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 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 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; }
@Override public boolean containsBook(Book book) { return book != null && book.authors().contains(Author); }
@Override protected void onPostExecute(JSONArray result) { linearLayoutSearchLayout.setEnabled(true); buttonSearch.setVisibility(View.VISIBLE); progressBarSearchButton.setVisibility(View.GONE); int returnFromJson = App.GENERAL_NO_INTERNET; try { returnFromJson = result.getJSONObject(0).getInt("result"); } catch (Exception e1) { returnFromJson = App.BOOKS_OF_USER_NO_BOOKS; } switch (returnFromJson) { case App.GENERAL_SUCCESSFULL: // Hide search pane & show results linearLayoutSearchLayout.setVisibility(View.GONE); textViewSearchResults.setVisibility(View.VISIBLE); // Is viewing results now! isMakingSearch = false; invalidateOptionsMenu(); // Save all books to array try { textViewSearchResults.setText( getString(R.string.results) + " (" + result.getJSONObject(0).getInt("booksNum") + ")"); } catch (Exception e) { } for (int i = 1; i < result.length(); i++) { try { JSONObject row; Book book = new Book(); row = result.getJSONObject(i); String isbn = row.getString("isbn"); String username = row.getString("username"); int bookStatus = row.getInt("status"); Book bookExistance = bookExists(isbn); // Get the use and its book status info Book.DataClassUser dataClassUser = new Book.DataClassUser(username, bookStatus); // Check if book already exists if (bookExistance != null) { // Add only new owner bookExistance.owners.add(dataClassUser); // User Owns that book if (dataClassUser.username.equalsIgnoreCase(app.user.username)) { bookExistance.status = bookStatus; } } // Add book + his first onwer else { String title = row.getString("title"); String authors = row.getString("authors"); int publishedYear = row.getInt("publishedYear"); int pageCount = row.getInt("pageCount"); String dateOfInsert = row.getString("dateOfInsert"); String imgURL = row.getString("imgURL"); String lang = row.getString("lang"); book.isbn = isbn; book.title = title; book.authors = authors; book.publishedYear = publishedYear; book.pageCount = pageCount; book.dateOfInsert = dateOfInsert; book.imgURL = imgURL; book.lang = lang; // Add book first owner book.owners.add(dataClassUser); // Is user's book if (dataClassUser.username.equalsIgnoreCase(app.user.username)) { book.status = bookStatus; } else { book.status = App.BOOK_STATE_USER_DONT_OWNS; } // Insert book to array searchResultBooks.add(book); } } catch (JSONException e) { } } adapterBookResults = new AdapterBookInfo( BookSearch.this.getApplicationContext(), R.layout.book_item, searchResultBooks, true); // Show list listViewBookResults.setAdapter(adapterBookResults); break; case App.GENERAL_NO_INTERNET: // TODO refresh button, and call again asynctask from // refresh button break; case App.BOOKS_OF_USER_NO_BOOKS: Toast.makeText(BookSearch.this, R.string.msgNoResultsFound, Toast.LENGTH_LONG).show(); break; case App.GENERAL_WEIRD_ERROR: Toast.makeText(BookSearch.this, R.string.msgWeirdError, Toast.LENGTH_LONG).show(); break; case App.GENERAL_DATABASE_ERROR: Toast.makeText(BookSearch.this, R.string.msgDatabaseError, Toast.LENGTH_LONG).show(); break; default: break; } }