mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
loader code updated to be android-independent
This commit is contained in:
parent
f506acdfb2
commit
c49eec0e0d
17 changed files with 123 additions and 120 deletions
|
@ -23,6 +23,9 @@ DONE single book activity
|
||||||
depends_on_ip (?)
|
depends_on_ip (?)
|
||||||
|
|
||||||
resources for search actions
|
resources for search actions
|
||||||
|
errorMessage
|
||||||
|
titles/summaries
|
||||||
|
menu items
|
||||||
Search actions
|
Search actions
|
||||||
stopping search
|
stopping search
|
||||||
проверить все пути регистрации
|
проверить все пути регистрации
|
||||||
|
|
|
@ -637,10 +637,6 @@
|
||||||
<node name="noRequiredInformation" value="Required information is not specified in the catalog" />
|
<node name="noRequiredInformation" value="Required information is not specified in the catalog" />
|
||||||
<node name="cacheDirectoryError" value="Unable to create cache directory" />
|
<node name="cacheDirectoryError" value="Unable to create cache directory" />
|
||||||
</node>
|
</node>
|
||||||
<node name="emptySearchResults">
|
|
||||||
<node name="title" value="Search results" />
|
|
||||||
<node name="message" value="There are no suitable books found" />
|
|
||||||
</node>
|
|
||||||
<node name="AuthenticationDialog">
|
<node name="AuthenticationDialog">
|
||||||
<node name="title" value="Authentication" />
|
<node name="title" value="Authentication" />
|
||||||
<node name="unencryptedWarning" value="Your password will be sent unencrypted" />
|
<node name="unencryptedWarning" value="Your password will be sent unencrypted" />
|
||||||
|
@ -693,6 +689,7 @@
|
||||||
<node name="noFavorites" value="Your favorites list is empty, sorry"/>
|
<node name="noFavorites" value="Your favorites list is empty, sorry"/>
|
||||||
<node name="emptyCatalog" value="Catalog is empty, sorry" />
|
<node name="emptyCatalog" value="Catalog is empty, sorry" />
|
||||||
<node name="emptyBasket" value="Your basket is empty, sorry" />
|
<node name="emptyBasket" value="Your basket is empty, sorry" />
|
||||||
|
<node name="emptyNetworkSearchResults" value="No books found, sorry" />
|
||||||
</node>
|
</node>
|
||||||
<node name="external">
|
<node name="external">
|
||||||
<node name="browser" value="Browser"/>
|
<node name="browser" value="Browser"/>
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.geometerplus.android.fbreader.network;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.*;
|
import org.geometerplus.fbreader.network.*;
|
||||||
|
@ -30,18 +28,12 @@ import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
||||||
|
|
||||||
public abstract class ItemsLoader extends NetworkItemsLoader {
|
public abstract class ItemsLoader extends NetworkItemsLoader {
|
||||||
protected final Activity myActivity;
|
|
||||||
|
|
||||||
private volatile boolean myFinishProcessed;
|
|
||||||
private final Object myFinishMonitor = new Object();
|
|
||||||
|
|
||||||
private volatile boolean myFinished;
|
private volatile boolean myFinished;
|
||||||
private volatile Runnable myPostRunnable;
|
private volatile Runnable myPostRunnable;
|
||||||
private final Object myFinishedLock = new Object();
|
private final Object myFinishedLock = new Object();
|
||||||
|
|
||||||
public ItemsLoader(Activity activity, NetworkCatalogTree tree) {
|
public ItemsLoader(NetworkCatalogTree tree) {
|
||||||
super(tree);
|
super(tree);
|
||||||
myActivity = activity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void run() {
|
public final void run() {
|
||||||
|
@ -54,7 +46,7 @@ public abstract class ItemsLoader extends NetworkItemsLoader {
|
||||||
try {
|
try {
|
||||||
doBefore();
|
doBefore();
|
||||||
} catch (ZLNetworkException e) {
|
} catch (ZLNetworkException e) {
|
||||||
finishOnUiThread(e.getMessage(), false);
|
onFinish(e.getMessage(), false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String error = null;
|
String error = null;
|
||||||
|
@ -64,8 +56,7 @@ public abstract class ItemsLoader extends NetworkItemsLoader {
|
||||||
error = e.getMessage();
|
error = e.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
finishOnUiThread(error, isLoadingInterrupted());
|
onFinish(error, isLoadingInterrupted());
|
||||||
ensureFinishProcessed();
|
|
||||||
} finally {
|
} finally {
|
||||||
library.removeStoredLoader(getTree());
|
library.removeStoredLoader(getTree());
|
||||||
synchronized (myFinishedLock) {
|
synchronized (myFinishedLock) {
|
||||||
|
@ -91,30 +82,6 @@ public abstract class ItemsLoader extends NetworkItemsLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void ensureFinishProcessed() {
|
|
||||||
synchronized (myFinishMonitor) {
|
|
||||||
while (!myFinishProcessed) {
|
|
||||||
try {
|
|
||||||
myFinishMonitor.wait();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void finishOnUiThread(final String errorMessage, final boolean interrupted) {
|
|
||||||
myActivity.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
synchronized (myFinishMonitor) {
|
|
||||||
onFinish(errorMessage, interrupted);
|
|
||||||
myFinishProcessed = true;
|
|
||||||
// wake up process, that waits for finish condition (see ensureFinish() method)
|
|
||||||
myFinishMonitor.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void onFinish(String errorMessage, boolean interrupted);
|
protected abstract void onFinish(String errorMessage, boolean interrupted);
|
||||||
|
|
||||||
protected abstract void doBefore() throws ZLNetworkException;
|
protected abstract void doBefore() throws ZLNetworkException;
|
||||||
|
|
|
@ -396,7 +396,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkLibrary.
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLibraryChanged(NetworkLibrary.ChangeListener.Code code) {
|
public void onLibraryChanged(NetworkLibrary.ChangeListener.Code code, Object[] params) {
|
||||||
if (myBook == null) {
|
if (myBook == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ import org.geometerplus.fbreader.network.tree.*;
|
||||||
import org.geometerplus.android.fbreader.tree.TreeActivity;
|
import org.geometerplus.android.fbreader.tree.TreeActivity;
|
||||||
import org.geometerplus.android.fbreader.network.action.*;
|
import org.geometerplus.android.fbreader.network.action.*;
|
||||||
|
|
||||||
|
import org.geometerplus.android.util.UIUtil;
|
||||||
|
|
||||||
public class NetworkLibraryActivity extends TreeActivity implements NetworkLibrary.ChangeListener {
|
public class NetworkLibraryActivity extends TreeActivity implements NetworkLibrary.ChangeListener {
|
||||||
protected static final int BASIC_AUTHENTICATION_CODE = 1;
|
protected static final int BASIC_AUTHENTICATION_CODE = 1;
|
||||||
protected static final int SIGNUP_CODE = 2;
|
protected static final int SIGNUP_CODE = 2;
|
||||||
|
@ -324,9 +326,12 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
||||||
}
|
}
|
||||||
|
|
||||||
// method from NetworkLibrary.ChangeListener
|
// method from NetworkLibrary.ChangeListener
|
||||||
public void onLibraryChanged(NetworkLibrary.ChangeListener.Code code) {
|
public void onLibraryChanged(final NetworkLibrary.ChangeListener.Code code, final Object[] params) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
switch (code) {
|
||||||
|
default:
|
||||||
|
{
|
||||||
final NetworkTree tree = getLoadableNetworkTree((NetworkTree)getCurrentTree());
|
final NetworkTree tree = getLoadableNetworkTree((NetworkTree)getCurrentTree());
|
||||||
final boolean inProgress =
|
final boolean inProgress =
|
||||||
tree != null &&
|
tree != null &&
|
||||||
|
@ -335,6 +340,18 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
|
||||||
|
|
||||||
getListAdapter().replaceAll(getCurrentTree().subTrees());
|
getListAdapter().replaceAll(getCurrentTree().subTrees());
|
||||||
getListView().invalidateViews();
|
getListView().invalidateViews();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NotFound:
|
||||||
|
UIUtil.showErrorMessage(NetworkLibraryActivity.this, "emptyNetworkSearchResults");
|
||||||
|
break;
|
||||||
|
case EmptyCatalog:
|
||||||
|
UIUtil.showErrorMessage(NetworkLibraryActivity.this, "emptyCatalog");
|
||||||
|
break;
|
||||||
|
case NetworkError:
|
||||||
|
UIUtil.showMessageText(NetworkLibraryActivity.this, (String)params[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,9 +64,10 @@ public class NetworkSearchActivity extends Activity {
|
||||||
|
|
||||||
private static class Searcher extends ItemsLoader {
|
private static class Searcher extends ItemsLoader {
|
||||||
private final String myPattern;
|
private final String myPattern;
|
||||||
|
private volatile boolean myItemFound;
|
||||||
|
|
||||||
public Searcher(Activity activity, SearchCatalogTree tree, String pattern) {
|
public Searcher(SearchCatalogTree tree, String pattern) {
|
||||||
super(activity, tree);
|
super(tree);
|
||||||
myPattern = pattern;
|
myPattern = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,23 +77,24 @@ public class NetworkSearchActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doLoading() {
|
public void doLoading() {
|
||||||
try {
|
//try {
|
||||||
NetworkLibrary.Instance().simpleSearch(myPattern, this);
|
//NetworkLibrary.Instance().simpleSearch(myPattern, this);
|
||||||
} catch (ZLNetworkException e) {
|
//} catch (ZLNetworkException e) {
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
protected void addItem(NetworkItem item) {
|
public synchronized void onNewItem(final NetworkItem item) {
|
||||||
SearchResult result = getTree().getSearchResult();
|
if (!myItemFound) {
|
||||||
if (item instanceof NetworkBookItem) {
|
((SearchCatalogTree)getTree()).setPattern(myPattern);
|
||||||
result.addBook((NetworkBookItem)item);
|
getTree().clearCatalog();
|
||||||
getTree().updateSubTrees();
|
NetworkLibrary.Instance().fireModelChangedEvent(
|
||||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
NetworkLibrary.ChangeListener.Code.Found, getTree().getUniqueKey()
|
||||||
|
);
|
||||||
|
myItemFound = true;
|
||||||
}
|
}
|
||||||
|
super.onNewItem(item);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinish(String errorMessage, boolean interrupted) {
|
protected void onFinish(String errorMessage, boolean interrupted) {
|
||||||
|
@ -102,9 +104,12 @@ public class NetworkSearchActivity extends Activity {
|
||||||
//getTree().updateSubTrees();
|
//getTree().updateSubTrees();
|
||||||
//afterUpdateCatalog(errorMessage, getTree().getSearchResult().isEmpty());
|
//afterUpdateCatalog(errorMessage, getTree().getSearchResult().isEmpty());
|
||||||
}
|
}
|
||||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
if (!myItemFound) {
|
||||||
|
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.NotFound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private void afterUpdateCatalog(String errorMessage, boolean childrenEmpty) {
|
private void afterUpdateCatalog(String errorMessage, boolean childrenEmpty) {
|
||||||
final ZLResource dialogResource = ZLResource.resource("dialog");
|
final ZLResource dialogResource = ZLResource.resource("dialog");
|
||||||
ZLResource boxResource = null;
|
ZLResource boxResource = null;
|
||||||
|
@ -132,20 +137,19 @@ public class NetworkSearchActivity extends Activity {
|
||||||
.setPositiveButton(buttonResource.getResource("ok").getValue(), null)
|
.setPositiveButton(buttonResource.getResource("ok").getValue(), null)
|
||||||
.create().show();
|
.create().show();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void runSearch(SearchCatalogTree tree, String pattern) {
|
protected void runSearch(SearchCatalogTree tree, String pattern) {
|
||||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||||
library.NetworkSearchPatternOption.setValue(pattern);
|
library.NetworkSearchPatternOption.setValue(pattern);
|
||||||
|
new Searcher(tree, pattern).start();
|
||||||
/*
|
/*
|
||||||
final String summary = NetworkLibrary.resource().getResource("searchResults").getValue().replace("%s", pattern);
|
final String summary = NetworkLibrary.resource().getResource("searchResults").getValue().replace("%s", pattern);
|
||||||
final SearchResult result = new SearchResult(summary);
|
final SearchResult result = new SearchResult(summary);
|
||||||
|
|
||||||
//tree.setSearchResult(result);
|
//tree.setSearchResult(result);
|
||||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
|
||||||
|
|
||||||
new Searcher(this, tree, pattern).start();
|
|
||||||
Util.openTree(this, tree);
|
Util.openTree(this, tree);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,8 @@ package org.geometerplus.android.fbreader.network.action;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
import org.geometerplus.android.util.UIUtil;
|
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.INetworkLink;
|
import org.geometerplus.fbreader.network.INetworkLink;
|
||||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
import org.geometerplus.fbreader.network.NetworkItem;
|
import org.geometerplus.fbreader.network.NetworkItem;
|
||||||
|
@ -40,9 +36,8 @@ class CatalogExpander extends ItemsLoader {
|
||||||
private final boolean myCheckAuthentication;
|
private final boolean myCheckAuthentication;
|
||||||
private final boolean myResumeNotLoad;
|
private final boolean myResumeNotLoad;
|
||||||
|
|
||||||
public CatalogExpander(Activity activity,
|
public CatalogExpander(NetworkCatalogTree tree, boolean checkAuthentication, boolean resumeNotLoad) {
|
||||||
NetworkCatalogTree tree, boolean checkAuthentication, boolean resumeNotLoad) {
|
super(tree);
|
||||||
super(activity, tree);
|
|
||||||
myCheckAuthentication = checkAuthentication;
|
myCheckAuthentication = checkAuthentication;
|
||||||
myResumeNotLoad = resumeNotLoad;
|
myResumeNotLoad = resumeNotLoad;
|
||||||
}
|
}
|
||||||
|
@ -80,9 +75,13 @@ class CatalogExpander extends ItemsLoader {
|
||||||
getTree().updateLoadedTime();
|
getTree().updateLoadedTime();
|
||||||
if (!interrupted) {
|
if (!interrupted) {
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
UIUtil.showMessageText(myActivity, errorMessage);
|
NetworkLibrary.Instance().fireModelChangedEvent(
|
||||||
|
NetworkLibrary.ChangeListener.Code.NetworkError, errorMessage
|
||||||
|
);
|
||||||
} else if (getTree().subTrees().isEmpty()) {
|
} else if (getTree().subTrees().isEmpty()) {
|
||||||
UIUtil.showErrorMessage(myActivity, "emptyCatalog");
|
NetworkLibrary.Instance().fireModelChangedEvent(
|
||||||
|
NetworkLibrary.ChangeListener.Code.EmptyCatalog, errorMessage
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class OpenCatalogAction extends CatalogAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new CatalogExpander(myActivity, tree, true, resumeNotLoad).start();
|
new CatalogExpander(tree, true, resumeNotLoad).start();
|
||||||
processExtraData(tree.Item.extraData(), new Runnable() {
|
processExtraData(tree.Item.extraData(), new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Util.openTree(myActivity, tree);
|
Util.openTree(myActivity, tree);
|
||||||
|
|
|
@ -50,6 +50,6 @@ public class ReloadCatalogAction extends CatalogAction {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
((NetworkCatalogTree)tree).clearCatalog();
|
((NetworkCatalogTree)tree).clearCatalog();
|
||||||
new CatalogExpander(myActivity, (NetworkCatalogTree)tree, false, false).start();
|
new CatalogExpander((NetworkCatalogTree)tree, false, false).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class RunSearchAction extends Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(NetworkTree tree) {
|
public boolean isEnabled(NetworkTree tree) {
|
||||||
return NetworkLibrary.Instance().getStoredLoader(tree) != null;
|
return NetworkLibrary.Instance().getStoredLoader(tree) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,10 +25,15 @@ import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
||||||
|
|
||||||
public class AllCatalogsSearchItem extends SearchItem {
|
public class AllCatalogsSearchItem extends SearchItem {
|
||||||
public AllCatalogsSearchItem() {
|
public AllCatalogsSearchItem() {
|
||||||
super(
|
super(null);
|
||||||
null,
|
}
|
||||||
getResource().getResource("summaryAllCatalogs").getValue()
|
|
||||||
);
|
@Override
|
||||||
|
protected String getSummaryString() {
|
||||||
|
return
|
||||||
|
getPattern() != null
|
||||||
|
? NetworkLibrary.resource().getResource("found").getResource("summary").getValue().replace("%s", getPattern())
|
||||||
|
: NetworkLibrary.resource().getResource("search").getResource("summaryAllCatalogs").getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,17 +38,19 @@ import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||||
public class NetworkLibrary {
|
public class NetworkLibrary {
|
||||||
public interface ChangeListener {
|
public interface ChangeListener {
|
||||||
public enum Code {
|
public enum Code {
|
||||||
SomeCode
|
SomeCode,
|
||||||
/*
|
/*
|
||||||
ItemAdded,
|
ItemAdded,
|
||||||
ItemRemoved,
|
ItemRemoved,
|
||||||
StatusChanged,
|
StatusChanged,
|
||||||
Found,
|
|
||||||
NotFound
|
|
||||||
*/
|
*/
|
||||||
|
Found,
|
||||||
|
NotFound,
|
||||||
|
EmptyCatalog,
|
||||||
|
NetworkError
|
||||||
}
|
}
|
||||||
|
|
||||||
void onLibraryChanged(Code code);
|
void onLibraryChanged(Code code, Object[] params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NetworkLibrary ourInstance;
|
private static NetworkLibrary ourInstance;
|
||||||
|
@ -174,6 +176,8 @@ public class NetworkLibrary {
|
||||||
|
|
||||||
private volatile boolean myIsInitialized;
|
private volatile boolean myIsInitialized;
|
||||||
|
|
||||||
|
private final SearchItem mySearchItem = new AllCatalogsSearchItem();
|
||||||
|
|
||||||
private NetworkLibrary() {
|
private NetworkLibrary() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,18 +284,6 @@ public class NetworkLibrary {
|
||||||
myUpdateVisibility = true;
|
myUpdateVisibility = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static boolean linkIsChanged(INetworkLink link) {
|
|
||||||
// return
|
|
||||||
// link instanceof ICustomNetworkLink &&
|
|
||||||
// ((ICustomNetworkLink)link).hasChanges();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void makeValid(INetworkLink link) {
|
|
||||||
// if (link instanceof ICustomNetworkLink) {
|
|
||||||
// ((ICustomNetworkLink)link).resetChanges();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void makeUpToDate() {
|
private void makeUpToDate() {
|
||||||
final SortedSet<INetworkLink> linkSet = new TreeSet<INetworkLink>(activeLinks());
|
final SortedSet<INetworkLink> linkSet = new TreeSet<INetworkLink>(activeLinks());
|
||||||
|
|
||||||
|
@ -338,7 +330,7 @@ public class NetworkLibrary {
|
||||||
new NetworkCatalogRootTree(myRootTree, link, index);
|
new NetworkCatalogRootTree(myRootTree, link, index);
|
||||||
}
|
}
|
||||||
// we do add non-catalog items
|
// we do add non-catalog items
|
||||||
new SearchCatalogTree(myRootTree, new AllCatalogsSearchItem(), 0);
|
new SearchCatalogTree(myRootTree, mySearchItem, 0);
|
||||||
new AddCustomCatalogItemTree(myRootTree);
|
new AddCustomCatalogItemTree(myRootTree);
|
||||||
|
|
||||||
fireModelChangedEvent(ChangeListener.Code.SomeCode);
|
fireModelChangedEvent(ChangeListener.Code.SomeCode);
|
||||||
|
@ -463,10 +455,10 @@ public class NetworkLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: change to private
|
// TODO: change to private
|
||||||
/*private*/ public void fireModelChangedEvent(ChangeListener.Code code) {
|
/*private*/ public void fireModelChangedEvent(ChangeListener.Code code, Object ... params) {
|
||||||
synchronized (myListeners) {
|
synchronized (myListeners) {
|
||||||
for (ChangeListener l : myListeners) {
|
for (ChangeListener l : myListeners) {
|
||||||
l.onLibraryChanged(code);
|
l.onLibraryChanged(code, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,28 +19,34 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.network;
|
package org.geometerplus.fbreader.network;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.urlInfo.*;
|
import org.geometerplus.fbreader.network.urlInfo.*;
|
||||||
|
|
||||||
public abstract class SearchItem extends NetworkCatalogItem {
|
public abstract class SearchItem extends NetworkCatalogItem {
|
||||||
protected static ZLResource getResource() {
|
|
||||||
return NetworkLibrary.resource().getResource("search");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String myPattern;
|
private String myPattern;
|
||||||
|
|
||||||
protected SearchItem(INetworkLink link, String summary) {
|
protected SearchItem(INetworkLink link) {
|
||||||
super(
|
super(
|
||||||
link,
|
link,
|
||||||
getResource().getValue(),
|
NetworkLibrary.resource().getResource("search").getValue(),
|
||||||
summary,
|
"",
|
||||||
new UrlInfoCollection<UrlInfo>(),
|
new UrlInfoCollection<UrlInfo>(),
|
||||||
Accessibility.ALWAYS,
|
Accessibility.ALWAYS,
|
||||||
FLAGS_DEFAULT
|
FLAGS_DEFAULT
|
||||||
);
|
);
|
||||||
|
setSummary(getSummaryString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPattern(String pattern) {
|
||||||
|
myPattern = pattern;
|
||||||
|
setSummary(getSummaryString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getPattern() {
|
||||||
|
return myPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getSummaryString();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStringId() {
|
public String getStringId() {
|
||||||
return "@Search";
|
return "@Search";
|
||||||
|
|
|
@ -25,10 +25,15 @@ import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
||||||
|
|
||||||
public class SingleCatalogSearchItem extends SearchItem {
|
public class SingleCatalogSearchItem extends SearchItem {
|
||||||
public SingleCatalogSearchItem(INetworkLink link) {
|
public SingleCatalogSearchItem(INetworkLink link) {
|
||||||
super(
|
super(link);
|
||||||
link,
|
}
|
||||||
getResource().getResource("summary").getValue().replace("%s", link.getSiteName())
|
|
||||||
);
|
@Override
|
||||||
|
protected String getSummaryString() {
|
||||||
|
return
|
||||||
|
getPattern() != null
|
||||||
|
? NetworkLibrary.resource().getResource("found").getResource("summary").getValue().replace("%s", getPattern())
|
||||||
|
: NetworkLibrary.resource().getResource("search").getResource("summary").getValue().replace("%s", Link.getSiteName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -59,13 +59,17 @@ public class NetworkCatalogTree extends NetworkTree {
|
||||||
return Item.canBeOpened();
|
return Item.canBeOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SearchItem mySearchItem;
|
||||||
|
|
||||||
private void addSearchTree() {
|
private void addSearchTree() {
|
||||||
if ((Item.getFlags() & NetworkCatalogItem.FLAG_ADD_SEARCH_ITEM) != 0) {
|
if ((Item.getFlags() & NetworkCatalogItem.FLAG_ADD_SEARCH_ITEM) != 0) {
|
||||||
final INetworkLink link = getLink();
|
final INetworkLink link = getLink();
|
||||||
if (link != null && link.getUrl(UrlInfo.Type.Search) != null) {
|
if (link != null && link.getUrl(UrlInfo.Type.Search) != null) {
|
||||||
final SearchItem item = new SingleCatalogSearchItem(link);
|
if (mySearchItem == null) {
|
||||||
myChildrenItems.add(item);
|
mySearchItem = new SingleCatalogSearchItem(link);
|
||||||
new SearchCatalogTree(this, item, 0);
|
}
|
||||||
|
myChildrenItems.add(mySearchItem);
|
||||||
|
new SearchCatalogTree(this, mySearchItem, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ public abstract class NetworkItemsLoader implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void onNewItem(final NetworkItem item) {
|
public void onNewItem(final NetworkItem item) {
|
||||||
getTree().addItem(item);
|
getTree().addItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ public class SearchCatalogTree extends NetworkCatalogTree {
|
||||||
setCover(null);
|
setCover(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPattern(String pattern) {
|
||||||
|
((SearchItem)Item).setPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTreeTitle() {
|
public String getTreeTitle() {
|
||||||
return getSummary();
|
return getSummary();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue