mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
refactoring: no dependency fbreader => text view (in progress)
This commit is contained in:
parent
21fc9bbb54
commit
5763e2ef63
15 changed files with 79 additions and 39 deletions
|
@ -247,9 +247,9 @@ void BookReader::addVideoEntry(const ZLVideoEntry &entry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookReader::addFBReaderSpecialEntry(const std::string &action, const std::map<std::string,std::string> &data) {
|
void BookReader::addExtensionEntry(const std::string &action, const std::map<std::string,std::string> &data) {
|
||||||
if (myCurrentTextModel != 0) {
|
if (myCurrentTextModel != 0) {
|
||||||
myCurrentTextModel->addFBReaderSpecialEntry(action, data);
|
myCurrentTextModel->addExtensionEntry(action, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
void addImage(const std::string &id, shared_ptr<const ZLImage> image);
|
void addImage(const std::string &id, shared_ptr<const ZLImage> image);
|
||||||
|
|
||||||
void addVideoEntry(const ZLVideoEntry &entry);
|
void addVideoEntry(const ZLVideoEntry &entry);
|
||||||
void addFBReaderSpecialEntry(const std::string &action, const std::map<std::string,std::string> &data);
|
void addExtensionEntry(const std::string &action, const std::map<std::string,std::string> &data);
|
||||||
|
|
||||||
void beginContentsParagraph(int referenceNumber = -1);
|
void beginContentsParagraph(int referenceNumber = -1);
|
||||||
void endContentsParagraph();
|
void endContentsParagraph();
|
||||||
|
|
|
@ -543,7 +543,7 @@ void XHTMLTagPreAction::doAtEnd(XHTMLReader &reader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void XHTMLTagOpdsAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
|
void XHTMLTagOpdsAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
|
||||||
bookReader(reader).addFBReaderSpecialEntry("opds", reader.attributeMap(xmlattributes));
|
bookReader(reader).addExtensionEntry("opds", reader.attributeMap(xmlattributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
void XHTMLTagOpdsAction::doAtEnd(XHTMLReader &reader) {
|
void XHTMLTagOpdsAction::doAtEnd(XHTMLReader &reader) {
|
||||||
|
|
|
@ -385,7 +385,7 @@ void ZLTextModel::addVideoEntry(const ZLVideoEntry &entry) {
|
||||||
++myParagraphLengths.back();
|
++myParagraphLengths.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZLTextModel::addFBReaderSpecialEntry(const std::string &action, const std::map<std::string,std::string> &data) {
|
void ZLTextModel::addExtensionEntry(const std::string &action, const std::map<std::string,std::string> &data) {
|
||||||
std::size_t fullLength = 2; // entry type + map size
|
std::size_t fullLength = 2; // entry type + map size
|
||||||
fullLength += 2 + ZLUnicodeUtil::utf8Length(action) * 2; // action name
|
fullLength += 2 + ZLUnicodeUtil::utf8Length(action) * 2; // action name
|
||||||
for (std::map<std::string,std::string>::const_iterator it = data.begin(); it != data.end(); ++it) {
|
for (std::map<std::string,std::string>::const_iterator it = data.begin(); it != data.end(); ++it) {
|
||||||
|
@ -394,7 +394,7 @@ void ZLTextModel::addFBReaderSpecialEntry(const std::string &action, const std::
|
||||||
}
|
}
|
||||||
|
|
||||||
myLastEntryStart = myAllocator->allocate(fullLength);
|
myLastEntryStart = myAllocator->allocate(fullLength);
|
||||||
*myLastEntryStart = ZLTextParagraphEntry::FBREADER_SPECIAL;
|
*myLastEntryStart = ZLTextParagraphEntry::EXTENSION_ENTRY;
|
||||||
*(myLastEntryStart + 1) = data.size();
|
*(myLastEntryStart + 1) = data.size();
|
||||||
|
|
||||||
char *p = myLastEntryStart + 2;
|
char *p = myLastEntryStart + 2;
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
void addFixedHSpace(unsigned char length);
|
void addFixedHSpace(unsigned char length);
|
||||||
void addBidiReset();
|
void addBidiReset();
|
||||||
void addVideoEntry(const ZLVideoEntry &entry);
|
void addVideoEntry(const ZLVideoEntry &entry);
|
||||||
void addFBReaderSpecialEntry(const std::string &action, const std::map<std::string,std::string> &data);
|
void addExtensionEntry(const std::string &action, const std::map<std::string,std::string> &data);
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
RESET_BIDI_ENTRY = 9,
|
RESET_BIDI_ENTRY = 9,
|
||||||
AUDIO_ENTRY = 10,
|
AUDIO_ENTRY = 10,
|
||||||
VIDEO_ENTRY = 11,
|
VIDEO_ENTRY = 11,
|
||||||
FBREADER_SPECIAL = 12,
|
EXTENSION_ENTRY = 12,
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -154,10 +154,10 @@ private:
|
||||||
ResetBidiEntry();
|
ResetBidiEntry();
|
||||||
};
|
};
|
||||||
|
|
||||||
class FBReaderSpecialEntry : public ZLTextParagraphEntry {
|
class ExtensionEntry : public ZLTextParagraphEntry {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~FBReaderSpecialEntry();
|
~ExtensionEntry();
|
||||||
const std::string &action() const;
|
const std::string &action() const;
|
||||||
const std::string &data() const;
|
const std::string &data() const;
|
||||||
|
|
||||||
|
@ -269,9 +269,9 @@ inline short ImageEntry::vOffset() const { return myVOffset; }
|
||||||
|
|
||||||
inline ResetBidiEntry::ResetBidiEntry() {}
|
inline ResetBidiEntry::ResetBidiEntry() {}
|
||||||
|
|
||||||
inline FBReaderSpecialEntry::~FBReaderSpecialEntry() {}
|
inline ExtensionEntry::~ExtensionEntry() {}
|
||||||
inline const std::string &FBReaderSpecialEntry::action() const { return myAction; }
|
inline const std::string &ExtensionEntry::action() const { return myAction; }
|
||||||
inline const std::string &FBReaderSpecialEntry::data() const { return myData; }
|
inline const std::string &ExtensionEntry::data() const { return myData; }
|
||||||
|
|
||||||
inline ZLTextParagraph::ZLTextParagraph() : myEntryNumber(0) {}
|
inline ZLTextParagraph::ZLTextParagraph() : myEntryNumber(0) {}
|
||||||
inline ZLTextParagraph::~ZLTextParagraph() {}
|
inline ZLTextParagraph::~ZLTextParagraph() {}
|
||||||
|
|
|
@ -17,23 +17,24 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.fbreader.fbreader;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.*;
|
import org.geometerplus.zlibrary.core.network.*;
|
||||||
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.opds.*;
|
import org.geometerplus.fbreader.network.opds.*;
|
||||||
|
|
||||||
class BookElementsHolder {
|
class BookElementManager extends ExtensionElementManager {
|
||||||
private final Runnable myScreenRefresher;
|
private final Runnable myScreenRefresher;
|
||||||
private final Map<Map<String,String>,List<BookElement>> myCache =
|
private final Map<Map<String,String>,List<BookElement>> myCache =
|
||||||
new HashMap<Map<String,String>,List<BookElement>>();
|
new HashMap<Map<String,String>,List<BookElement>>();
|
||||||
private Timer myTimer;
|
private Timer myTimer;
|
||||||
|
|
||||||
BookElementsHolder(final ZLTextView view) {
|
BookElementManager(final ZLTextView view) {
|
||||||
myScreenRefresher = new Runnable() {
|
myScreenRefresher = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
view.Application.getViewWidget().reset();
|
view.Application.getViewWidget().reset();
|
||||||
|
@ -42,7 +43,12 @@ class BookElementsHolder {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized List<BookElement> getElements(Map<String,String> data) {
|
@Override
|
||||||
|
protected synchronized List<BookElement> getElements(String type, Map<String,String> data) {
|
||||||
|
if (!"opds".equals(type)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
List<BookElement> elements = myCache.get(data);
|
List<BookElement> elements = myCache.get(data);
|
||||||
if (elements == null) {
|
if (elements == null) {
|
||||||
try {
|
try {
|
|
@ -40,6 +40,7 @@ import org.geometerplus.fbreader.fbreader.options.*;
|
||||||
public final class FBView extends ZLTextView {
|
public final class FBView extends ZLTextView {
|
||||||
private final FBReaderApp myReader;
|
private final FBReaderApp myReader;
|
||||||
private final ViewOptions myViewOptions;
|
private final ViewOptions myViewOptions;
|
||||||
|
private final BookElementManager myBookElementManager = new BookElementManager(this);
|
||||||
|
|
||||||
FBView(FBReaderApp reader) {
|
FBView(FBReaderApp reader) {
|
||||||
super(reader);
|
super(reader);
|
||||||
|
@ -783,4 +784,9 @@ public final class FBView extends ZLTextView {
|
||||||
super.onScrollingFinished(pageIndex);
|
super.onScrollingFinished(pageIndex);
|
||||||
myReader.storePosition();
|
myReader.storePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ExtensionElementManager getExtensionManager() {
|
||||||
|
return myBookElementManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@ package org.geometerplus.zlibrary.text.model;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class FBReaderSpecialEntry {
|
public class ExtensionEntry {
|
||||||
public final String Type;
|
public final String Type;
|
||||||
public final Map<String,String> Data;
|
public final Map<String,String> Data;
|
||||||
|
|
||||||
FBReaderSpecialEntry(String type, Map<String,String> data) {
|
ExtensionEntry(String type, Map<String,String> data) {
|
||||||
Type = type;
|
Type = type;
|
||||||
Data = data;
|
Data = data;
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ public class FBReaderSpecialEntry {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(other instanceof FBReaderSpecialEntry)) {
|
if (!(other instanceof ExtensionEntry)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final FBReaderSpecialEntry entry = (FBReaderSpecialEntry)other;
|
final ExtensionEntry entry = (ExtensionEntry)other;
|
||||||
return Type.equals(entry.Type) && Data.equals(entry.Data);
|
return Type.equals(entry.Type) && Data.equals(entry.Data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public interface ZLTextParagraph {
|
||||||
byte RESET_BIDI = 9;
|
byte RESET_BIDI = 9;
|
||||||
byte AUDIO = 10;
|
byte AUDIO = 10;
|
||||||
byte VIDEO = 11;
|
byte VIDEO = 11;
|
||||||
byte FBREADER_SPECIAL = 12;
|
byte EXTENSION = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EntryIterator {
|
interface EntryIterator {
|
||||||
|
@ -50,7 +50,7 @@ public interface ZLTextParagraph {
|
||||||
|
|
||||||
ZLImageEntry getImageEntry();
|
ZLImageEntry getImageEntry();
|
||||||
ZLVideoEntry getVideoEntry();
|
ZLVideoEntry getVideoEntry();
|
||||||
FBReaderSpecialEntry getFBReaderSpecialEntry();
|
ExtensionEntry getExtensionEntry();
|
||||||
ZLTextStyleEntry getStyleEntry();
|
ZLTextStyleEntry getStyleEntry();
|
||||||
|
|
||||||
short getFixedHSpaceLength();
|
short getFixedHSpaceLength();
|
||||||
|
|
|
@ -70,8 +70,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
// VideoEntry
|
// VideoEntry
|
||||||
private ZLVideoEntry myVideoEntry;
|
private ZLVideoEntry myVideoEntry;
|
||||||
|
|
||||||
// FBReaderSpecialEntry
|
// ExtensionEntry
|
||||||
private FBReaderSpecialEntry myFBReaderSpecialEntry;
|
private ExtensionEntry myExtensionEntry;
|
||||||
|
|
||||||
// StyleEntry
|
// StyleEntry
|
||||||
private ZLTextStyleEntry myStyleEntry;
|
private ZLTextStyleEntry myStyleEntry;
|
||||||
|
@ -125,8 +125,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
return myVideoEntry;
|
return myVideoEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FBReaderSpecialEntry getFBReaderSpecialEntry() {
|
public ExtensionEntry getExtensionEntry() {
|
||||||
return myFBReaderSpecialEntry;
|
return myExtensionEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLTextStyleEntry getStyleEntry() {
|
public ZLTextStyleEntry getStyleEntry() {
|
||||||
|
@ -272,7 +272,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ZLTextParagraph.Entry.FBREADER_SPECIAL:
|
case ZLTextParagraph.Entry.EXTENSION:
|
||||||
{
|
{
|
||||||
final short kindLength = (short)data[dataOffset++];
|
final short kindLength = (short)data[dataOffset++];
|
||||||
final String kind = new String(data, dataOffset, kindLength);
|
final String kind = new String(data, dataOffset, kindLength);
|
||||||
|
@ -288,7 +288,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
map.put(key, new String(data, dataOffset, valueLength));
|
map.put(key, new String(data, dataOffset, valueLength));
|
||||||
dataOffset += valueLength;
|
dataOffset += valueLength;
|
||||||
}
|
}
|
||||||
myFBReaderSpecialEntry = new FBReaderSpecialEntry(kind, map);
|
myExtensionEntry = new ExtensionEntry(kind, map);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class BookElement extends ZLTextElement {
|
||||||
private OPDSBookItem myItem;
|
private OPDSBookItem myItem;
|
||||||
private NetworkImage myCover;
|
private NetworkImage myCover;
|
||||||
|
|
||||||
void setData(OPDSBookItem item) {
|
public void setData(OPDSBookItem item) {
|
||||||
final String bookUrl = item.getUrl(UrlInfo.Type.Book);
|
final String bookUrl = item.getUrl(UrlInfo.Type.Book);
|
||||||
String coverUrl = item.getUrl(UrlInfo.Type.Image);
|
String coverUrl = item.getUrl(UrlInfo.Type.Image);
|
||||||
if (coverUrl == null) {
|
if (coverUrl == null) {
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2014 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.model.ExtensionEntry;
|
||||||
|
|
||||||
|
public abstract class ExtensionElementManager {
|
||||||
|
final List<BookElement> getElements(ExtensionEntry entry) {
|
||||||
|
return getElements(entry.Type, entry.Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract List<BookElement> getElements(String type, Map<String,String> data);
|
||||||
|
}
|
|
@ -108,14 +108,9 @@ public final class ZLTextParagraphCursor {
|
||||||
case ZLTextParagraph.Entry.VIDEO:
|
case ZLTextParagraph.Entry.VIDEO:
|
||||||
elements.add(new ZLTextVideoElement(it.getVideoEntry().sources()));
|
elements.add(new ZLTextVideoElement(it.getVideoEntry().sources()));
|
||||||
break;
|
break;
|
||||||
case ZLTextParagraph.Entry.FBREADER_SPECIAL:
|
case ZLTextParagraph.Entry.EXTENSION:
|
||||||
{
|
elements.addAll(myView.getExtensionManager().getElements(it.getExtensionEntry()));
|
||||||
final FBReaderSpecialEntry entry = it.getFBReaderSpecialEntry();
|
|
||||||
if ("opds".equals(entry.Type)) {
|
|
||||||
elements.addAll(myView.Holder.getElements(entry.Data));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case ZLTextParagraph.Entry.STYLE_CSS:
|
case ZLTextParagraph.Entry.STYLE_CSS:
|
||||||
case ZLTextParagraph.Entry.STYLE_OTHER:
|
case ZLTextParagraph.Entry.STYLE_OTHER:
|
||||||
elements.add(new ZLTextStyleElement(it.getStyleEntry()));
|
elements.add(new ZLTextStyleElement(it.getStyleEntry()));
|
||||||
|
|
|
@ -68,8 +68,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
|
|
||||||
private final ZLTextParagraphCursorCache myCursorCache = new ZLTextParagraphCursorCache();
|
private final ZLTextParagraphCursorCache myCursorCache = new ZLTextParagraphCursorCache();
|
||||||
|
|
||||||
final BookElementsHolder Holder = new BookElementsHolder(this);
|
|
||||||
|
|
||||||
public ZLTextView(ZLApplication application) {
|
public ZLTextView(ZLApplication application) {
|
||||||
super(application);
|
super(application);
|
||||||
}
|
}
|
||||||
|
@ -1887,4 +1885,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract ExtensionElementManager getExtensionManager();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue