private void installSingleBook(String initials) {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      if (initials.equalsIgnoreCase(book.getInitials())) {
        String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode();
        System.out.println("Found in repo:" + lang + " " + book.getName());

        try {
          if (Books.installed().getBook(book.getInitials()) != null) {
            System.out.println("Already installed:" + book.getInitials() + ":" + book.getName());
          } else {
            System.out.println(
                "Downloading and installing:" + book.getInitials() + ":" + book.getName());
            bookInstaller.installBook(REPOSITORY, book);
            waitToFinish();
          }

          Book installedBook = bookInstaller.getInstalledBook(book.getInitials());
          if (installedBook == null) {
            System.out.println("Not installed:" + book.getInitials() + " Name:" + book.getName());
          }

        } catch (Exception e) {
          System.out.println("Error installing:" + book.getInitials());
          e.printStackTrace();
        }
      }
    }
  }
  private void showRepoBooks() {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode();
      System.out.println(lang + " " + book.getName());
    }
  }
示例#3
0
  /**
   * return a list of all available docs that have not already been downloaded, have no lang, or
   * don't work
   *
   * @return
   */
  public List<Book> getDownloadableDocuments(boolean refresh) {
    List<Book> availableDocs = null;
    try {
      availableDocs = SwordDocumentFacade.getInstance().getDownloadableDocuments(refresh);

      // create a Map of installed doc names so we can remove them from the list of downloadable
      // books
      // need to compare using lower case because Xiphos repo books are lower case
      List<Book> installedDocs = SwordDocumentFacade.getInstance().getDocuments();
      Map<String, Object> installedDocInitials = new HashMap<String, Object>();
      for (Book book : installedDocs) {
        Log.d(TAG, "Install list " + book.getInitials() + "/" + book.getInitials().toLowerCase());
        installedDocInitials.put(book.getInitials().toLowerCase(), null);
      }

      // there are a number of books we need to filter out of the download list for various reasons
      for (Iterator<Book> iter = availableDocs.iterator(); iter.hasNext(); ) {
        Book doc = iter.next();
        if (doc.getLanguage() == null) {
          Log.d(TAG, "Ignoring " + doc.getInitials() + " because it has no language");
          iter.remove();
        } else if (installedDocInitials.containsKey(doc.getInitials().toLowerCase())) {
          Log.d(TAG, "Ignoring " + doc.getInitials() + " because already installed");
          iter.remove();
        } else if (doc.isQuestionable()) {
          Log.d(TAG, "Ignoring " + doc.getInitials() + " because it is questionable");
          iter.remove();
        } else if (doc.getInitials().equalsIgnoreCase("westminster")) {
          Log.d(
              TAG,
              "Ignoring "
                  + doc.getInitials()
                  + " because some sections are too large for a mobile phone e.g. Q91-150");
          iter.remove();
        } else if (doc.getInitials().equalsIgnoreCase("passion")) {
          Log.d(TAG, "Ignoring " + doc.getInitials());
          iter.remove();
        } else if (doc.getInitials().equals("WebstersDict")) {
          Log.d(
              TAG,
              "Ignoring "
                  + doc.getInitials()
                  + " because it is too big and crashes dictionary code");
          iter.remove();
        }
      }

      // get fonts.properties at the same time as repo list, or if not yet downloaded
      // the download happens in another thread
      fontControl.checkFontPropertiesFile(refresh);

    } catch (Exception e) {
      Log.e(TAG, "Error downloading document list", e);
      availableDocs = new ArrayList<Book>();
    }
    return availableDocs;
  }