示例#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;
  }
示例#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;
  }
示例#3
0
 private void storeAllVisitedHyperinks() {
   if (myId != -1 && myVisitedHyperlinks != null) {
     for (String linkId : myVisitedHyperlinks) {
       BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
     }
   }
 }
示例#4
0
 private void loadLists() {
   final BooksDatabase database = BooksDatabase.Instance();
   myAuthors = database.loadAuthors(myId);
   myTags = database.loadTags(myId);
   mySeriesInfo = database.loadSeriesInfo(myId);
   myIsSaved = true;
 }
示例#5
0
 private void initHyperlinkSet() {
   if (myVisitedHyperlinks == null) {
     myVisitedHyperlinks = new TreeSet<String>();
     if (myId != -1) {
       myVisitedHyperlinks.addAll(BooksDatabase.Instance().loadVisitedHyperlinks(myId));
     }
   }
 }
示例#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;
 }
示例#7
0
 public void markHyperlinkAsVisited(String linkId) {
   initHyperlinkSet();
   if (!myVisitedHyperlinks.contains(linkId)) {
     myVisitedHyperlinks.add(linkId);
     if (myId != -1) {
       BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
     }
   }
 }
示例#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;
  }
示例#9
0
 public void insertIntoBookList() {
   if (myId != -1) {
     BooksDatabase.Instance().insertIntoBookList(myId);
   }
 }
示例#10
0
 public void storePosition(ZLTextPosition position) {
   if (myId != -1) {
     BooksDatabase.Instance().storePosition(myId, position);
   }
 }
示例#11
0
 public ZLTextPosition getStoredPosition() {
   return BooksDatabase.Instance().getStoredPosition(myId);
 }