Exemple #1
0
  public boolean save() {
    if (myIsSaved) {
      return false;
    }
    final BooksDatabase database = BooksDatabase.Instance();
    database.executeAsATransaction(
        new Runnable() {
          public void run() {
            if (myId >= 0) {
              final FileInfoSet fileInfos = new FileInfoSet(File);
              database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle);
            } else {
              myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);
              storeAllVisitedHyperinks();
            }

            long index = 0;
            database.deleteAllBookAuthors(myId);
            for (Author author : authors()) {
              database.saveBookAuthorInfo(myId, index++, author);
            }
            database.deleteAllBookTags(myId);
            for (Tag tag : tags()) {
              database.saveBookTagInfo(myId, tag);
            }
            database.saveBookSeriesInfo(myId, mySeriesInfo);
          }
        });

    myIsSaved = true;
    return true;
  }
Exemple #2
0
  public static Book getByFile(ZLFile bookFile) {
    if (bookFile == null) {
      return null;
    }

    final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
    if (physicalFile != null && !physicalFile.exists()) {
      return null;
    }

    final FileInfoSet fileInfos = new FileInfoSet(bookFile);

    Book book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile);
    if (book != null) {
      book.loadLists();
    }

    if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
      return book;
    }
    fileInfos.save();

    if (book == null) {
      book = new Book(bookFile);
    }
    if (book.readMetaInfo()) {
      book.save();
      return book;
    }
    return null;
  }
Exemple #3
0
 private void storeAllVisitedHyperinks() {
   if (myId != -1 && myVisitedHyperlinks != null) {
     for (String linkId : myVisitedHyperlinks) {
       BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
     }
   }
 }
Exemple #4
0
 private void loadLists() {
   final BooksDatabase database = BooksDatabase.Instance();
   myAuthors = database.loadAuthors(myId);
   myTags = database.loadTags(myId);
   mySeriesInfo = database.loadSeriesInfo(myId);
   myIsSaved = true;
 }
Exemple #5
0
 private void initHyperlinkSet() {
   if (myVisitedHyperlinks == null) {
     myVisitedHyperlinks = new TreeSet<String>();
     if (myId != -1) {
       myVisitedHyperlinks.addAll(BooksDatabase.Instance().loadVisitedHyperlinks(myId));
     }
   }
 }
Exemple #6
0
 public void reloadInfoFromDatabase() {
   final BooksDatabase database = BooksDatabase.Instance();
   database.reloadBook(this);
   myAuthors = database.loadAuthors(myId);
   myTags = database.loadTags(myId);
   mySeriesInfo = database.loadSeriesInfo(myId);
   myIsSaved = true;
 }
Exemple #7
0
 public void markHyperlinkAsVisited(String linkId) {
   initHyperlinkSet();
   if (!myVisitedHyperlinks.contains(linkId)) {
     myVisitedHyperlinks.add(linkId);
     if (myId != -1) {
       BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
     }
   }
 }
Exemple #8
0
  public static Book getById(long bookId) {
    final Book book = BooksDatabase.Instance().loadBook(bookId);
    if (book == null) {
      return null;
    }
    book.loadLists();

    final ZLFile bookFile = book.File;
    final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
    if (physicalFile == null) {
      return book;
    }
    if (!physicalFile.exists()) {
      return null;
    }

    FileInfoSet fileInfos = new FileInfoSet(physicalFile);
    if (fileInfos.check(physicalFile, physicalFile != bookFile)) {
      return book;
    }
    fileInfos.save();

    return book.readMetaInfo() ? book : null;
  }
Exemple #9
0
 public void insertIntoBookList() {
   if (myId != -1) {
     BooksDatabase.Instance().insertIntoBookList(myId);
   }
 }
Exemple #10
0
 public void storePosition(ZLTextPosition position) {
   if (myId != -1) {
     BooksDatabase.Instance().storePosition(myId, position);
   }
 }
Exemple #11
0
 public ZLTextPosition getStoredPosition() {
   return BooksDatabase.Instance().getStoredPosition(myId);
 }