mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
manual merging with steffen branch: visited hyperlinks engine
This commit is contained in:
parent
343f0818a2
commit
f9a3335ce5
7 changed files with 94 additions and 10 deletions
|
@ -63,6 +63,7 @@ class ProcessHyperlinkAction extends FBAction {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FBHyperlinkType.INTERNAL:
|
case FBHyperlinkType.INTERNAL:
|
||||||
|
Reader.Model.Book.markHyperlinkAsVisited(hyperlink.Id);
|
||||||
Reader.tryOpenFootnote(hyperlink.Id);
|
Reader.tryOpenFootnote(hyperlink.Id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
|
|
||||||
private void migrate(Context context) {
|
private void migrate(Context context) {
|
||||||
final int version = myDatabase.getVersion();
|
final int version = myDatabase.getVersion();
|
||||||
final int currentVersion = 15;
|
final int currentVersion = 16;
|
||||||
if (version >= currentVersion) {
|
if (version >= currentVersion) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
updateTables13();
|
updateTables13();
|
||||||
case 14:
|
case 14:
|
||||||
updateTables14();
|
updateTables14();
|
||||||
|
case 15:
|
||||||
|
updateTables15();
|
||||||
}
|
}
|
||||||
myDatabase.setTransactionSuccessful();
|
myDatabase.setTransactionSuccessful();
|
||||||
myDatabase.endTransaction();
|
myDatabase.endTransaction();
|
||||||
|
@ -838,6 +840,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
}
|
}
|
||||||
myDeleteFromBookListStatement.bindLong(1, bookId);
|
myDeleteFromBookListStatement.bindLong(1, bookId);
|
||||||
myDeleteFromBookListStatement.execute();
|
myDeleteFromBookListStatement.execute();
|
||||||
|
deleteVisitedHyperlinks(bookId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,6 +855,41 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
return myCheckBookListStatement.simpleQueryForLong() > 0;
|
return myCheckBookListStatement.simpleQueryForLong() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SQLiteStatement myDeleteVisitedHyperlinksStatement;
|
||||||
|
private void deleteVisitedHyperlinks(long bookId) {
|
||||||
|
if (myDeleteVisitedHyperlinksStatement == null) {
|
||||||
|
myDeleteVisitedHyperlinksStatement = myDatabase.compileStatement(
|
||||||
|
"DELETE FROM VisitedHyperlinks WHERE book_id = ?"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
myDeleteVisitedHyperlinksStatement.bindLong(1, bookId);
|
||||||
|
myDeleteVisitedHyperlinksStatement.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private SQLiteStatement myStoreVisitedHyperlinksStatement;
|
||||||
|
protected void addVisitedHyperlink(long bookId, String hyperlinkId) {
|
||||||
|
if (myStoreVisitedHyperlinksStatement == null) {
|
||||||
|
myStoreVisitedHyperlinksStatement = myDatabase.compileStatement(
|
||||||
|
"INSERT OR IGNORE INTO VisitedHyperlinks(book_id,hyperlink_id) VALUES (?,?)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
myStoreVisitedHyperlinksStatement.bindLong(1, bookId);
|
||||||
|
myStoreVisitedHyperlinksStatement.bindString(2, hyperlinkId);
|
||||||
|
myStoreVisitedHyperlinksStatement.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Collection<String> loadVisitedHyperlinks(long bookId) {
|
||||||
|
final TreeSet<String> links = new TreeSet<String>();
|
||||||
|
final Cursor cursor = myDatabase.rawQuery("SELECT hyperlink_id FROM VisitedHyperlinks WHERE book_id = ?", new String[] { "" + bookId });
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
links.add(cursor.getString(0));
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createTables() {
|
private void createTables() {
|
||||||
myDatabase.execSQL(
|
myDatabase.execSQL(
|
||||||
|
@ -1140,4 +1178,12 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
myDatabase.execSQL("INSERT INTO BookSeries (series_id,book_id,book_index) SELECT series_id,book_id,book_index FROM BookSeries_Obsolete");
|
myDatabase.execSQL("INSERT INTO BookSeries (series_id,book_id,book_index) SELECT series_id,book_id,book_index FROM BookSeries_Obsolete");
|
||||||
myDatabase.execSQL("DROP TABLE BookSeries_Obsolete");
|
myDatabase.execSQL("DROP TABLE BookSeries_Obsolete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateTables15() {
|
||||||
|
myDatabase.execSQL(
|
||||||
|
"CREATE TABLE IF NOT EXISTS VisitedHyperlinks(" +
|
||||||
|
"book_id INTEGER NOT NULL REFERENCES Books(book_id)," +
|
||||||
|
"hyperlink_id TEXT NOT NULL," +
|
||||||
|
"CONSTRAINT VisitedHyperlinks_Unique UNIQUE (book_id, hyperlink_id))");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,4 @@ public interface FBHyperlinkType {
|
||||||
byte NONE = 0;
|
byte NONE = 0;
|
||||||
byte INTERNAL = 1;
|
byte INTERNAL = 1;
|
||||||
byte EXTERNAL = 2;
|
byte EXTERNAL = 2;
|
||||||
byte INTERNAL_VISITED = 3;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,17 +386,18 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLColor getTextColor(byte hyperlinkType) {
|
public ZLColor getTextColor(ZLTextHyperlink hyperlink) {
|
||||||
final ColorProfile profile = myReader.getColorProfile();
|
final ColorProfile profile = myReader.getColorProfile();
|
||||||
switch (hyperlinkType) {
|
switch (hyperlink.Type) {
|
||||||
default:
|
default:
|
||||||
case FBHyperlinkType.NONE:
|
case FBHyperlinkType.NONE:
|
||||||
return profile.RegularTextOption.getValue();
|
return profile.RegularTextOption.getValue();
|
||||||
case FBHyperlinkType.INTERNAL:
|
case FBHyperlinkType.INTERNAL:
|
||||||
|
return myReader.Model.Book.isHyperlinkVisited(hyperlink.Id)
|
||||||
|
? profile.VisitedHyperlinkTextOption.getValue()
|
||||||
|
: profile.HyperlinkTextOption.getValue();
|
||||||
case FBHyperlinkType.EXTERNAL:
|
case FBHyperlinkType.EXTERNAL:
|
||||||
return profile.HyperlinkTextOption.getValue();
|
return profile.HyperlinkTextOption.getValue();
|
||||||
case FBHyperlinkType.INTERNAL_VISITED:
|
|
||||||
return profile.VisitedHyperlinkTextOption.getValue();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +464,7 @@ public final class FBView extends ZLTextView {
|
||||||
|
|
||||||
final ZLColor bgColor = getBackgroundColor();
|
final ZLColor bgColor = getBackgroundColor();
|
||||||
// TODO: separate color option for footer color
|
// TODO: separate color option for footer color
|
||||||
final ZLColor fgColor = getTextColor(FBHyperlinkType.NONE);
|
final ZLColor fgColor = getTextColor(ZLTextHyperlink.NO_LINK);
|
||||||
final ZLColor fillColor = reader.getColorProfile().FooterFillOption.getValue();
|
final ZLColor fillColor = reader.getColorProfile().FooterFillOption.getValue();
|
||||||
|
|
||||||
final int left = getLeftMargin();
|
final int left = getLeftMargin();
|
||||||
|
|
|
@ -335,6 +335,7 @@ public class Book {
|
||||||
database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle);
|
database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle);
|
||||||
} else {
|
} else {
|
||||||
myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);
|
myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);
|
||||||
|
storeAllVisitedHyperinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
long index = 0;
|
long index = 0;
|
||||||
|
@ -364,6 +365,39 @@ public class Book {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> myVisitedHyperlinks;
|
||||||
|
private void initHyperlinkSet() {
|
||||||
|
if (myVisitedHyperlinks == null) {
|
||||||
|
myVisitedHyperlinks = new TreeSet<String>();
|
||||||
|
if (myId != -1) {
|
||||||
|
myVisitedHyperlinks.addAll(BooksDatabase.Instance().loadVisitedHyperlinks(myId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHyperlinkVisited(String linkId) {
|
||||||
|
initHyperlinkSet();
|
||||||
|
return myVisitedHyperlinks.contains(linkId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void markHyperlinkAsVisited(String linkId) {
|
||||||
|
initHyperlinkSet();
|
||||||
|
if (!myVisitedHyperlinks.contains(linkId)) {
|
||||||
|
myVisitedHyperlinks.add(linkId);
|
||||||
|
if (myId != -1) {
|
||||||
|
BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void storeAllVisitedHyperinks() {
|
||||||
|
if (myId != -1 && myVisitedHyperlinks != null) {
|
||||||
|
for (String linkId : myVisitedHyperlinks) {
|
||||||
|
BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void insertIntoBookList() {
|
public void insertIntoBookList() {
|
||||||
if (myId != -1) {
|
if (myId != -1) {
|
||||||
BooksDatabase.Instance().insertIntoBookList(myId);
|
BooksDatabase.Instance().insertIntoBookList(myId);
|
||||||
|
|
|
@ -104,4 +104,7 @@ public abstract class BooksDatabase {
|
||||||
protected abstract boolean insertIntoBookList(long bookId);
|
protected abstract boolean insertIntoBookList(long bookId);
|
||||||
protected abstract boolean deleteFromBookList(long bookId);
|
protected abstract boolean deleteFromBookList(long bookId);
|
||||||
protected abstract boolean checkBookList(long bookId);
|
protected abstract boolean checkBookList(long bookId);
|
||||||
|
|
||||||
|
protected abstract Collection<String> loadVisitedHyperlinks(long bookId);
|
||||||
|
protected abstract void addVisitedHyperlink(long bookId, String hyperlinkId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
public abstract ZLFile getWallpaperFile();
|
public abstract ZLFile getWallpaperFile();
|
||||||
public abstract ZLColor getBackgroundColor();
|
public abstract ZLColor getBackgroundColor();
|
||||||
public abstract ZLColor getSelectedBackgroundColor();
|
public abstract ZLColor getSelectedBackgroundColor();
|
||||||
public abstract ZLColor getTextColor(byte hyperlinkType);
|
public abstract ZLColor getTextColor(ZLTextHyperlink hyperlink);
|
||||||
public abstract ZLColor getHighlightingColor();
|
public abstract ZLColor getHighlightingColor();
|
||||||
|
|
||||||
int getTextAreaHeight() {
|
int getTextAreaHeight() {
|
||||||
|
@ -185,7 +185,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
|
|
||||||
final void drawWord(int x, int y, ZLTextWord word, int start, int length, boolean addHyphenationSign) {
|
final void drawWord(int x, int y, ZLTextWord word, int start, int length, boolean addHyphenationSign) {
|
||||||
final ZLPaintContext context = myContext;
|
final ZLPaintContext context = myContext;
|
||||||
context.setTextColor(getTextColor(myTextStyle.Hyperlink.Type));
|
context.setTextColor(getTextColor(myTextStyle.Hyperlink));
|
||||||
if ((start == 0) && (length == -1)) {
|
if ((start == 0) && (length == -1)) {
|
||||||
drawString(x, y, word.Data, word.Offset, word.Length, word.getMark(), 0);
|
drawString(x, y, word.Data, word.Offset, word.Length, word.getMark(), 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue