Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/resources/application/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@
<node name="selectionBackground" value="Hintergrund von ausgewählten Text"/>
<node name="text" value="Normalen Text"/>
<node name="hyperlink" value="Hyperlinks"/>
<node name="hyperlinkVisited" value="Besuchte Hyperlinks"/>
<node name="highlighting" value="Hintergrund der Suchergebnisse"/>
<node name="footer" value="Footer" toBeTranslated="true"/>
</node>
Expand Down
1 change: 1 addition & 0 deletions assets/resources/application/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
<node name="selectionBackground" value="Selection background"/>
<node name="text" value="Regular text"/>
<node name="hyperlink" value="Hyperlink text"/>
<node name="hyperlinkVisited" value="Visited hyperlink text"/>
<node name="highlighting" value="Search results background"/>
<node name="footer" value="Footer" />
</node>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import android.net.Uri;

import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.ZLHyperlinkStackManager;
import org.geometerplus.zlibrary.core.util.ZLVisitedLinkManager;
import org.geometerplus.zlibrary.core.network.ZLNetworkException;

import org.geometerplus.zlibrary.text.view.ZLTextView;
Expand Down Expand Up @@ -53,14 +55,18 @@ public boolean isEnabled() {
}

public void run() {
final ZLTextHyperlink hyperlink = Reader.getTextView().getCurrentHyperlink();
ZLTextHyperlink hyperlink = Reader.getTextView().getCurrentHyperlink();
if (hyperlink != null) {
switch (hyperlink.Type) {
case FBHyperlinkType.EXTERNAL:
openInBrowser(hyperlink.Id);
break;
case FBHyperlinkType.INTERNAL:
case FBHyperlinkType.INTERNAL_VISITED:
ZLHyperlinkStackManager.Instance().pushPosition(Reader.getPosition());
ZLVisitedLinkManager.Instance().markLinkVisited(hyperlink.Id);
Reader.tryOpenFootnote(hyperlink.Id);
hyperlink.Type = FBHyperlinkType.INTERNAL_VISITED;
break;
}
return;
Expand Down
127 changes: 126 additions & 1 deletion src/org/geometerplus/android/fbreader/SQLiteBooksDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.options.ZLIntegerOption;
import org.geometerplus.zlibrary.core.util.ZLHyperlinkStackManager;
import org.geometerplus.zlibrary.core.util.ZLVisitedLinkManager;
import org.geometerplus.zlibrary.core.config.ZLConfig;
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
Expand Down Expand Up @@ -60,7 +62,7 @@ protected void executeAsATransaction(Runnable actions) {

private void migrate(Context context) {
final int version = myDatabase.getVersion();
final int currentVersion = 13;
final int currentVersion = 14;
if (version >= currentVersion) {
return;
}
Expand Down Expand Up @@ -95,6 +97,8 @@ public void run() {
updateTables11();
case 12:
updateTables12();
case 13:
updateTables13();
}
myDatabase.setTransactionSuccessful();
myDatabase.endTransaction();
Expand Down Expand Up @@ -849,6 +853,8 @@ protected boolean deleteFromBookList(long bookId) {
}
myDeleteFromBookListStatement.bindLong(1, bookId);
myDeleteFromBookListStatement.execute();
deleteVisitedLinks(bookId);
deleteLinkHistory(bookId);
return true;
}

Expand All @@ -864,6 +870,108 @@ protected boolean checkBookList(long bookId) {
}


private SQLiteStatement myDeleteVisitedLinksStatement;
private void deleteVisitedLinks(long bookId) {
if (myDeleteVisitedLinksStatement == null) {
myDeleteVisitedLinksStatement = myDatabase.compileStatement(
"DELETE FROM VisitedLinks WHERE book_id = ?"
);
}

myDeleteVisitedLinksStatement.bindLong(1, bookId);
myDeleteVisitedLinksStatement.execute();
}

private SQLiteStatement myStoreVisitedLinksStatement;
protected void storeVisitedLinks(long bookId) {
if (myStoreVisitedLinksStatement == null) {
myStoreVisitedLinksStatement = myDatabase.compileStatement(
"INSERT OR REPLACE INTO VisitedLinks(book_id, link_id, link) VALUES (?,?,?)"
);
}

deleteVisitedLinks(bookId);
int linkId = 0;
Iterator<String> it = ZLVisitedLinkManager.Instance().getVisitedLinks().iterator();
while( it.hasNext()) {
String link = it.next();
myStoreVisitedLinksStatement.bindLong(1, bookId);
myStoreVisitedLinksStatement.bindLong(2, linkId);
myStoreVisitedLinksStatement.bindString(3, link);
myStoreVisitedLinksStatement.execute();
linkId = linkId + 1;
}
}

protected void loadVisitedLinks(long bookId) {
ZLVisitedLinkManager linkManager = ZLVisitedLinkManager.Instance();
linkManager.reset();
final Cursor cursor = myDatabase.rawQuery("SELECT link FROM VisitedLinks WHERE book_id = ?", new String[] { "" + bookId });
if (!cursor.moveToNext()) {
cursor.close();
return;
}
do {
String link = cursor.getString(0);
linkManager.markLinkVisited(link);
} while (cursor.moveToNext());
cursor.close();
}

private SQLiteStatement myDeleteLinkHistoryStatement;
private void deleteLinkHistory(long bookId) {
if (myDeleteLinkHistoryStatement == null) {
myDeleteLinkHistoryStatement = myDatabase.compileStatement(
"DELETE FROM LinkHistory WHERE book_id = ?"
);
}

myDeleteLinkHistoryStatement.bindLong(1, bookId);
myDeleteLinkHistoryStatement.execute();
}

private SQLiteStatement myStoreLinkHistoryStatement;
protected void storeLinkHistory(long bookId) {
if (myStoreLinkHistoryStatement == null) {
myStoreLinkHistoryStatement = myDatabase.compileStatement(
"INSERT OR REPLACE INTO LinkHistory (book_id, history_id, paragraph, word, char) VALUES (?,?,?,?,?)"
);
}

deleteLinkHistory(bookId);
int historyId = 0;
Iterator<ZLTextPosition> iterator = ZLHyperlinkStackManager.Instance().getIterator();
while (iterator.hasNext()) {
ZLTextPosition position = iterator.next();
myStoreLinkHistoryStatement.bindLong(1, bookId);
myStoreLinkHistoryStatement.bindLong(2, historyId);
myStoreLinkHistoryStatement.bindLong(3, position.getParagraphIndex());
myStoreLinkHistoryStatement.bindLong(4, position.getElementIndex());
myStoreLinkHistoryStatement.bindLong(5, position.getCharIndex());
myStoreLinkHistoryStatement.execute();
historyId = historyId + 1;
}
}

protected void loadLinkHistory(long bookId) {
ZLHyperlinkStackManager stackManager = ZLHyperlinkStackManager.Instance();
stackManager.reset();
final Cursor cursor = myDatabase.rawQuery("SELECT paragraph, word, char FROM LinkHistory WHERE book_id = ? ORDER BY history_id", new String[] { "" + bookId });
if (!cursor.moveToNext()) {
cursor.close();
return;
}
do {
ZLTextPosition position = new ZLTextFixedPosition(
(int)cursor.getLong(0),
(int)cursor.getLong(1),
(int)cursor.getLong(2)
);
stackManager.pushPosition(position);
} while (cursor.moveToNext());
cursor.close();
}

private void createTables() {
myDatabase.execSQL(
"CREATE TABLE Books(" +
Expand Down Expand Up @@ -1134,4 +1242,21 @@ private void updateTables11() {
private void updateTables12() {
myDatabase.execSQL("DELETE FROM Files WHERE parent_id IN (SELECT file_id FROM Files WHERE name LIKE '%.epub')");
}

private void updateTables13() {
myDatabase.execSQL(
"CREATE TABLE VisitedLinks(" +
"book_id INTEGER NOT NULL REFERENCES Books(book_id)," +
"link_id INTEGER NOT NULL," +
"link TEXT NOT NULL," +
"CONSTRAINT VisitedLinks_Unique UNIQUE (book_id, link_id))");
myDatabase.execSQL(
"CREATE TABLE LinkHistory(" +
"book_id INTEGER NOT NULL REFERENCES Books(book_id)," +
"history_id INTEGER NOT NULL," +
"paragraph INTEGER NOT NULL," +
"word INTEGER NOT NULL," +
"char INTEGER NOT NULL," +
"CONSTRAINT LinkHistory_Unique UNIQUE (book_id, history_id))");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ protected void onDialogClosed(boolean result) {
colorsScreen.addOption(profile.HighlightingOption, "highlighting");
colorsScreen.addOption(profile.RegularTextOption, "text");
colorsScreen.addOption(profile.HyperlinkTextOption, "hyperlink");
colorsScreen.addOption(profile.HyperlinkVisitedTextOption, "hyperlinkVisited");
colorsScreen.addOption(profile.FooterFillOption, "footer");

final Screen marginsScreen = createPreferenceScreen("margins");
Expand Down
17 changes: 17 additions & 0 deletions src/org/geometerplus/fbreader/bookmodel/BookReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ private final void insertEndParagraph(byte kind) {
}
}

public final void beginStartOfSectionParagraph() {
final ZLTextWritableModel textModel = myCurrentTextModel;
if (textModel != null) {
textModel.createParagraph(ZLTextParagraph.Kind.START_OF_SECTION_PARAGRAPH);
myTextParagraphExists = true;
}
}

public final void insertEndOfSectionParagraph() {
insertEndParagraph(ZLTextParagraph.Kind.END_OF_SECTION_PARAGRAPH);
}
Expand Down Expand Up @@ -394,6 +402,15 @@ public final void addImageReference(String ref, short vOffset) {
}
}

public final void addPageLink(String ref) {
final ZLTextWritableModel textModel = myCurrentTextModel;
if (textModel != null) {
beginStartOfSectionParagraph();
textModel.addPageLink(ref);
endParagraph();
}
}

public final void addImage(String id, ZLImage image) {
Model.addImage(id, image);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public interface FBHyperlinkType {
byte NONE = 0;
byte INTERNAL = 1;
byte EXTERNAL = 2;
byte INTERNAL_VISITED = 3;
}
10 changes: 9 additions & 1 deletion src/org/geometerplus/fbreader/fbreader/CancelAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.geometerplus.fbreader.fbreader;

import org.geometerplus.zlibrary.core.util.ZLHyperlinkStackManager;

class CancelAction extends FBAction {
CancelAction(FBReaderApp fbreader) {
super(fbreader);
Expand All @@ -28,7 +30,13 @@ public void run() {
if (Reader.getCurrentView() != Reader.BookTextView) {
Reader.showBookTextView();
} else {
Reader.closeWindow();
ZLHyperlinkStackManager hyperlinkStack = ZLHyperlinkStackManager.Instance();
if (!hyperlinkStack.emptyStack()) {
Reader.gotoPosition(hyperlinkStack.popPosition());
} else {
// Reader.doAction(ActionCode.SHOW_LIBRARY);
Reader.closeWindow();
}
}
}
}
6 changes: 6 additions & 0 deletions src/org/geometerplus/fbreader/fbreader/ColorProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static ColorProfile get(String name) {
public final ZLColorOption HighlightingOption;
public final ZLColorOption RegularTextOption;
public final ZLColorOption HyperlinkTextOption;
public final ZLColorOption HyperlinkVisitedTextOption;
public final ZLColorOption FooterFillOption;

private ColorProfile(String name, ColorProfile base) {
Expand All @@ -68,6 +69,7 @@ private ColorProfile(String name, ColorProfile base) {
HighlightingOption.setValue(base.HighlightingOption.getValue());
RegularTextOption.setValue(base.RegularTextOption.getValue());
HyperlinkTextOption.setValue(base.HyperlinkTextOption.getValue());
HyperlinkVisitedTextOption.setValue(base.HyperlinkVisitedTextOption.getValue());
FooterFillOption.setValue(base.FooterFillOption.getValue());
}

Expand All @@ -89,6 +91,8 @@ private ColorProfile(String name) {
createOption(name, "Text", 192, 192, 192);
HyperlinkTextOption =
createOption(name, "Hyperlink", 60, 142, 224);
HyperlinkVisitedTextOption =
createOption(name, "HyperlinkVisited", 200, 139, 255);
FooterFillOption =
createOption(name, "FooterFillOption", 85, 85, 85);
} else {
Expand All @@ -104,6 +108,8 @@ private ColorProfile(String name) {
createOption(name, "Text", 0, 0, 0);
HyperlinkTextOption =
createOption(name, "Hyperlink", 60, 139, 255);
HyperlinkVisitedTextOption =
createOption(name, "HyperlinkVisited", 200, 139, 255);
FooterFillOption =
createOption(name, "FooterFillOption", 170, 170, 170);
}
Expand Down
16 changes: 16 additions & 0 deletions src/org/geometerplus/fbreader/fbreader/FBReaderApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.geometerplus.zlibrary.core.options.*;

import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
import org.geometerplus.zlibrary.text.view.ZLTextPosition;

import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.library.Library;
Expand Down Expand Up @@ -207,6 +208,8 @@ void openBookInternal(Book book, Bookmark bookmark) {

if (Model != null) {
Model.Book.storePosition(BookTextView.getStartCursor());
Model.Book.storeVisitedLinks();
Model.Book.storeLinkHistory();
}
BookTextView.setModel(null);
FootnoteView.setModel(null);
Expand All @@ -218,6 +221,8 @@ void openBookInternal(Book book, Bookmark bookmark) {
Model = BookModel.createModel(book);
if (Model != null) {
ZLTextHyphenator.Instance().load(book.getLanguage());
book.loadLinkHistory();
book.loadVisitedLinks();
BookTextView.setModel(Model.BookTextModel);
BookTextView.gotoPosition(book.getStoredPosition());
if (bookmark == null) {
Expand Down Expand Up @@ -248,6 +253,15 @@ public void showBookTextView() {
setView(BookTextView);
}

public void gotoPosition(ZLTextPosition position) {
BookTextView.gotoPosition(position);
setView(BookTextView);
}

public ZLTextPosition getPosition() {
return BookTextView.getStartCursor();
}

private Book createBookForFile(ZLFile file) {
if (file == null) {
return null;
Expand Down Expand Up @@ -280,6 +294,8 @@ public void openFile(ZLFile file) {
public void onWindowClosing() {
if ((Model != null) && (BookTextView != null)) {
Model.Book.storePosition(BookTextView.getStartCursor());
Model.Book.storeVisitedLinks();
Model.Book.storeLinkHistory();
}
}
}
2 changes: 2 additions & 0 deletions src/org/geometerplus/fbreader/fbreader/FBView.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ public ZLColor getTextColor(byte hyperlinkType) {
default:
case FBHyperlinkType.NONE:
return profile.RegularTextOption.getValue();
case FBHyperlinkType.INTERNAL_VISITED:
return profile.HyperlinkVisitedTextOption.getValue();
case FBHyperlinkType.INTERNAL:
case FBHyperlinkType.EXTERNAL:
return profile.HyperlinkTextOption.getValue();
Expand Down
1 change: 1 addition & 0 deletions src/org/geometerplus/fbreader/fbreader/TurnPageAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public boolean isEnabled() {
public void run() {
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
final FBView view = Reader.getTextView();
view.checkInvalidCache();
if (view.getAnimationType() != FBView.Animation.none) {
final boolean horizontal = preferences.HorizontalOption.getValue();
if (myForward) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void run() {
}
}
final FBView view = Reader.getTextView();
view.checkInvalidCache();
if (view.getAnimationType() != FBView.Animation.none) {
final boolean horizontal = preferences.HorizontalOption.getValue();
if (forward) {
Expand Down
Loading