1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

bookmarks highlighting

This commit is contained in:
Nikolay Pultsin 2013-04-30 22:57:22 +02:00
parent fd144412c0
commit 3522a11302
4 changed files with 51 additions and 39 deletions

View file

@ -840,7 +840,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
.append(" bm.bookmark_id,bm.book_id,b.title,bm.bookmark_text,")
.append("bm.creation_time,bm.modification_time,bm.access_time,bm.access_counter,")
.append("bm.model_id,bm.paragraph,bm.word,bm.char,")
.append("bm.end_paragraph,bm.end_word,bm.end_character,")
.append("bm.end_paragraph,bm.end_word,bm.end_character")
.append(" FROM Bookmarks AS bm INNER JOIN Books AS b ON b.book_id = bm.book_id")
.append(" WHERE");
if (query.Book != null) {
@ -883,14 +883,14 @@ final class SQLiteBooksDatabase extends BooksDatabase {
if (bookmark.getId() == -1) {
if (myInsertBookmarkStatement == null) {
myInsertBookmarkStatement = myDatabase.compileStatement(
"INSERT OR IGNORE INTO Bookmarks (book_id,bookmark_text,creation_time,modification_time,access_time,access_counter,model_id,paragraph,word,char,visible) VALUES (?,?,?,?,?,?,?,?,?,?,?)"
"INSERT OR IGNORE INTO Bookmarks (book_id,bookmark_text,creation_time,modification_time,access_time,access_counter,model_id,paragraph,word,char,end_paragraph,end_word,end_character,visible) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
}
statement = myInsertBookmarkStatement;
} else {
if (myUpdateBookmarkStatement == null) {
myUpdateBookmarkStatement = myDatabase.compileStatement(
"UPDATE Bookmarks SET book_id = ?, bookmark_text = ?, creation_time =?, modification_time = ?,access_time = ?, access_counter = ?, model_id = ?, paragraph = ?, word = ?, char = ?, visible = ? WHERE bookmark_id = ?"
"UPDATE Bookmarks SET book_id = ?, bookmark_text = ?, creation_time =?, modification_time = ?,access_time = ?, access_counter = ?, model_id = ?, paragraph = ?, word = ?, char = ?, end_paragraph = ?, end_word = ?, end_character = ?, visible = ? WHERE bookmark_id = ?"
);
}
statement = myUpdateBookmarkStatement;
@ -906,7 +906,17 @@ final class SQLiteBooksDatabase extends BooksDatabase {
statement.bindLong(8, bookmark.ParagraphIndex);
statement.bindLong(9, bookmark.ElementIndex);
statement.bindLong(10, bookmark.CharIndex);
statement.bindLong(11, bookmark.IsVisible ? 1 : 0);
final ZLTextPosition end = bookmark.getEnd();
if (end != null) {
statement.bindLong(11, end.getParagraphIndex());
statement.bindLong(12, end.getElementIndex());
statement.bindLong(13, end.getCharIndex());
} else {
statement.bindLong(11, bookmark.getLength());
statement.bindNull(12);
statement.bindNull(13);
}
statement.bindLong(14, bookmark.IsVisible ? 1 : 0);
if (statement == myInsertBookmarkStatement) {
return statement.executeInsert();

View file

@ -272,6 +272,29 @@ public final class FBReaderApp extends ZLApplication {
Collection.saveBook(book, false);
ZLTextHyphenator.Instance().load(book.getLanguage());
BookTextView.setModel(Model.getTextModel());
for (BookmarkQuery query = new BookmarkQuery(book, 20); ; query = query.next()) {
final List<Bookmark> bookmarks = Collection.bookmarks(query);
if (bookmarks.isEmpty()) {
break;
}
for (Bookmark b : bookmarks) {
if (b.ModelId == null) {
ZLTextPosition end = b.getEnd();
if (end == null) {
// TODO: compute end and save bookmark
continue;
}
BookTextView.addHighlighting(
new ZLTextSimpleHighlighting(BookTextView, b, end) {
@Override
public ZLColor getBackgroundColor() {
return new ZLColor(127, 127, 127);
}
}
);
}
}
}
BookTextView.gotoPosition(Collection.getStoredPosition(book.getId()));
if (bookmark == null) {
setView(BookTextView);

View file

@ -21,44 +21,13 @@ package org.geometerplus.zlibrary.text.view;
import org.geometerplus.zlibrary.core.util.ZLColor;
class ZLTextManualHighlighting extends ZLTextHighlighting {
private final ZLTextView myView;
private final ZLTextPosition myStartPosition;
private final ZLTextPosition myEndPosition;
class ZLTextManualHighlighting extends ZLTextSimpleHighlighting {
ZLTextManualHighlighting(ZLTextView view, ZLTextPosition start, ZLTextPosition end) {
myView = view;
myStartPosition = new ZLTextFixedPosition(start);
myEndPosition = new ZLTextFixedPosition(end);
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public ZLTextPosition getStartPosition() {
return myStartPosition;
}
@Override
public ZLTextPosition getEndPosition() {
return myEndPosition;
}
@Override
public ZLTextElementArea getStartArea(ZLTextPage page) {
return page.TextElementMap.getFirstAfter(myStartPosition);
}
@Override
public ZLTextElementArea getEndArea(ZLTextPage page) {
return page.TextElementMap.getLastBefore(myEndPosition);
super(view, start, end);
}
@Override
public ZLColor getBackgroundColor() {
return myView.getHighlightingBackgroundColor();
return View.getHighlightingBackgroundColor();
}
}

View file

@ -273,13 +273,23 @@ public abstract class ZLTextView extends ZLTextViewBase {
public void highlight(ZLTextPosition start, ZLTextPosition end) {
removeManualHighlightings();
final ZLTextHighlighting h = new ZLTextManualHighlighting(this, start, end);
addHighlighting(new ZLTextManualHighlighting(this, start, end));
}
public final void addHighlighting(ZLTextHighlighting h) {
myHighlightingsByStart.add(h);
myHighlightingsByEnd.add(h);
Application.getViewWidget().reset();
Application.getViewWidget().repaint();
}
public final void addHighlightings(Collection<ZLTextHighlighting> hilites) {
myHighlightingsByStart.addAll(hilites);
myHighlightingsByEnd.addAll(hilites);
Application.getViewWidget().reset();
Application.getViewWidget().repaint();
}
public void clearHighlighting() {
if (removeManualHighlightings()) {
Application.getViewWidget().reset();