mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
fixed custom catalog search
This commit is contained in:
parent
16fd2dd17e
commit
ad05ea1664
9 changed files with 90 additions and 95 deletions
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.geometerplus.android.fbreader.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -35,15 +37,14 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
|||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSLinkReader;
|
||||
|
||||
import org.geometerplus.android.util.UIUtil;
|
||||
|
||||
public class AddCustomCatalogActivity extends Activity {
|
||||
private ZLResource myResource;
|
||||
private Integer myCatalogId;
|
||||
private String myIcon;
|
||||
private volatile ICustomNetworkLink myLink;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -83,21 +84,16 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
myLink = NetworkLibraryActivity.getLinkFromIntent(intent);
|
||||
final Uri uri = intent.getData();
|
||||
myCatalogId = ICustomNetworkLink.INVALID_ID;
|
||||
if (uri != null) {
|
||||
myCatalogId = intent.getIntExtra(
|
||||
NetworkLibraryActivity.ADD_CATALOG_ID_KEY, myCatalogId
|
||||
);
|
||||
if (myCatalogId != ICustomNetworkLink.INVALID_ID) {
|
||||
setTextById(R.id.add_custom_catalog_url, uri.toString());
|
||||
setTextById(R.id.add_custom_catalog_title, intent.getStringExtra(NetworkLibraryActivity.ADD_CATALOG_TITLE_KEY));
|
||||
setTextById(R.id.add_custom_catalog_summary, intent.getStringExtra(NetworkLibraryActivity.ADD_CATALOG_SUMMARY_KEY));
|
||||
myIcon = intent.getStringExtra(NetworkLibraryActivity.ADD_CATALOG_ICON_KEY);
|
||||
} else {
|
||||
loadInfoByUri(uri);
|
||||
}
|
||||
|
||||
if (myLink != null) {
|
||||
setTextById(R.id.add_custom_catalog_url, myLink.getUrlInfo(INetworkLink.URL_MAIN).URL);
|
||||
setTextById(R.id.add_custom_catalog_title, myLink.getTitle());
|
||||
setTextById(R.id.add_custom_catalog_summary, myLink.getSummary());
|
||||
setExtraFieldsVisibility(true);
|
||||
} else if (uri != null) {
|
||||
loadInfoByUri(uri);
|
||||
} else {
|
||||
setExtraFieldsVisibility(false);
|
||||
}
|
||||
|
@ -126,24 +122,22 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
setErrorByKey("invalidUrl");
|
||||
return;
|
||||
}
|
||||
if (!getExtraFieldsVisibility()) {
|
||||
if (myLink == null) {
|
||||
loadInfoByUri(uri);
|
||||
} else if (isEmptyString(title)) {
|
||||
setErrorByKey("titleIsEmpty");
|
||||
} else {
|
||||
startActivity(
|
||||
new Intent(
|
||||
NetworkLibraryActivity.ADD_CATALOG,
|
||||
uri,
|
||||
AddCustomCatalogActivity.this,
|
||||
NetworkLibraryActivity.class
|
||||
)
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_TITLE_KEY, title)
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_SUMMARY_KEY, summary)
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_ICON_KEY, myIcon)
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_ID_KEY, myCatalogId)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
);
|
||||
myLink.setTitle(title);
|
||||
myLink.setSummary(summary);
|
||||
|
||||
Intent intent = new Intent(
|
||||
NetworkLibraryActivity.ADD_CATALOG,
|
||||
uri,
|
||||
AddCustomCatalogActivity.this,
|
||||
NetworkLibraryActivity.class
|
||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
NetworkLibraryActivity.addLinkToIntent(intent, myLink);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@ -152,10 +146,6 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
return s == null || s.length() == 0;
|
||||
}
|
||||
|
||||
private boolean getExtraFieldsVisibility() {
|
||||
return findViewById(R.id.add_custom_catalog_title_group).getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
private void setExtraFieldsVisibility(boolean show) {
|
||||
final int visibility = show ? View.VISIBLE : View.GONE;
|
||||
runOnUiThread(new Runnable() {
|
||||
|
@ -253,8 +243,11 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
if (siteName.startsWith("www.")) {
|
||||
siteName = siteName.substring(4);
|
||||
}
|
||||
final ICustomNetworkLink link =
|
||||
OPDSLinkReader.createCustomLink(siteName, null, null, null, textUrl);
|
||||
final HashMap<String,UrlInfo> infos = new HashMap<String,UrlInfo>();
|
||||
infos.put(INetworkLink.URL_MAIN, new UrlInfo(textUrl));
|
||||
myLink = OPDSLinkReader.createCustomLink(
|
||||
ICustomNetworkLink.INVALID_ID, siteName, null, null, null, infos
|
||||
);
|
||||
|
||||
final Runnable loadInfoRunnable = new Runnable() {
|
||||
private String myError;
|
||||
|
@ -262,20 +255,19 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
public void run() {
|
||||
try {
|
||||
myError = null;
|
||||
link.reloadInfo();
|
||||
myLink.reloadInfo();
|
||||
} catch (ZLNetworkException e) {
|
||||
myError = e.getMessage();
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (myError == null) {
|
||||
setTextById(R.id.add_custom_catalog_title, link.getTitle());
|
||||
setTextById(R.id.add_custom_catalog_summary, link.getSummary());
|
||||
myIcon = link.getIcon();
|
||||
setTextById(R.id.add_custom_catalog_title, myLink.getTitle());
|
||||
setTextById(R.id.add_custom_catalog_summary, myLink.getSummary());
|
||||
setExtraFieldsVisibility(true);
|
||||
} else {
|
||||
runErrorDialog(myError);
|
||||
myIcon = null;
|
||||
myLink = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -248,19 +248,12 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
|||
return true;
|
||||
case CUSTOM_CATALOG_EDIT:
|
||||
{
|
||||
final ICustomNetworkLink link =
|
||||
(ICustomNetworkLink)((NetworkCatalogTree)tree).Item.Link;
|
||||
final String textUrl = link.getUrlInfo(INetworkLink.URL_MAIN).URL;
|
||||
if (textUrl != null) {
|
||||
activity.startActivity(
|
||||
new Intent(activity, AddCustomCatalogActivity.class)
|
||||
.setData(Uri.parse(textUrl))
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_TITLE_KEY, link.getTitle())
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_SUMMARY_KEY, link.getSummary())
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_ICON_KEY, link.getIcon())
|
||||
.putExtra(NetworkLibraryActivity.ADD_CATALOG_ID_KEY, link.getId())
|
||||
);
|
||||
}
|
||||
final Intent intent = new Intent(activity, AddCustomCatalogActivity.class);
|
||||
NetworkLibraryActivity.addLinkToIntent(
|
||||
intent,
|
||||
(ICustomNetworkLink)((NetworkCatalogTree)tree).Item.Link
|
||||
);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
case CUSTOM_CATALOG_REMOVE:
|
||||
|
|
|
@ -39,19 +39,43 @@ import org.geometerplus.zlibrary.ui.android.R;
|
|||
|
||||
import org.geometerplus.android.util.UIUtil;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSLinkReader;
|
||||
|
||||
public class NetworkLibraryActivity extends NetworkBaseActivity {
|
||||
final static String ADD_CATALOG = "android.fbreader.action.ADD_CATALOG";
|
||||
static final String ADD_CATALOG = "android.fbreader.action.ADD_CATALOG";
|
||||
|
||||
final static String ADD_CATALOG_TITLE_KEY = "title";
|
||||
final static String ADD_CATALOG_SUMMARY_KEY = "summary";
|
||||
final static String ADD_CATALOG_ICON_KEY = "icon";
|
||||
final static String ADD_CATALOG_ID_KEY = "id";
|
||||
final static String ADD_CATALOG_URLS_BUNDLE_KEY = "urls";
|
||||
private static final String ADD_CATALOG_TITLE_KEY = "title";
|
||||
private static final String ADD_CATALOG_SUMMARY_KEY = "summary";
|
||||
private static final String ADD_CATALOG_ICON_KEY = "icon";
|
||||
private static final String ADD_CATALOG_ID_KEY = "id";
|
||||
private static final String ADD_CATALOG_URLS_MAP_KEY = "urls";
|
||||
|
||||
static void addLinkToIntent(Intent intent, ICustomNetworkLink link) {
|
||||
final String textUrl = link.getUrlInfo(INetworkLink.URL_MAIN).URL;
|
||||
intent.setData(Uri.parse(textUrl));
|
||||
intent
|
||||
.putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle())
|
||||
.putExtra(ADD_CATALOG_SUMMARY_KEY, link.getSummary())
|
||||
.putExtra(ADD_CATALOG_ICON_KEY, link.getIcon())
|
||||
.putExtra(ADD_CATALOG_ID_KEY, link.getId())
|
||||
.putExtra(ADD_CATALOG_URLS_MAP_KEY, link.urlInfoMap());
|
||||
}
|
||||
|
||||
static ICustomNetworkLink getLinkFromIntent(Intent intent) {
|
||||
final Uri uri = intent.getData();
|
||||
if (uri == null || !intent.hasExtra(ADD_CATALOG_ID_KEY)) {
|
||||
return null;
|
||||
}
|
||||
return OPDSLinkReader.createCustomLink(
|
||||
intent.getIntExtra(ADD_CATALOG_ID_KEY, ICustomNetworkLink.INVALID_ID),
|
||||
uri.getHost(),
|
||||
intent.getStringExtra(ADD_CATALOG_TITLE_KEY),
|
||||
intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY),
|
||||
intent.getStringExtra(ADD_CATALOG_ICON_KEY),
|
||||
(HashMap<String,UrlInfo>)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY)
|
||||
);
|
||||
}
|
||||
|
||||
private NetworkTree myTree;
|
||||
private volatile Intent myIntent;
|
||||
|
@ -74,19 +98,9 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
}
|
||||
|
||||
private void processIntent(Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (ADD_CATALOG.equals(action)) {
|
||||
final Uri uri = intent.getData();
|
||||
final String title = intent.getStringExtra(ADD_CATALOG_TITLE_KEY);
|
||||
final String summary = intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY);
|
||||
final String icon = intent.getStringExtra(ADD_CATALOG_ICON_KEY);
|
||||
final int id = intent.getIntExtra(ADD_CATALOG_ID_KEY, ICustomNetworkLink.INVALID_ID);
|
||||
if (uri == null || title == null) {
|
||||
return;
|
||||
}
|
||||
final ICustomNetworkLink link = OPDSLinkReader.createCustomLink(
|
||||
id, uri.getHost(), title, summary, icon, uri.toString()
|
||||
);
|
||||
if (ADD_CATALOG.equals(intent.getAction())) {
|
||||
final ICustomNetworkLink link = getLinkFromIntent(intent);
|
||||
System.err.println("LINK = " + link);
|
||||
if (link != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
|
|
|
@ -90,10 +90,12 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
|||
@Override
|
||||
public String toString() {
|
||||
String icon = myIcon;
|
||||
if (icon.length() > 64) {
|
||||
icon = icon.substring(0, 61) + "...";
|
||||
if (icon != null) {
|
||||
if (icon.length() > 64) {
|
||||
icon = icon.substring(0, 61) + "...";
|
||||
}
|
||||
icon = icon.replaceAll("\n", "");
|
||||
}
|
||||
icon = icon.replaceAll("\n", "");
|
||||
return "AbstractNetworkLink: {"
|
||||
+ "siteName=" + mySiteName
|
||||
+ "; title=" + myTitle
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.geometerplus.fbreader.network;
|
|||
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface ICustomNetworkLink extends INetworkLink {
|
||||
public static final int INVALID_ID = -1;
|
||||
|
||||
|
@ -32,6 +34,7 @@ public interface ICustomNetworkLink extends INetworkLink {
|
|||
void setSummary(String summary);
|
||||
void setIcon(String icon);
|
||||
|
||||
HashMap<String,UrlInfo> urlInfoMap();
|
||||
void setUrl(String urlKey, String url);
|
||||
void removeUrl(String urlKey);
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ public interface INetworkLink {
|
|||
String getSummary();
|
||||
String getIcon();
|
||||
|
||||
HashMap<String,UrlInfo> urlInfoMap();
|
||||
UrlInfo getUrlInfo(String urlKey);
|
||||
Set<String> getUrlKeys();
|
||||
|
||||
|
|
|
@ -180,8 +180,12 @@ public class NetworkLibrary {
|
|||
new NetworkDatabase.ICustomLinksHandler() {
|
||||
public void handleCustomLinkData(int id, String siteName,
|
||||
String title, String summary, String icon, Map<String,UrlInfo> infos) {
|
||||
final ICustomNetworkLink link = OPDSLinkReader.createCustomLink(id, siteName, title, summary, icon, infos);
|
||||
if (link != null) {
|
||||
if (title != null &&
|
||||
siteName != null &&
|
||||
infos.get(INetworkLink.URL_MAIN) != null) {
|
||||
final ICustomNetworkLink link = OPDSLinkReader.createCustomLink(
|
||||
id, siteName, title, summary, icon, infos
|
||||
);
|
||||
addLinkInternal(link);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,22 +40,9 @@ public class OPDSLinkReader {
|
|||
static final String CATALOGS_URL = "http://data.fbreader.org/catalogs/generic-1.2.xml";
|
||||
|
||||
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,UrlInfo> infos) {
|
||||
if (siteName == null || title == null || infos.get(INetworkLink.URL_MAIN) == null) {
|
||||
return null;
|
||||
}
|
||||
return new OPDSCustomLink(id, siteName, title, summary, icon, infos);
|
||||
}
|
||||
|
||||
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, String url) {
|
||||
final HashMap<String,UrlInfo> infos = new HashMap<String,UrlInfo>();
|
||||
infos.put(INetworkLink.URL_MAIN, new UrlInfo(url));
|
||||
return new OPDSCustomLink(id, siteName, title, summary, icon, infos);
|
||||
}
|
||||
|
||||
public static ICustomNetworkLink createCustomLink(String siteName, String title, String summary, String icon, String url) {
|
||||
return createCustomLink(ICustomNetworkLink.INVALID_ID, siteName, title, summary, icon, url);
|
||||
}
|
||||
|
||||
public static final int CACHE_LOAD = 0;
|
||||
public static final int CACHE_UPDATE = 1;
|
||||
public static final int CACHE_CLEAR = 2;
|
||||
|
|
|
@ -127,6 +127,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
System.err.println("URL = " + url);
|
||||
try {
|
||||
pattern = URLEncoder.encode(pattern, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue