1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

custom links search; custom links update

This commit is contained in:
Nikolay Pultsin 2011-03-04 22:23:23 +00:00
parent 34119928a0
commit c5f9ea0bd4
5 changed files with 41 additions and 12 deletions

View file

@ -4,6 +4,8 @@
* opds:// URLs support has been implemented * opds:// URLs support has been implemented
* Unexpected search call has been fixed * Unexpected search call has been fixed
* Ignore case comparison for zip entry names * Ignore case comparison for zip entry names
* Fixed custom OPDS link search
* Periodical update of custom links information has been added
===== 0.99.13 (Feb 13, 2011) ===== ===== 0.99.13 (Feb 13, 2011) =====
* Fixed book/position forgetting bug * Fixed book/position forgetting bug

View file

@ -85,7 +85,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
final String summary = cursor.getString(3); final String summary = cursor.getString(3);
linksMap.clear(); linksMap.clear();
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE url NOT NULL AND link_id = " + id, null); final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + id, null);
while (linksCursor.moveToNext()) { while (linksCursor.moveToNext()) {
linksMap.put( linksMap.put(
linksCursor.getString(0), linksCursor.getString(0),
@ -141,10 +141,10 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
link.setId((int) id); link.setId((int) id);
} else { } else {
id = link.getId(); id = link.getId();
statement.bindLong(5, id); statement.bindLong(4, id);
statement.execute(); statement.execute();
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE url NOT NULL AND link_id = " + link.getId(), null); final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + link.getId(), null);
while (linksCursor.moveToNext()) { while (linksCursor.moveToNext()) {
linksMap.put( linksMap.put(
linksCursor.getString(0), linksCursor.getString(0),

View file

@ -37,6 +37,7 @@ public interface ICustomNetworkLink extends INetworkLink {
void setUrl(String urlKey, String url); void setUrl(String urlKey, String url);
void removeUrl(String urlKey); void removeUrl(String urlKey);
boolean isObsolete(long milliSeconds);
void reloadInfo(boolean urlsOnly) throws ZLNetworkException; void reloadInfo(boolean urlsOnly) throws ZLNetworkException;
// returns true if next methods have changed link's data: // returns true if next methods have changed link's data:

View file

@ -244,6 +244,15 @@ public class NetworkLibrary {
} }
} }
} }
for (INetworkLink link : myLinks) {
if (link instanceof ICustomNetworkLink) {
final ICustomNetworkLink customLink = (ICustomNetworkLink)link;
if (customLink.isObsolete(12 * 60 * 60 * 1000)) { // 12 hours
customLink.reloadInfo(true);
NetworkDatabase.Instance().saveCustomLink(customLink);
}
}
}
} }
} }
@ -253,12 +262,11 @@ public class NetworkLibrary {
// synchronize() method MUST be called after this method // synchronize() method MUST be called after this method
public void finishBackgroundUpdate() { public void finishBackgroundUpdate() {
synchronized (myBackgroundLock) { synchronized (myBackgroundLock) {
if (myBackgroundLinks == null) {
return;
}
synchronized (myLinks) { synchronized (myLinks) {
if (myBackgroundLinks != null) {
removeAllLoadedLinks(); removeAllLoadedLinks();
myLinks.addAll(myBackgroundLinks); myLinks.addAll(myBackgroundLinks);
}
invalidateChildren(); invalidateChildren();
} }
} }

View file

@ -85,13 +85,29 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
myHasChanges = myHasChanges || oldUrl != null; myHasChanges = myHasChanges || oldUrl != null;
} }
public void reloadInfo(boolean urlsOnly) throws ZLNetworkException { public boolean isObsolete(long milliSeconds) {
final long old = System.currentTimeMillis() - milliSeconds;
final Date searchUpdateDate = getUrlInfo(URL_SEARCH).Updated;
if (searchUpdateDate == null || searchUpdateDate.getTime() < old) {
return true;
}
final Date iconUpdateDate = getUrlInfo(URL_ICON).Updated;
if (iconUpdateDate == null || iconUpdateDate.getTime() < old) {
return true;
}
return false;
}
public void reloadInfo(final boolean urlsOnly) throws ZLNetworkException {
final LinkedList<String> opensearchDescriptionURLs = new LinkedList<String>(); final LinkedList<String> opensearchDescriptionURLs = new LinkedList<String>();
final List<OpenSearchDescription> descriptions = Collections.synchronizedList(new LinkedList<OpenSearchDescription>()); final List<OpenSearchDescription> descriptions = Collections.synchronizedList(new LinkedList<OpenSearchDescription>());
ZLNetworkException error = null; ZLNetworkException error = null;
try { try {
ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(INetworkLink.URL_MAIN).URL) { ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(URL_MAIN).URL) {
@Override @Override
public void handleStream(URLConnection connection, InputStream inputStream) throws IOException, ZLNetworkException { public void handleStream(URLConnection connection, InputStream inputStream) throws IOException, ZLNetworkException {
final CatalogInfoReader info = new CatalogInfoReader(URL, OPDSCustomLink.this, opensearchDescriptionURLs); final CatalogInfoReader info = new CatalogInfoReader(URL, OPDSCustomLink.this, opensearchDescriptionURLs);
@ -103,12 +119,14 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
if (info.Title == null) { if (info.Title == null) {
throw new ZLNetworkException(NetworkException.ERROR_NO_REQUIRED_INFORMATION); throw new ZLNetworkException(NetworkException.ERROR_NO_REQUIRED_INFORMATION);
} }
myTitle = info.Title;
setUrl(URL_ICON, info.Icon); setUrl(URL_ICON, info.Icon);
mySummary = info.Summary;
if (info.DirectOpenSearchDescription != null) { if (info.DirectOpenSearchDescription != null) {
descriptions.add(info.DirectOpenSearchDescription); descriptions.add(info.DirectOpenSearchDescription);
} }
if (!urlsOnly) {
myTitle = info.Title;
mySummary = info.Summary;
}
} }
}); });
} catch (ZLNetworkException e) { } catch (ZLNetworkException e) {