Ejemplo n.º 1
0
  public void runCancelAction(int index) {
    if (index < 0 || index >= myCancelActionsList.size()) {
      return;
    }

    final CancelActionDescription description = myCancelActionsList.get(index);
    switch (description.Type) {
      case library:
        runAction(ActionCode.SHOW_LIBRARY);
        break;
      case networkLibrary:
        runAction(ActionCode.SHOW_NETWORK_LIBRARY);
        break;
      case previousBook:
        openBook(Library.Instance().getPreviousBook(), null, null);
        break;
      case returnTo:
        {
          final Bookmark b = ((BookmarkDescription) description).Bookmark;
          b.delete();
          gotoBookmark(b);
          break;
        }
      case close:
        closeWindow();
        break;
    }
  }
  protected Collection<FileInfo> loadFileInfos(ZLFile file) {
    final LinkedList<ZLFile> fileStack = new LinkedList<ZLFile>();
    for (; file != null; file = file.getParent()) {
      fileStack.addFirst(file);
    }

    final ArrayList<FileInfo> infos = new ArrayList<FileInfo>(fileStack.size());
    final String[] parameters = {null};
    FileInfo current = null;
    for (ZLFile f : fileStack) {
      parameters[0] = f.getLongName();
      final Cursor cursor =
          myDatabase.rawQuery(
              (current == null)
                  ? "SELECT file_id,size FROM Files WHERE name = ?"
                  : "SELECT file_id,size FROM Files WHERE parent_id = "
                      + current.Id
                      + " AND name = ?",
              parameters);
      if (cursor.moveToNext()) {
        current = createFileInfo(cursor.getLong(0), parameters[0], current);
        if (!cursor.isNull(1)) {
          current.FileSize = cursor.getLong(1);
        }
        infos.add(current);
        cursor.close();
      } else {
        cursor.close();
        break;
      }
    }

    return infos;
  }
  private void updateTables7() {
    final ArrayList<Long> seriesIDs = new ArrayList<Long>();
    Cursor cursor = myDatabase.rawQuery("SELECT series_id,name FROM Series", null);
    while (cursor.moveToNext()) {
      if (cursor.getString(1).length() > 200) {
        seriesIDs.add(cursor.getLong(0));
      }
    }
    cursor.close();
    if (seriesIDs.isEmpty()) {
      return;
    }

    final ArrayList<Long> bookIDs = new ArrayList<Long>();
    for (Long id : seriesIDs) {
      cursor = myDatabase.rawQuery("SELECT book_id FROM BookSeries WHERE series_id=" + id, null);
      while (cursor.moveToNext()) {
        bookIDs.add(cursor.getLong(0));
      }
      cursor.close();
      myDatabase.execSQL("DELETE FROM BookSeries WHERE series_id=" + id);
      myDatabase.execSQL("DELETE FROM Series WHERE series_id=" + id);
    }

    for (Long id : bookIDs) {
      myDatabase.execSQL("DELETE FROM Books WHERE book_id=" + id);
      myDatabase.execSQL("DELETE FROM BookAuthor WHERE book_id=" + id);
      myDatabase.execSQL("DELETE FROM BookTag WHERE book_id=" + id);
    }
  }
  private void updateTables4() {
    final FileInfoSet fileInfos = new FileInfoSet();
    final Cursor cursor = myDatabase.rawQuery("SELECT file_name FROM Books", null);
    while (cursor.moveToNext()) {
      fileInfos.check(ZLFile.createFileByPath(cursor.getString(0)).getPhysicalFile(), false);
    }
    cursor.close();
    fileInfos.save();

    myDatabase.execSQL(
        "CREATE TABLE RecentBooks("
            + "book_index INTEGER PRIMARY KEY,"
            + "book_id INTEGER REFERENCES Books(book_id))");
    final ArrayList<Long> ids = new ArrayList<Long>();

    final SQLiteStatement statement =
        myDatabase.compileStatement("SELECT book_id FROM Books WHERE file_name = ?");

    for (int i = 0; i < 20; ++i) {
      final ZLStringOption option = new ZLStringOption("LastOpenedBooks", "Book" + i, "");
      final String fileName = option.getValue();
      option.setValue("");
      try {
        statement.bindString(1, fileName);
        final long bookId = statement.simpleQueryForLong();
        if (bookId != -1) {
          ids.add(bookId);
        }
      } catch (SQLException e) {
      }
    }
    saveRecentBookIds(ids);
  }
 protected List<Tag> loadTags(long bookId) {
   final Cursor cursor =
       myDatabase.rawQuery(
           "SELECT Tags.tag_id FROM BookTag INNER JOIN Tags ON Tags.tag_id = BookTag.tag_id WHERE BookTag.book_id = ?",
           new String[] {"" + bookId});
   if (!cursor.moveToNext()) {
     cursor.close();
     return null;
   }
   ArrayList<Tag> list = new ArrayList<Tag>();
   do {
     list.add(getTagById(cursor.getLong(0)));
   } while (cursor.moveToNext());
   cursor.close();
   return list;
 }
 protected List<Author> loadAuthors(long bookId) {
   final Cursor cursor =
       myDatabase.rawQuery(
           "SELECT Authors.name,Authors.sort_key FROM BookAuthor INNER JOIN Authors ON Authors.author_id = BookAuthor.author_id WHERE BookAuthor.book_id = ?",
           new String[] {"" + bookId});
   if (!cursor.moveToNext()) {
     cursor.close();
     return null;
   }
   final ArrayList<Author> list = new ArrayList<Author>();
   do {
     list.add(new Author(cursor.getString(0), cursor.getString(1)));
   } while (cursor.moveToNext());
   cursor.close();
   return list;
 }
Ejemplo n.º 7
0
 public List<CancelActionDescription> getCancelActionsList() {
   myCancelActionsList.clear();
   if (ShowLibraryInCancelMenuOption.getValue()) {
     myCancelActionsList.add(new CancelActionDescription(CancelActionType.library, null));
   }
   if (ShowNetworkLibraryInCancelMenuOption.getValue()) {
     myCancelActionsList.add(new CancelActionDescription(CancelActionType.networkLibrary, null));
   }
   if (ShowPreviousBookInCancelMenuOption.getValue()) {
     final Book previousBook = Library.Instance().getPreviousBook();
     if (previousBook != null) {
       myCancelActionsList.add(
           new CancelActionDescription(CancelActionType.previousBook, previousBook.getTitle()));
     }
   }
   if (ShowPositionsInCancelMenuOption.getValue()) {
     if (Model != null && Model.Book != null) {
       for (Bookmark bookmark : Library.Instance().invisibleBookmarks(Model.Book)) {
         myCancelActionsList.add(new BookmarkDescription(bookmark));
       }
     }
   }
   myCancelActionsList.add(new CancelActionDescription(CancelActionType.close, null));
   return myCancelActionsList;
 }
 protected Collection<FileInfo> loadFileInfos(long fileId) {
   final ArrayList<FileInfo> infos = new ArrayList<FileInfo>();
   while (fileId != -1) {
     final Cursor cursor =
         myDatabase.rawQuery(
             "SELECT name,size,parent_id FROM Files WHERE file_id = " + fileId, null);
     if (cursor.moveToNext()) {
       FileInfo info = createFileInfo(fileId, cursor.getString(0), null);
       if (!cursor.isNull(1)) {
         info.FileSize = cursor.getLong(1);
       }
       infos.add(0, info);
       fileId = cursor.isNull(2) ? -1 : cursor.getLong(2);
     } else {
       fileId = -1;
     }
     cursor.close();
   }
   for (int i = 1; i < infos.size(); ++i) {
     final FileInfo oldInfo = infos.get(i);
     final FileInfo newInfo = createFileInfo(oldInfo.Id, oldInfo.Name, infos.get(i - 1));
     newInfo.FileSize = oldInfo.FileSize;
     infos.set(i, newInfo);
   }
   return infos;
 }