private void saveState() {
   SharedPreferences.Editor editor =
       mTarget.getContext().getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit();
   editor
       .putInt("Chapter", mChapter)
       .putInt("Word", mWordArray.length - mWordQueue.size())
       .putString("Title", mBook.getTitle())
       .putInt("Wpm", mWPM)
       .apply();
 }
 private void restoreState() {
   SharedPreferences prefs =
       mTarget.getContext().getSharedPreferences(PREFS, Context.MODE_PRIVATE);
   if (mBook.getTitle().compareTo(prefs.getString("Title", "<>?l")) == 0) {
     mChapter = prefs.getInt("Chapter", 0);
     setText(loadCleanStringFromChapter(mChapter));
     int oldSize = prefs.getInt("Word", 0);
     setWpm(prefs.getInt("Wpm", 500));
     while (mWordQueue.size() > oldSize) {
       mWordQueue.remove();
     }
   } else {
     mChapter = 0;
     setText(loadCleanStringFromChapter(mChapter));
   }
 }
  @Override
  public void storeBook(String fileName, Book book, boolean updateLastRead, boolean copyFile)
      throws IOException {

    File bookFile = new File(fileName);

    boolean hasBook = hasBook(bookFile.getName());

    if (hasBook && !updateLastRead) {
      return;
    } else if (hasBook) {
      helper.updateLastRead(bookFile.getName(), -1);
      return;
    }

    Metadata metaData = book.getMetadata();

    String authorFirstName = "Unknown author";
    String authorLastName = "";

    if (metaData.getAuthors().size() > 0) {
      authorFirstName = metaData.getAuthors().get(0).getFirstname();
      authorLastName = metaData.getAuthors().get(0).getLastname();
    }

    byte[] thumbNail = null;

    try {
      if (book.getCoverImage() != null && book.getCoverImage().getSize() < MAX_COVER_SIZE) {
        thumbNail = resizeImage(book.getCoverImage().getData());
        book.getCoverImage().close();
      }
    } catch (IOException io) {

    } catch (OutOfMemoryError err) {
      // If the image resource is too big, just import without a cover.
    }

    String description = "";

    if (!metaData.getDescriptions().isEmpty()) {
      description = metaData.getDescriptions().get(0);
    }

    String title = book.getTitle();

    if (title.trim().length() == 0) {
      title = fileName.substring(fileName.lastIndexOf('/') + 1);
    }

    if (copyFile) {
      bookFile = copyToLibrary(fileName, authorLastName + ", " + authorFirstName, title);
    }

    this.helper.storeNewBook(
        bookFile.getAbsolutePath(),
        authorFirstName,
        authorLastName,
        title,
        description,
        thumbNail,
        updateLastRead);
  }