mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
BookElementsHolder (in text view) => BookElementManager (in fbreader.fbreader)
This commit is contained in:
parent
6d2ab76f50
commit
0bf543eb6c
5 changed files with 93 additions and 14 deletions
|
@ -17,26 +17,39 @@
|
|||
* 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.*;
|
||||
|
||||
class BookElementsHolder {
|
||||
import org.geometerplus.zlibrary.core.network.*;
|
||||
import org.geometerplus.zlibrary.text.view.BookElement;
|
||||
import org.geometerplus.zlibrary.text.view.ExtensionElementManager;
|
||||
|
||||
import org.geometerplus.fbreader.network.opds.*;
|
||||
|
||||
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 FBReaderApp reader) {
|
||||
myScreenRefresher = new Runnable() {
|
||||
public void run() {
|
||||
view.Application.getViewWidget().reset();
|
||||
view.Application.getViewWidget().repaint();
|
||||
reader.getViewWidget().reset();
|
||||
reader.getViewWidget().repaint();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -57,6 +70,37 @@ class BookElementsHolder {
|
|||
private void startLoading(final String url, final List<BookElement> elements) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
final SimpleOPDSFeedHandler handler = new SimpleOPDSFeedHandler(url);
|
||||
try {
|
||||
new QuietNetworkContext().perform(new ZLNetworkRequest.Get(url, true) {
|
||||
@Override
|
||||
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
|
||||
new OPDSXMLReader(handler, false).read(inputStream);
|
||||
}
|
||||
});
|
||||
if (handler.books().isEmpty()) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
myTimer = null;
|
||||
final List<OPDSBookItem> items = handler.books();
|
||||
int index = 0;
|
||||
for (BookElement book : elements) {
|
||||
//book.setData(items.get(index));
|
||||
index = (index + 1) % items.size();
|
||||
myScreenRefresher.run();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (myTimer == null) {
|
||||
myTimer = new Timer();
|
||||
}
|
||||
myTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
startLoading(url, elements);
|
||||
}
|
||||
}, 10000);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
|
@ -40,11 +40,13 @@ import org.geometerplus.fbreader.fbreader.options.*;
|
|||
public final class FBView extends ZLTextView {
|
||||
private final FBReaderApp myReader;
|
||||
private final ViewOptions myViewOptions;
|
||||
private final BookElementManager myBookElementManager;
|
||||
|
||||
FBView(FBReaderApp reader) {
|
||||
super(reader);
|
||||
myReader = reader;
|
||||
myViewOptions = reader.ViewOptions;
|
||||
myBookElementManager = new BookElementManager(reader);
|
||||
}
|
||||
|
||||
public void setModel(ZLTextModel model) {
|
||||
|
@ -783,4 +785,9 @@ public final class FBView extends ZLTextView {
|
|||
super.onScrollingFinished(pageIndex);
|
||||
myReader.storePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExtensionElementManager getExtensionManager() {
|
||||
return myBookElementManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -109,13 +109,8 @@ public final class ZLTextParagraphCursor {
|
|||
elements.add(new ZLTextVideoElement(it.getVideoEntry().sources()));
|
||||
break;
|
||||
case ZLTextParagraph.Entry.EXTENSION:
|
||||
{
|
||||
final ExtensionEntry entry = it.getExtensionEntry();
|
||||
if ("opds".equals(entry.Type)) {
|
||||
elements.addAll(myView.Holder.getElements(entry.Data));
|
||||
}
|
||||
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