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) {
|
||||
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 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 endContentsParagraph();
|
||||
|
|
|
@ -543,7 +543,7 @@ void XHTMLTagPreAction::doAtEnd(XHTMLReader &reader) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -385,7 +385,7 @@ void ZLTextModel::addVideoEntry(const ZLVideoEntry &entry) {
|
|||
++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
|
||||
fullLength += 2 + ZLUnicodeUtil::utf8Length(action) * 2; // action name
|
||||
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 = ZLTextParagraphEntry::FBREADER_SPECIAL;
|
||||
*myLastEntryStart = ZLTextParagraphEntry::EXTENSION_ENTRY;
|
||||
*(myLastEntryStart + 1) = data.size();
|
||||
|
||||
char *p = myLastEntryStart + 2;
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
void addFixedHSpace(unsigned char length);
|
||||
void addBidiReset();
|
||||
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();
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
RESET_BIDI_ENTRY = 9,
|
||||
AUDIO_ENTRY = 10,
|
||||
VIDEO_ENTRY = 11,
|
||||
FBREADER_SPECIAL = 12,
|
||||
EXTENSION_ENTRY = 12,
|
||||
};
|
||||
|
||||
protected:
|
||||
|
@ -154,10 +154,10 @@ private:
|
|||
ResetBidiEntry();
|
||||
};
|
||||
|
||||
class FBReaderSpecialEntry : public ZLTextParagraphEntry {
|
||||
class ExtensionEntry : public ZLTextParagraphEntry {
|
||||
|
||||
public:
|
||||
~FBReaderSpecialEntry();
|
||||
~ExtensionEntry();
|
||||
const std::string &action() const;
|
||||
const std::string &data() const;
|
||||
|
||||
|
@ -269,9 +269,9 @@ inline short ImageEntry::vOffset() const { return myVOffset; }
|
|||
|
||||
inline ResetBidiEntry::ResetBidiEntry() {}
|
||||
|
||||
inline FBReaderSpecialEntry::~FBReaderSpecialEntry() {}
|
||||
inline const std::string &FBReaderSpecialEntry::action() const { return myAction; }
|
||||
inline const std::string &FBReaderSpecialEntry::data() const { return myData; }
|
||||
inline ExtensionEntry::~ExtensionEntry() {}
|
||||
inline const std::string &ExtensionEntry::action() const { return myAction; }
|
||||
inline const std::string &ExtensionEntry::data() const { return myData; }
|
||||
|
||||
inline ZLTextParagraph::ZLTextParagraph() : myEntryNumber(0) {}
|
||||
inline ZLTextParagraph::~ZLTextParagraph() {}
|
||||
|
|
|
@ -17,23 +17,24 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.zlibrary.text.view;
|
||||
package org.geometerplus.fbreader.fbreader;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.network.*;
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
|
||||
import org.geometerplus.fbreader.network.opds.*;
|
||||
|
||||
class BookElementsHolder {
|
||||
class BookElementManager extends ExtensionElementManager {
|
||||
private final Runnable myScreenRefresher;
|
||||
private final Map<Map<String,String>,List<BookElement>> myCache =
|
||||
new HashMap<Map<String,String>,List<BookElement>>();
|
||||
private Timer myTimer;
|
||||
|
||||
BookElementsHolder(final ZLTextView view) {
|
||||
BookElementManager(final ZLTextView view) {
|
||||
myScreenRefresher = new Runnable() {
|
||||
public void run() {
|
||||
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);
|
||||
if (elements == null) {
|
||||
try {
|
|
@ -40,6 +40,7 @@ import org.geometerplus.fbreader.fbreader.options.*;
|
|||
public final class FBView extends ZLTextView {
|
||||
private final FBReaderApp myReader;
|
||||
private final ViewOptions myViewOptions;
|
||||
private final BookElementManager myBookElementManager = new BookElementManager(this);
|
||||
|
||||
FBView(FBReaderApp reader) {
|
||||
super(reader);
|
||||
|
@ -783,4 +784,9 @@ public final class FBView extends ZLTextView {
|
|||
super.onScrollingFinished(pageIndex);
|
||||
myReader.storePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExtensionElementManager getExtensionManager() {
|
||||
return myBookElementManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ package org.geometerplus.zlibrary.text.model;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class FBReaderSpecialEntry {
|
||||
public class ExtensionEntry {
|
||||
public final String Type;
|
||||
public final Map<String,String> Data;
|
||||
|
||||
FBReaderSpecialEntry(String type, Map<String,String> data) {
|
||||
ExtensionEntry(String type, Map<String,String> data) {
|
||||
Type = type;
|
||||
Data = data;
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ public class FBReaderSpecialEntry {
|
|||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof FBReaderSpecialEntry)) {
|
||||
if (!(other instanceof ExtensionEntry)) {
|
||||
return false;
|
||||
}
|
||||
final FBReaderSpecialEntry entry = (FBReaderSpecialEntry)other;
|
||||
final ExtensionEntry entry = (ExtensionEntry)other;
|
||||
return Type.equals(entry.Type) && Data.equals(entry.Data);
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ public interface ZLTextParagraph {
|
|||
byte RESET_BIDI = 9;
|
||||
byte AUDIO = 10;
|
||||
byte VIDEO = 11;
|
||||
byte FBREADER_SPECIAL = 12;
|
||||
byte EXTENSION = 12;
|
||||
}
|
||||
|
||||
interface EntryIterator {
|
||||
|
@ -50,7 +50,7 @@ public interface ZLTextParagraph {
|
|||
|
||||
ZLImageEntry getImageEntry();
|
||||
ZLVideoEntry getVideoEntry();
|
||||
FBReaderSpecialEntry getFBReaderSpecialEntry();
|
||||
ExtensionEntry getExtensionEntry();
|
||||
ZLTextStyleEntry getStyleEntry();
|
||||
|
||||
short getFixedHSpaceLength();
|
||||
|
|
|
@ -70,8 +70,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
// VideoEntry
|
||||
private ZLVideoEntry myVideoEntry;
|
||||
|
||||
// FBReaderSpecialEntry
|
||||
private FBReaderSpecialEntry myFBReaderSpecialEntry;
|
||||
// ExtensionEntry
|
||||
private ExtensionEntry myExtensionEntry;
|
||||
|
||||
// StyleEntry
|
||||
private ZLTextStyleEntry myStyleEntry;
|
||||
|
@ -125,8 +125,8 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
return myVideoEntry;
|
||||
}
|
||||
|
||||
public FBReaderSpecialEntry getFBReaderSpecialEntry() {
|
||||
return myFBReaderSpecialEntry;
|
||||
public ExtensionEntry getExtensionEntry() {
|
||||
return myExtensionEntry;
|
||||
}
|
||||
|
||||
public ZLTextStyleEntry getStyleEntry() {
|
||||
|
@ -272,7 +272,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case ZLTextParagraph.Entry.FBREADER_SPECIAL:
|
||||
case ZLTextParagraph.Entry.EXTENSION:
|
||||
{
|
||||
final short kindLength = (short)data[dataOffset++];
|
||||
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));
|
||||
dataOffset += valueLength;
|
||||
}
|
||||
myFBReaderSpecialEntry = new FBReaderSpecialEntry(kind, map);
|
||||
myExtensionEntry = new ExtensionEntry(kind, map);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public final class BookElement extends ZLTextElement {
|
|||
private OPDSBookItem myItem;
|
||||
private NetworkImage myCover;
|
||||
|
||||
void setData(OPDSBookItem item) {
|
||||
public void setData(OPDSBookItem item) {
|
||||
final String bookUrl = item.getUrl(UrlInfo.Type.Book);
|
||||
String coverUrl = item.getUrl(UrlInfo.Type.Image);
|
||||
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:
|
||||
elements.add(new ZLTextVideoElement(it.getVideoEntry().sources()));
|
||||
break;
|
||||
case ZLTextParagraph.Entry.FBREADER_SPECIAL:
|
||||
{
|
||||
final FBReaderSpecialEntry entry = it.getFBReaderSpecialEntry();
|
||||
if ("opds".equals(entry.Type)) {
|
||||
elements.addAll(myView.Holder.getElements(entry.Data));
|
||||
}
|
||||
case ZLTextParagraph.Entry.EXTENSION:
|
||||
elements.addAll(myView.getExtensionManager().getElements(it.getExtensionEntry()));
|
||||
break;
|
||||
}
|
||||
case ZLTextParagraph.Entry.STYLE_CSS:
|
||||
case ZLTextParagraph.Entry.STYLE_OTHER:
|
||||
elements.add(new ZLTextStyleElement(it.getStyleEntry()));
|
||||
|
|
|
@ -68,8 +68,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
|
||||
private final ZLTextParagraphCursorCache myCursorCache = new ZLTextParagraphCursorCache();
|
||||
|
||||
final BookElementsHolder Holder = new BookElementsHolder(this);
|
||||
|
||||
public ZLTextView(ZLApplication application) {
|
||||
super(application);
|
||||
}
|
||||
|
@ -1887,4 +1885,6 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract ExtensionElementManager getExtensionManager();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue