mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
bookmarks highlighting
This commit is contained in:
parent
fd144412c0
commit
3522a11302
4 changed files with 51 additions and 39 deletions
|
@ -840,7 +840,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
.append(" bm.bookmark_id,bm.book_id,b.title,bm.bookmark_text,")
|
.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.creation_time,bm.modification_time,bm.access_time,bm.access_counter,")
|
||||||
.append("bm.model_id,bm.paragraph,bm.word,bm.char,")
|
.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(" FROM Bookmarks AS bm INNER JOIN Books AS b ON b.book_id = bm.book_id")
|
||||||
.append(" WHERE");
|
.append(" WHERE");
|
||||||
if (query.Book != null) {
|
if (query.Book != null) {
|
||||||
|
@ -883,14 +883,14 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
if (bookmark.getId() == -1) {
|
if (bookmark.getId() == -1) {
|
||||||
if (myInsertBookmarkStatement == null) {
|
if (myInsertBookmarkStatement == null) {
|
||||||
myInsertBookmarkStatement = myDatabase.compileStatement(
|
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;
|
statement = myInsertBookmarkStatement;
|
||||||
} else {
|
} else {
|
||||||
if (myUpdateBookmarkStatement == null) {
|
if (myUpdateBookmarkStatement == null) {
|
||||||
myUpdateBookmarkStatement = myDatabase.compileStatement(
|
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;
|
statement = myUpdateBookmarkStatement;
|
||||||
|
@ -906,7 +906,17 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
statement.bindLong(8, bookmark.ParagraphIndex);
|
statement.bindLong(8, bookmark.ParagraphIndex);
|
||||||
statement.bindLong(9, bookmark.ElementIndex);
|
statement.bindLong(9, bookmark.ElementIndex);
|
||||||
statement.bindLong(10, bookmark.CharIndex);
|
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) {
|
if (statement == myInsertBookmarkStatement) {
|
||||||
return statement.executeInsert();
|
return statement.executeInsert();
|
||||||
|
|
|
@ -272,6 +272,29 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
Collection.saveBook(book, false);
|
Collection.saveBook(book, false);
|
||||||
ZLTextHyphenator.Instance().load(book.getLanguage());
|
ZLTextHyphenator.Instance().load(book.getLanguage());
|
||||||
BookTextView.setModel(Model.getTextModel());
|
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()));
|
BookTextView.gotoPosition(Collection.getStoredPosition(book.getId()));
|
||||||
if (bookmark == null) {
|
if (bookmark == null) {
|
||||||
setView(BookTextView);
|
setView(BookTextView);
|
||||||
|
|
|
@ -21,44 +21,13 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.ZLColor;
|
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||||
|
|
||||||
class ZLTextManualHighlighting extends ZLTextHighlighting {
|
class ZLTextManualHighlighting extends ZLTextSimpleHighlighting {
|
||||||
private final ZLTextView myView;
|
|
||||||
private final ZLTextPosition myStartPosition;
|
|
||||||
private final ZLTextPosition myEndPosition;
|
|
||||||
|
|
||||||
ZLTextManualHighlighting(ZLTextView view, ZLTextPosition start, ZLTextPosition end) {
|
ZLTextManualHighlighting(ZLTextView view, ZLTextPosition start, ZLTextPosition end) {
|
||||||
myView = view;
|
super(view, start, end);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLColor getBackgroundColor() {
|
public ZLColor getBackgroundColor() {
|
||||||
return myView.getHighlightingBackgroundColor();
|
return View.getHighlightingBackgroundColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,13 +273,23 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
|
|
||||||
public void highlight(ZLTextPosition start, ZLTextPosition end) {
|
public void highlight(ZLTextPosition start, ZLTextPosition end) {
|
||||||
removeManualHighlightings();
|
removeManualHighlightings();
|
||||||
final ZLTextHighlighting h = new ZLTextManualHighlighting(this, start, end);
|
addHighlighting(new ZLTextManualHighlighting(this, start, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void addHighlighting(ZLTextHighlighting h) {
|
||||||
myHighlightingsByStart.add(h);
|
myHighlightingsByStart.add(h);
|
||||||
myHighlightingsByEnd.add(h);
|
myHighlightingsByEnd.add(h);
|
||||||
Application.getViewWidget().reset();
|
Application.getViewWidget().reset();
|
||||||
Application.getViewWidget().repaint();
|
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() {
|
public void clearHighlighting() {
|
||||||
if (removeManualHighlightings()) {
|
if (removeManualHighlightings()) {
|
||||||
Application.getViewWidget().reset();
|
Application.getViewWidget().reset();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue