Skip to content

Commit

Permalink
new implementation of network search (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
geometer committed Sep 12, 2011
1 parent 5a4e3a0 commit c7c7391
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 34 deletions.
Binary file removed icons/tree/ic_list_searchresult.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.geometerplus.android.fbreader.network;

import java.util.*;
import java.util.Set;

import android.app.Activity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;

import org.geometerplus.fbreader.network.NetworkTree;
import org.geometerplus.fbreader.network.*;
import org.geometerplus.fbreader.network.tree.*;

import org.geometerplus.android.fbreader.tree.TreeAdapter;
Expand Down Expand Up @@ -119,8 +119,8 @@ private void setupCover(final ImageView coverView, NetworkTree tree, int width,
coverView.setImageResource(R.drawable.ic_list_library_book);
} else if (tree instanceof AddCustomCatalogItemTree) {
coverView.setImageResource(R.drawable.ic_list_plus);
} else if (tree instanceof SearchItemTree) {
coverView.setImageResource(R.drawable.ic_list_searchresult);
} else if (tree instanceof NetworkCatalogTree && tree.getHoldedItem() instanceof SearchItem) {
coverView.setImageResource(android.R.drawable.ic_menu_search);
} else {
coverView.setImageResource(R.drawable.ic_list_library_books);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public abstract class NetworkCatalogItem extends NetworkItem {
public static final int FLAG_GROUP_BY_AUTHOR = 1 << 1;
public static final int FLAG_GROUP_BY_SERIES = 1 << 2;
public static final int FLAG_GROUP_MORE_THAN_1_BOOK_BY_SERIES = 1 << 3;
public static final int FLAG_ADD_SEARCH_ITEM = 1 << 4;

public static final int FLAGS_DEFAULT =
FLAG_SHOW_AUTHOR |
Expand Down
6 changes: 5 additions & 1 deletion src/org/geometerplus/fbreader/network/NetworkLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ private void makeUpToDate() {
} else {
linkSet.remove(link);
}
} else {
// 3. search item
toRemove.add(t);
}
} else {
// 3. non-catalog nodes
// 4. non-catalog nodes
toRemove.add(t);
}
}
Expand All @@ -335,6 +338,7 @@ private void makeUpToDate() {
new NetworkCatalogRootTree(myRootTree, link, index);
}
// we do add non-catalog items
new NetworkCatalogTree(myRootTree, new SearchItem(null), 0);
new AddCustomCatalogItemTree(myRootTree);

fireModelChangedEvent(ChangeListener.Code.SomeCode);
Expand Down
14 changes: 1 addition & 13 deletions src/org/geometerplus/fbreader/network/NetworkURLCatalogItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@
import org.geometerplus.fbreader.network.urlInfo.UrlInfoCollection;

public abstract class NetworkURLCatalogItem extends NetworkCatalogItem {
/**
* Creates new NetworkURLCatalogItem instance with <code>Accessibility.ALWAYS</code> accessibility and <code>FLAGS_DEFAULT</code> flags.
*
* @param link corresponding NetworkLink object. Must be not <code>null</code>.
* @param title title of this library item. Must be not <code>null</code>.
* @param summary description of this library item. Can be <code>null</code>.
* @param urls collection of item-related URLs. Can be <code>null</code>.
*/
public NetworkURLCatalogItem(INetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls) {
this(link, title, summary, urls, Accessibility.ALWAYS, FLAGS_DEFAULT);
}

/**
* Creates new NetworkURLCatalogItem instance with specified accessibility and type.
*
Expand All @@ -50,7 +38,7 @@ public NetworkURLCatalogItem(INetworkLink link, CharSequence title, CharSequence
* in the network library view.
* @param flags value defines how to show book items in this catalog.
*/
public NetworkURLCatalogItem(INetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls, Accessibility accessibility, int flags) {
protected NetworkURLCatalogItem(INetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls, Accessibility accessibility, int flags) {
super(link, title, summary, urls, accessibility, flags);
}

Expand Down
63 changes: 63 additions & 0 deletions src/org/geometerplus/fbreader/network/SearchItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2010-2011 Geometer Plus <[email protected]>
*
* 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.fbreader.network;

//import org.geometerplus.zlibrary.core.util.ZLNetworkUtil;
import org.geometerplus.zlibrary.core.network.ZLNetworkException;

import org.geometerplus.fbreader.network.urlInfo.*;

public class SearchItem extends NetworkCatalogItem {
public SearchItem(INetworkLink link) {
super(
link,
NetworkLibrary.resource().getResource("search").getValue(),
NetworkLibrary.resource().getResource("searchSummaryEmpty").getValue(),
new UrlInfoCollection<UrlInfo>(),
Accessibility.ALWAYS,
FLAGS_DEFAULT
);
}

public String getStringId() {
return "@Search";
}

public void loadChildren(NetworkItemsLoader loader) throws ZLNetworkException {
}

/*
@Override
protected String getCatalogUrl() {
final StringBuilder builder = new StringBuilder();
boolean flag = false;
for (String bookId : Link.basket().bookIds()) {
if (flag) {
builder.append(',');
} else {
flag = true;
}
builder.append(bookId);
}
return ZLNetworkUtil.appendParameter(getUrl(UrlInfo.Type.Catalog), "ids", builder.toString());
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class LitResRecommendationsItem extends OPDSCatalogItem {
public LitResRecommendationsItem(OPDSNetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls) {
super(link, title, summary, urls, Accessibility.HAS_BOOKS, FLAGS_DEFAULT & ~FLAGS_GROUP);
super(link, title, summary, urls, Accessibility.HAS_BOOKS, FLAGS_DEFAULT & ~FLAGS_GROUP, null);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/org/geometerplus/fbreader/network/opds/BasketItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class BasketItem extends OPDSCatalogItem {
NetworkLibrary.resource().getResource("basketSummaryEmpty").getValue(),
urls,
Accessibility.ALWAYS,
FLAGS_DEFAULT & ~FLAGS_GROUP
FLAGS_DEFAULT & ~FLAGS_GROUP,
null
);
link.setSupportsBasket();
}
Expand Down
25 changes: 15 additions & 10 deletions src/org/geometerplus/fbreader/network/opds/OPDSCatalogItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public State(OPDSNetworkLink link, NetworkItemsLoader loader) {
private State myLoadingState;
private final Map<String,String> myExtraData;

OPDSCatalogItem(OPDSNetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls, Map<String,String> extraData) {
super(link, title, summary, urls);
myExtraData = extraData;
OPDSCatalogItem(OPDSNetworkLink link, RelatedUrlInfo info) {
this(link, info.Title, null, createSimpleCollection(info.Url));
}

protected OPDSCatalogItem(OPDSNetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls, Accessibility accessibility, int flags) {
OPDSCatalogItem(OPDSNetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls) {
this(link, title, summary, urls, Accessibility.ALWAYS, FLAGS_DEFAULT, null);
}

protected OPDSCatalogItem(OPDSNetworkLink link, CharSequence title, CharSequence summary, UrlInfoCollection<?> urls, Accessibility accessibility, int flags, Map<String,String> extraData) {
super(link, title, summary, urls, accessibility, flags);
myExtraData = null;
myExtraData = extraData;
}

private static UrlInfoCollection<UrlInfo> createSimpleCollection(String url) {
Expand All @@ -55,11 +58,6 @@ private static UrlInfoCollection<UrlInfo> createSimpleCollection(String url) {
return collection;
}

OPDSCatalogItem(OPDSNetworkLink link, RelatedUrlInfo info) {
super(link, info.Title, null, createSimpleCollection(info.Url));
myExtraData = null;
}

private void doLoadChildren(ZLNetworkRequest networkRequest) throws ZLNetworkException {
try {
super.doLoadChildren(myLoadingState, networkRequest);
Expand All @@ -82,6 +80,13 @@ protected String getCatalogUrl() {
public final void loadChildren(NetworkItemsLoader loader) throws ZLNetworkException {
final OPDSNetworkLink opdsLink = (OPDSNetworkLink)Link;

if ((getFlags() & FLAG_ADD_SEARCH_ITEM) != 0) {
if (opdsLink.getUrl(UrlInfo.Type.Search) != null) {
loader.onNewItem(new SearchItem(opdsLink));
loader.commitItems();
}
}

myLoadingState = opdsLink.createOperationData(loader);

doLoadChildren(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ private NetworkItem readCatalogItem(OPDSEntry entry) {
opdsLink,
entry.Title,
annotation,
urlMap,
OPDSCatalogItem.Accessibility.ALWAYS,
NetworkCatalogItem.FLAGS_DEFAULT
urlMap
);
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/org/geometerplus/fbreader/network/opds/OPDSNetworkLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ public NetworkCatalogItem libraryItem() {
urlMap.addInfo(getUrlInfo(UrlInfo.Type.Catalog));
urlMap.addInfo(getUrlInfo(UrlInfo.Type.Image));
urlMap.addInfo(getUrlInfo(UrlInfo.Type.Thumbnail));
return new OPDSCatalogItem(this, getTitle(), getSummary(), urlMap, myExtraData);
return new OPDSCatalogItem(
this,
getTitle(),
getSummary(),
urlMap,
OPDSCatalogItem.Accessibility.ALWAYS,
OPDSCatalogItem.FLAGS_DEFAULT | OPDSCatalogItem.FLAG_ADD_SEARCH_ITEM,
myExtraData
);
}

public NetworkAuthenticationManager authenticationManager() {
Expand Down

0 comments on commit c7c7391

Please sign in to comment.