1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

access rights + some bookmark-related methods moved to BookCollection

This commit is contained in:
Nikolay Pultsin 2013-02-10 00:00:35 +04:00
parent d8bb1ad585
commit 99b44927b3
5 changed files with 39 additions and 49 deletions

View file

@ -77,7 +77,7 @@ public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuIte
final TabHost host = getTabHost(); final TabHost host = getTabHost();
LayoutInflater.from(this).inflate(R.layout.bookmarks, host.getTabContentView(), true); LayoutInflater.from(this).inflate(R.layout.bookmarks, host.getTabContentView(), true);
myAllBooksBookmarks = Library.Instance().allBookmarks(); myAllBooksBookmarks = Library.Instance().Collection.allBookmarks();
Collections.sort(myAllBooksBookmarks, new Bookmark.ByTimeComparator()); Collections.sort(myAllBooksBookmarks, new Bookmark.ByTimeComparator());
final Book book = SerializerUtil.deserializeBook(getIntent().getStringExtra(FBReader.BOOK_KEY)); final Book book = SerializerUtil.deserializeBook(getIntent().getStringExtra(FBReader.BOOK_KEY));

View file

@ -294,7 +294,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private SQLiteStatement myUpdateBookInfoStatement; private SQLiteStatement myUpdateBookInfoStatement;
@Override @Override
public /*protected*/ void updateBookInfo(long bookId, long fileId, String encoding, String language, String title) { protected void updateBookInfo(long bookId, long fileId, String encoding, String language, String title) {
if (myUpdateBookInfoStatement == null) { if (myUpdateBookInfoStatement == null) {
myUpdateBookInfoStatement = myDatabase.compileStatement( myUpdateBookInfoStatement = myDatabase.compileStatement(
"UPDATE OR IGNORE Books SET file_id = ?, encoding = ?, language = ?, title = ? WHERE book_id = ?" "UPDATE OR IGNORE Books SET file_id = ?, encoding = ?, language = ?, title = ? WHERE book_id = ?"
@ -310,7 +310,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private SQLiteStatement myInsertBookInfoStatement; private SQLiteStatement myInsertBookInfoStatement;
@Override @Override
public /*protected*/ long insertBookInfo(ZLFile file, String encoding, String language, String title) { protected long insertBookInfo(ZLFile file, String encoding, String language, String title) {
if (myInsertBookInfoStatement == null) { if (myInsertBookInfoStatement == null) {
myInsertBookInfoStatement = myDatabase.compileStatement( myInsertBookInfoStatement = myDatabase.compileStatement(
"INSERT OR IGNORE INTO Books (encoding,language,title,file_id) VALUES (?,?,?,?)" "INSERT OR IGNORE INTO Books (encoding,language,title,file_id) VALUES (?,?,?,?)"
@ -540,7 +540,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
private SQLiteStatement myRemoveFileInfoStatement; private SQLiteStatement myRemoveFileInfoStatement;
public /*protected*/ void removeFileInfo(long fileId) { protected void removeFileInfo(long fileId) {
if (fileId == -1) { if (fileId == -1) {
return; return;
} }
@ -555,7 +555,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private SQLiteStatement myInsertFileInfoStatement; private SQLiteStatement myInsertFileInfoStatement;
private SQLiteStatement myUpdateFileInfoStatement; private SQLiteStatement myUpdateFileInfoStatement;
public /*protected*/ void saveFileInfo(FileInfo fileInfo) { protected void saveFileInfo(FileInfo fileInfo) {
final long id = fileInfo.Id; final long id = fileInfo.Id;
SQLiteStatement statement; SQLiteStatement statement;
if (id == -1) { if (id == -1) {
@ -594,7 +594,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
} }
public /*protected*/ Collection<FileInfo> loadFileInfos() { protected Collection<FileInfo> loadFileInfos() {
Cursor cursor = myDatabase.rawQuery( Cursor cursor = myDatabase.rawQuery(
"SELECT file_id,name,parent_id,size FROM Files", null "SELECT file_id,name,parent_id,size FROM Files", null
); );
@ -614,7 +614,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
return infosById.values(); return infosById.values();
} }
public /*protected*/ Collection<FileInfo> loadFileInfos(ZLFile file) { protected Collection<FileInfo> loadFileInfos(ZLFile file) {
final LinkedList<ZLFile> fileStack = new LinkedList<ZLFile>(); final LinkedList<ZLFile> fileStack = new LinkedList<ZLFile>();
for (; file != null; file = file.getParent()) { for (; file != null; file = file.getParent()) {
fileStack.addFirst(file); fileStack.addFirst(file);
@ -647,7 +647,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
return infos; return infos;
} }
public /*protected*/ Collection<FileInfo> loadFileInfos(long fileId) { protected Collection<FileInfo> loadFileInfos(long fileId) {
final ArrayList<FileInfo> infos = new ArrayList<FileInfo>(); final ArrayList<FileInfo> infos = new ArrayList<FileInfo>();
while (fileId != -1) { while (fileId != -1) {
final Cursor cursor = myDatabase.rawQuery( final Cursor cursor = myDatabase.rawQuery(
@ -675,7 +675,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
private SQLiteStatement mySaveRecentBookStatement; private SQLiteStatement mySaveRecentBookStatement;
public /*protected*/ void saveRecentBookIds(final List<Long> ids) { protected void saveRecentBookIds(final List<Long> ids) {
if (mySaveRecentBookStatement == null) { if (mySaveRecentBookStatement == null) {
mySaveRecentBookStatement = myDatabase.compileStatement( mySaveRecentBookStatement = myDatabase.compileStatement(
"INSERT OR IGNORE INTO RecentBooks (book_id) VALUES (?)" "INSERT OR IGNORE INTO RecentBooks (book_id) VALUES (?)"
@ -692,7 +692,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
}); });
} }
public /*protected*/ List<Long> loadRecentBookIds() { protected List<Long> loadRecentBookIds() {
final Cursor cursor = myDatabase.rawQuery( final Cursor cursor = myDatabase.rawQuery(
"SELECT book_id FROM RecentBooks ORDER BY book_index", null "SELECT book_id FROM RecentBooks ORDER BY book_index", null
); );
@ -758,7 +758,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
@Override @Override
public /*protected*/ List<Bookmark> loadBookmarks(long bookId, boolean visible) { protected List<Bookmark> loadBookmarks(long bookId, boolean visible) {
LinkedList<Bookmark> list = new LinkedList<Bookmark>(); LinkedList<Bookmark> list = new LinkedList<Bookmark>();
Cursor cursor = myDatabase.rawQuery( Cursor cursor = myDatabase.rawQuery(
"SELECT Bookmarks.bookmark_id,Bookmarks.book_id,Books.title,Bookmarks.bookmark_text,Bookmarks.creation_time,Bookmarks.modification_time,Bookmarks.access_time,Bookmarks.access_counter,Bookmarks.model_id,Bookmarks.paragraph,Bookmarks.word,Bookmarks.char FROM Bookmarks INNER JOIN Books ON Books.book_id = Bookmarks.book_id WHERE Bookmarks.book_id = ? AND Bookmarks.visible = ?", new String[] { "" + bookId, visible ? "1" : "0" } "SELECT Bookmarks.bookmark_id,Bookmarks.book_id,Books.title,Bookmarks.bookmark_text,Bookmarks.creation_time,Bookmarks.modification_time,Bookmarks.access_time,Bookmarks.access_counter,Bookmarks.model_id,Bookmarks.paragraph,Bookmarks.word,Bookmarks.char FROM Bookmarks INNER JOIN Books ON Books.book_id = Bookmarks.book_id WHERE Bookmarks.book_id = ? AND Bookmarks.visible = ?", new String[] { "" + bookId, visible ? "1" : "0" }
@ -785,7 +785,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
@Override @Override
public /*protected*/ List<Bookmark> loadAllVisibleBookmarks() { protected List<Bookmark> loadAllVisibleBookmarks() {
LinkedList<Bookmark> list = new LinkedList<Bookmark>(); LinkedList<Bookmark> list = new LinkedList<Bookmark>();
myDatabase.execSQL("DELETE FROM Bookmarks WHERE book_id = -1"); myDatabase.execSQL("DELETE FROM Bookmarks WHERE book_id = -1");
Cursor cursor = myDatabase.rawQuery( Cursor cursor = myDatabase.rawQuery(
@ -815,7 +815,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private SQLiteStatement myInsertBookmarkStatement; private SQLiteStatement myInsertBookmarkStatement;
private SQLiteStatement myUpdateBookmarkStatement; private SQLiteStatement myUpdateBookmarkStatement;
@Override @Override
public /*protected*/ long saveBookmark(Bookmark bookmark) { protected long saveBookmark(Bookmark bookmark) {
SQLiteStatement statement; SQLiteStatement statement;
if (bookmark.getId() == -1) { if (bookmark.getId() == -1) {
if (myInsertBookmarkStatement == null) { if (myInsertBookmarkStatement == null) {
@ -857,7 +857,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private SQLiteStatement myDeleteBookmarkStatement; private SQLiteStatement myDeleteBookmarkStatement;
@Override @Override
public /*protected*/ void deleteBookmark(Bookmark bookmark) { protected void deleteBookmark(Bookmark bookmark) {
if (myDeleteBookmarkStatement == null) { if (myDeleteBookmarkStatement == null) {
myDeleteBookmarkStatement = myDatabase.compileStatement( myDeleteBookmarkStatement = myDatabase.compileStatement(
"DELETE FROM Bookmarks WHERE bookmark_id = ?" "DELETE FROM Bookmarks WHERE bookmark_id = ?"
@ -867,7 +867,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
myDeleteBookmarkStatement.execute(); myDeleteBookmarkStatement.execute();
} }
public /*protected*/ ZLTextPosition getStoredPosition(long bookId) { protected ZLTextPosition getStoredPosition(long bookId) {
ZLTextPosition position = null; ZLTextPosition position = null;
Cursor cursor = myDatabase.rawQuery( Cursor cursor = myDatabase.rawQuery(
"SELECT paragraph,word,char FROM BookState WHERE book_id = " + bookId, null "SELECT paragraph,word,char FROM BookState WHERE book_id = " + bookId, null
@ -884,7 +884,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
private SQLiteStatement myStorePositionStatement; private SQLiteStatement myStorePositionStatement;
public /*protected*/ void storePosition(long bookId, ZLTextPosition position) { protected void storePosition(long bookId, ZLTextPosition position) {
if (myStorePositionStatement == null) { if (myStorePositionStatement == null) {
myStorePositionStatement = myDatabase.compileStatement( myStorePositionStatement = myDatabase.compileStatement(
"INSERT OR REPLACE INTO BookState (book_id,paragraph,word,char) VALUES (?,?,?,?)" "INSERT OR REPLACE INTO BookState (book_id,paragraph,word,char) VALUES (?,?,?,?)"
@ -910,7 +910,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
} }
private SQLiteStatement myStoreVisitedHyperlinksStatement; private SQLiteStatement myStoreVisitedHyperlinksStatement;
public /*protected*/ void addVisitedHyperlink(long bookId, String hyperlinkId) { protected void addVisitedHyperlink(long bookId, String hyperlinkId) {
if (myStoreVisitedHyperlinksStatement == null) { if (myStoreVisitedHyperlinksStatement == null) {
myStoreVisitedHyperlinksStatement = myDatabase.compileStatement( myStoreVisitedHyperlinksStatement = myDatabase.compileStatement(
"INSERT OR IGNORE INTO VisitedHyperlinks(book_id,hyperlink_id) VALUES (?,?)" "INSERT OR IGNORE INTO VisitedHyperlinks(book_id,hyperlink_id) VALUES (?,?)"
@ -922,7 +922,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
myStoreVisitedHyperlinksStatement.execute(); myStoreVisitedHyperlinksStatement.execute();
} }
public /*protected*/ Collection<String> loadVisitedHyperlinks(long bookId) { protected Collection<String> loadVisitedHyperlinks(long bookId) {
final TreeSet<String> links = new TreeSet<String>(); final TreeSet<String> links = new TreeSet<String>();
final Cursor cursor = myDatabase.rawQuery("SELECT hyperlink_id FROM VisitedHyperlinks WHERE book_id = ?", new String[] { "" + bookId }); final Cursor cursor = myDatabase.rawQuery("SELECT hyperlink_id FROM VisitedHyperlinks WHERE book_id = ?", new String[] { "" + bookId });
while (cursor.moveToNext()) { while (cursor.moveToNext()) {

View file

@ -67,8 +67,8 @@ public abstract class BooksDatabase {
protected abstract List<Tag> listTags(long bookId); protected abstract List<Tag> listTags(long bookId);
protected abstract SeriesInfo getSeriesInfo(long bookId); protected abstract SeriesInfo getSeriesInfo(long bookId);
public /*protected*/ abstract void updateBookInfo(long bookId, long fileId, String encoding, String language, String title); protected abstract void updateBookInfo(long bookId, long fileId, String encoding, String language, String title);
public /*protected*/ abstract long insertBookInfo(ZLFile file, String encoding, String language, String title); protected abstract long insertBookInfo(ZLFile file, String encoding, String language, String title);
protected abstract void deleteAllBookAuthors(long bookId); protected abstract void deleteAllBookAuthors(long bookId);
protected abstract void saveBookAuthorInfo(long bookId, long index, Author author); protected abstract void saveBookAuthorInfo(long bookId, long index, Author author);
protected abstract void deleteAllBookTags(long bookId); protected abstract void deleteAllBookTags(long bookId);
@ -79,14 +79,14 @@ public abstract class BooksDatabase {
return new FileInfo(name, parent, id); return new FileInfo(name, parent, id);
} }
public /*protected*/ abstract Collection<FileInfo> loadFileInfos(); protected abstract Collection<FileInfo> loadFileInfos();
public /*protected*/ abstract Collection<FileInfo> loadFileInfos(ZLFile file); protected abstract Collection<FileInfo> loadFileInfos(ZLFile file);
public /*protected*/ abstract Collection<FileInfo> loadFileInfos(long fileId); protected abstract Collection<FileInfo> loadFileInfos(long fileId);
public /*protected*/ abstract void removeFileInfo(long fileId); protected abstract void removeFileInfo(long fileId);
public /*protected*/ abstract void saveFileInfo(FileInfo fileInfo); protected abstract void saveFileInfo(FileInfo fileInfo);
public /*protected*/ abstract List<Long> loadRecentBookIds(); protected abstract List<Long> loadRecentBookIds();
public /*protected*/ abstract void saveRecentBookIds(final List<Long> ids); protected abstract void saveRecentBookIds(final List<Long> ids);
protected abstract List<Long> loadFavoriteIds(); protected abstract List<Long> loadFavoriteIds();
protected abstract boolean hasFavorites(); protected abstract boolean hasFavorites();
@ -98,14 +98,14 @@ public abstract class BooksDatabase {
return new Bookmark(id, bookId, bookTitle, text, creationDate, modificationDate, accessDate, accessCounter, modelId, paragraphIndex, wordIndex, charIndex, isVisible); return new Bookmark(id, bookId, bookTitle, text, creationDate, modificationDate, accessDate, accessCounter, modelId, paragraphIndex, wordIndex, charIndex, isVisible);
} }
public /*protected*/ abstract List<Bookmark> loadBookmarks(long bookId, boolean isVisible); protected abstract List<Bookmark> loadBookmarks(long bookId, boolean isVisible);
public /*protected*/ abstract List<Bookmark> loadAllVisibleBookmarks(); protected abstract List<Bookmark> loadAllVisibleBookmarks();
public /*protected*/ abstract long saveBookmark(Bookmark bookmark); protected abstract long saveBookmark(Bookmark bookmark);
public /*protected*/ abstract void deleteBookmark(Bookmark bookmark); protected abstract void deleteBookmark(Bookmark bookmark);
public /*protected*/ abstract ZLTextPosition getStoredPosition(long bookId); protected abstract ZLTextPosition getStoredPosition(long bookId);
public /*protected*/ abstract void storePosition(long bookId, ZLTextPosition position); protected abstract void storePosition(long bookId, ZLTextPosition position);
public /*protected*/ abstract Collection<String> loadVisitedHyperlinks(long bookId); protected abstract Collection<String> loadVisitedHyperlinks(long bookId);
public /*protected*/ abstract void addVisitedHyperlink(long bookId, String hyperlinkId); protected abstract void addVisitedHyperlink(long bookId, String hyperlinkId);
} }

View file

@ -304,7 +304,7 @@ public final class FBReaderApp extends ZLApplication {
return false; return false;
} }
final List<Bookmark> bookmarks = Library.Instance().invisibleBookmarks(Model.Book); final List<Bookmark> bookmarks = Library.Instance().Collection.invisibleBookmarks(Model.Book);
if (bookmarks.isEmpty()) { if (bookmarks.isEmpty()) {
return false; return false;
} }
@ -401,7 +401,7 @@ public final class FBReaderApp extends ZLApplication {
} }
if (ShowPositionsInCancelMenuOption.getValue()) { if (ShowPositionsInCancelMenuOption.getValue()) {
if (Model != null && Model.Book != null) { if (Model != null && Model.Book != null) {
for (Bookmark bookmark : Library.Instance().invisibleBookmarks(Model.Book)) { for (Bookmark bookmark : Library.Instance().Collection.invisibleBookmarks(Model.Book)) {
myCancelActionsList.add(new BookmarkDescription(bookmark)); myCancelActionsList.add(new BookmarkDescription(bookmark));
} }
} }
@ -443,13 +443,13 @@ public final class FBReaderApp extends ZLApplication {
private synchronized void updateInvisibleBookmarksList(Bookmark b) { private synchronized void updateInvisibleBookmarksList(Bookmark b) {
if (Model != null && Model.Book != null && b != null) { if (Model != null && Model.Book != null && b != null) {
for (Bookmark bm : Library.Instance().invisibleBookmarks(Model.Book)) { for (Bookmark bm : Library.Instance().Collection.invisibleBookmarks(Model.Book)) {
if (b.equals(bm)) { if (b.equals(bm)) {
bm.delete(); bm.delete();
} }
} }
b.save(); b.save();
final List<Bookmark> bookmarks = Library.Instance().invisibleBookmarks(Model.Book); final List<Bookmark> bookmarks = Library.Instance().Collection.invisibleBookmarks(Model.Book);
for (int i = 3; i < bookmarks.size(); ++i) { for (int i = 3; i < bookmarks.size(); ++i) {
bookmarks.get(i).delete(); bookmarks.get(i).delete();
} }

View file

@ -252,14 +252,4 @@ public final class Library {
myBooks.remove(book.File); myBooks.remove(book.File);
Collection.removeBook(book, (removeMode & REMOVE_FROM_DISK) != 0); Collection.removeBook(book, (removeMode & REMOVE_FROM_DISK) != 0);
} }
public List<Bookmark> allBookmarks() {
return BooksDatabase.Instance().loadAllVisibleBookmarks();
}
public List<Bookmark> invisibleBookmarks(Book book) {
final List<Bookmark> list = BooksDatabase.Instance().loadBookmarks(book.getId(), false);
Collections.sort(list, new Bookmark.ByTimeComparator());
return list;
}
} }