mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
'updated' field for all INetworkLink urls has been introduced
This commit is contained in:
parent
7c679882f4
commit
dad7b7e8e4
14 changed files with 97 additions and 89 deletions
|
@ -250,7 +250,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
{
|
{
|
||||||
final ICustomNetworkLink link =
|
final ICustomNetworkLink link =
|
||||||
(ICustomNetworkLink)((NetworkCatalogTree)tree).Item.Link;
|
(ICustomNetworkLink)((NetworkCatalogTree)tree).Item.Link;
|
||||||
final String textUrl = link.getLink(INetworkLink.URL_MAIN);
|
final String textUrl = link.getUrlInfo(INetworkLink.URL_MAIN).URL;
|
||||||
if (textUrl != null) {
|
if (textUrl != null) {
|
||||||
activity.startActivity(
|
activity.startActivity(
|
||||||
new Intent(activity, AddCustomCatalogActivity.class)
|
new Intent(activity, AddCustomCatalogActivity.class)
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||||
import org.geometerplus.fbreader.network.NetworkDatabase;
|
import org.geometerplus.fbreader.network.NetworkDatabase;
|
||||||
|
import org.geometerplus.fbreader.network.URLInfo;
|
||||||
|
|
||||||
import org.geometerplus.android.util.SQLiteUtil;
|
import org.geometerplus.android.util.SQLiteUtil;
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
||||||
@Override
|
@Override
|
||||||
protected void loadCustomLinks(ICustomLinksHandler handler) {
|
protected void loadCustomLinks(ICustomLinksHandler handler) {
|
||||||
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary,icon FROM CustomLinks", null);
|
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary,icon FROM CustomLinks", null);
|
||||||
final HashMap<String,String> linksMap = new HashMap<String,String>();
|
final HashMap<String,URLInfo> linksMap = new HashMap<String,URLInfo>();
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
final int id = cursor.getInt(0);
|
final int id = cursor.getInt(0);
|
||||||
final String title = cursor.getString(1);
|
final String title = cursor.getString(1);
|
||||||
|
@ -83,9 +84,15 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
||||||
final String icon = cursor.getString(4);
|
final String icon = cursor.getString(4);
|
||||||
|
|
||||||
linksMap.clear();
|
linksMap.clear();
|
||||||
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url FROM LinkUrls WHERE url NOT NULL AND link_id = " + id, null);
|
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE url NOT NULL AND link_id = " + id, null);
|
||||||
while (linksCursor.moveToNext()) {
|
while (linksCursor.moveToNext()) {
|
||||||
linksMap.put(linksCursor.getString(0), linksCursor.getString(1));
|
linksMap.put(
|
||||||
|
linksCursor.getString(0),
|
||||||
|
new URLInfo(
|
||||||
|
linksCursor.getString(1),
|
||||||
|
SQLiteUtil.getDate(linksCursor, 2)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
linksCursor.close();
|
linksCursor.close();
|
||||||
|
|
||||||
|
@ -127,7 +134,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
||||||
SQLiteUtil.bindString(statement, 4, link.getIcon());
|
SQLiteUtil.bindString(statement, 4, link.getIcon());
|
||||||
|
|
||||||
final long id;
|
final long id;
|
||||||
final HashMap<String,String> linksMap = new HashMap<String,String>();
|
final HashMap<String,URLInfo> linksMap = new HashMap<String,URLInfo>();
|
||||||
|
|
||||||
if (statement == myInsertCustomLinkStatement) {
|
if (statement == myInsertCustomLinkStatement) {
|
||||||
id = statement.executeInsert();
|
id = statement.executeInsert();
|
||||||
|
@ -137,35 +144,42 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
||||||
statement.bindLong(5, id);
|
statement.bindLong(5, id);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
|
||||||
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url 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 url NOT NULL AND link_id = " + link.getId(), null);
|
||||||
while (linksCursor.moveToNext()) {
|
while (linksCursor.moveToNext()) {
|
||||||
linksMap.put(linksCursor.getString(0), linksCursor.getString(1));
|
linksMap.put(
|
||||||
|
linksCursor.getString(0),
|
||||||
|
new URLInfo(
|
||||||
|
linksCursor.getString(1),
|
||||||
|
SQLiteUtil.getDate(linksCursor, 2)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
linksCursor.close();
|
linksCursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String key: link.getLinkKeys()) {
|
for (String key : link.getUrlKeys()) {
|
||||||
final String value = link.getLink(key);
|
final URLInfo info = link.getUrlInfo(key);
|
||||||
final String dbValue = linksMap.remove(key);
|
final URLInfo dbInfo = linksMap.remove(key);
|
||||||
final SQLiteStatement urlStatement;
|
final SQLiteStatement urlStatement;
|
||||||
if (dbValue == null) {
|
if (dbInfo == null) {
|
||||||
if (myInsertCustomLinkUrlStatement == null) {
|
if (myInsertCustomLinkUrlStatement == null) {
|
||||||
myInsertCustomLinkUrlStatement = myDatabase.compileStatement(
|
myInsertCustomLinkUrlStatement = myDatabase.compileStatement(
|
||||||
"INSERT OR REPLACE INTO LinkUrls(url,link_id,key) VALUES (?,?,?)");
|
"INSERT OR REPLACE INTO LinkUrls(url,update_time,link_id,key) VALUES (?,?,?,?)");
|
||||||
}
|
}
|
||||||
urlStatement = myInsertCustomLinkUrlStatement;
|
urlStatement = myInsertCustomLinkUrlStatement;
|
||||||
} else if (!value.equals(dbValue)) {
|
} else if (!info.equals(dbInfo)) {
|
||||||
if (myUpdateCustomLinkUrlStatement == null) {
|
if (myUpdateCustomLinkUrlStatement == null) {
|
||||||
myUpdateCustomLinkUrlStatement = myDatabase.compileStatement(
|
myUpdateCustomLinkUrlStatement = myDatabase.compileStatement(
|
||||||
"UPDATE LinkUrls SET url = ? WHERE link_id = ? AND key = ?");
|
"UPDATE LinkUrls SET url = ?, update_time = ? WHERE link_id = ? AND key = ?");
|
||||||
}
|
}
|
||||||
urlStatement = myUpdateCustomLinkUrlStatement;
|
urlStatement = myUpdateCustomLinkUrlStatement;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
urlStatement.bindString(1, value);
|
SQLiteUtil.bindString(urlStatement, 1, info.URL);
|
||||||
urlStatement.bindLong(2, id);
|
SQLiteUtil.bindDate(urlStatement, 2, info.Updated);
|
||||||
urlStatement.bindString(3, key);
|
urlStatement.bindLong(3, id);
|
||||||
|
urlStatement.bindString(4, key);
|
||||||
urlStatement.execute();
|
urlStatement.execute();
|
||||||
}
|
}
|
||||||
for (String key: linksMap.keySet()) {
|
for (String key: linksMap.keySet()) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
return testService(
|
return testService(
|
||||||
activity,
|
activity,
|
||||||
REGISTRATION_ACTION,
|
REGISTRATION_ACTION,
|
||||||
link.getLink(INetworkLink.URL_SIGN_UP)
|
link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
try {
|
try {
|
||||||
final Intent intent = new Intent(
|
final Intent intent = new Intent(
|
||||||
REGISTRATION_ACTION,
|
REGISTRATION_ACTION,
|
||||||
Uri.parse(link.getLink(INetworkLink.URL_SIGN_UP))
|
Uri.parse(link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL)
|
||||||
);
|
);
|
||||||
if (PackageUtil.canBeStarted(activity, intent)) {
|
if (PackageUtil.canBeStarted(activity, intent)) {
|
||||||
activity.startActivityForResult(new Intent(
|
activity.startActivityForResult(new Intent(
|
||||||
REGISTRATION_ACTION,
|
REGISTRATION_ACTION,
|
||||||
Uri.parse(link.getLink(INetworkLink.URL_SIGN_UP))
|
Uri.parse(link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL)
|
||||||
), USER_REGISTRATION_REQUEST_CODE);
|
), USER_REGISTRATION_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
|
@ -93,7 +93,7 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
return testService(
|
return testService(
|
||||||
activity,
|
activity,
|
||||||
SMS_REFILLING_ACTION,
|
SMS_REFILLING_ACTION,
|
||||||
link.getLink(INetworkLink.URL_MAIN)
|
link.getUrlInfo(INetworkLink.URL_MAIN).URL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
try {
|
try {
|
||||||
final Intent intent = new Intent(
|
final Intent intent = new Intent(
|
||||||
SMS_REFILLING_ACTION,
|
SMS_REFILLING_ACTION,
|
||||||
Uri.parse(link.getLink(INetworkLink.URL_MAIN))
|
Uri.parse(link.getUrlInfo(INetworkLink.URL_MAIN).URL)
|
||||||
);
|
);
|
||||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||||
if (mgr != null) {
|
if (mgr != null) {
|
||||||
|
@ -117,7 +117,7 @@ abstract class Util implements UserRegistrationConstants {
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isBrowserAccountRefillingSupported(Activity activity, INetworkLink link) {
|
static boolean isBrowserAccountRefillingSupported(Activity activity, INetworkLink link) {
|
||||||
return link.getLink(INetworkLink.URL_REFILL_ACCOUNT) != null;
|
return link.getUrlInfo(INetworkLink.URL_REFILL_ACCOUNT).URL != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void openInBrowser(Context context, String url) {
|
static void openInBrowser(Context context, String url) {
|
||||||
|
|
|
@ -19,9 +19,7 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.network;
|
package org.geometerplus.fbreader.network;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
||||||
|
|
||||||
|
@ -31,7 +29,7 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
||||||
protected String mySummary;
|
protected String mySummary;
|
||||||
protected String myIcon;
|
protected String myIcon;
|
||||||
protected final String myLanguage;
|
protected final String myLanguage;
|
||||||
protected final TreeMap<String, String> myLinks;
|
protected final TreeMap<String,URLInfo> myInfos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new NetworkLink instance.
|
* Creates new NetworkLink instance.
|
||||||
|
@ -41,15 +39,15 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
||||||
* @param summary description of the corresponding library item. Can be <code>null</code>.
|
* @param summary description of the corresponding library item. Can be <code>null</code>.
|
||||||
* @param icon string contains link's icon data/url. Can be <code>null</code>.
|
* @param icon string contains link's icon data/url. Can be <code>null</code>.
|
||||||
* @param language language of the catalog. If <code>null</code> we assume this catalog is multilanguage.
|
* @param language language of the catalog. If <code>null</code> we assume this catalog is multilanguage.
|
||||||
* @param links map contains URLs with their identifiers; must always contain one URL with <code>URL_MAIN</code> identifier
|
* @param infos map contains URL infos with their identifiers; must always contain one URL with <code>URL_MAIN</code> identifier
|
||||||
*/
|
*/
|
||||||
public AbstractNetworkLink(String siteName, String title, String summary, String icon, String language, Map<String, String> links) {
|
public AbstractNetworkLink(String siteName, String title, String summary, String icon, String language, Map<String,URLInfo> infos) {
|
||||||
mySiteName = siteName;
|
mySiteName = siteName;
|
||||||
myTitle = title;
|
myTitle = title;
|
||||||
mySummary = summary;
|
mySummary = summary;
|
||||||
myIcon = icon;
|
myIcon = icon;
|
||||||
myLanguage = language != null ? language : "multi";
|
myLanguage = language != null ? language : "multi";
|
||||||
myLinks = new TreeMap<String, String>(links);
|
myInfos = new TreeMap<String,URLInfo>(infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getSiteName() {
|
public final String getSiteName() {
|
||||||
|
@ -72,12 +70,13 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
||||||
return myLanguage;
|
return myLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getLink(String urlKey) {
|
public final URLInfo getUrlInfo(String urlKey) {
|
||||||
return myLinks.get(urlKey);
|
final URLInfo info = myInfos.get(urlKey);
|
||||||
|
return info != null ? info : URLInfo.NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Set<String> getLinkKeys() {
|
public final Set<String> getUrlKeys() {
|
||||||
return myLinks.keySet();
|
return myInfos.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkOperationData createOperationData(NetworkOperationData.OnNewItemListener listener) {
|
public NetworkOperationData createOperationData(NetworkOperationData.OnNewItemListener listener) {
|
||||||
|
@ -96,7 +95,7 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
||||||
+ "; title=" + myTitle
|
+ "; title=" + myTitle
|
||||||
+ "; summary=" + mySummary
|
+ "; summary=" + mySummary
|
||||||
+ "; icon=" + icon
|
+ "; icon=" + icon
|
||||||
+ "; links=" + myLinks
|
+ "; infos=" + myInfos
|
||||||
+ "}";
|
+ "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +113,7 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
||||||
|| !myTitle.equals(lnk.myTitle)
|
|| !myTitle.equals(lnk.myTitle)
|
||||||
|| !ZLMiscUtil.equals(mySummary, lnk.mySummary)
|
|| !ZLMiscUtil.equals(mySummary, lnk.mySummary)
|
||||||
|| !ZLMiscUtil.equals(myIcon, lnk.myIcon)
|
|| !ZLMiscUtil.equals(myIcon, lnk.myIcon)
|
||||||
|| !ZLMiscUtil.mapsEquals(myLinks, lnk.myLinks)) {
|
|| !ZLMiscUtil.mapsEquals(myInfos, lnk.myInfos)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -32,8 +32,8 @@ public interface ICustomNetworkLink extends INetworkLink {
|
||||||
void setSummary(String summary);
|
void setSummary(String summary);
|
||||||
void setIcon(String icon);
|
void setIcon(String icon);
|
||||||
|
|
||||||
void setLink(String urlKey, String url);
|
void setUrl(String urlKey, String url);
|
||||||
void removeLink(String urlKey);
|
void removeUrl(String urlKey);
|
||||||
|
|
||||||
void reloadInfo() throws ZLNetworkException;
|
void reloadInfo() throws ZLNetworkException;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationMan
|
||||||
|
|
||||||
|
|
||||||
public interface INetworkLink {
|
public interface INetworkLink {
|
||||||
|
|
||||||
String URL_MAIN = "main";
|
String URL_MAIN = "main";
|
||||||
String URL_SEARCH = "search";
|
String URL_SEARCH = "search";
|
||||||
String URL_SIGN_IN = "signIn";
|
String URL_SIGN_IN = "signIn";
|
||||||
|
@ -41,15 +40,15 @@ public interface INetworkLink {
|
||||||
String getTitle();
|
String getTitle();
|
||||||
String getSummary();
|
String getSummary();
|
||||||
String getIcon();
|
String getIcon();
|
||||||
String getLink(String urlKey);
|
|
||||||
|
URLInfo getUrlInfo(String urlKey);
|
||||||
|
Set<String> getUrlKeys();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 2-letters language code or special token "multi"
|
* @return 2-letters language code or special token "multi"
|
||||||
*/
|
*/
|
||||||
String getLanguage();
|
String getLanguage();
|
||||||
|
|
||||||
Set<String> getLinkKeys();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param listener Network operation listener
|
* @param listener Network operation listener
|
||||||
* @return instance, which represents the state of the network operation.
|
* @return instance, which represents the state of the network operation.
|
||||||
|
|
|
@ -35,7 +35,7 @@ public abstract class NetworkDatabase {
|
||||||
protected abstract void executeAsATransaction(Runnable actions);
|
protected abstract void executeAsATransaction(Runnable actions);
|
||||||
|
|
||||||
public interface ICustomLinksHandler {
|
public interface ICustomLinksHandler {
|
||||||
void handleCustomLinkData(int id, String siteName, String title, String summary, String icon, Map<String, String> links);
|
void handleCustomLinkData(int id, String siteName, String title, String summary, String icon, Map<String,URLInfo> infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void loadCustomLinks(ICustomLinksHandler handler);
|
protected abstract void loadCustomLinks(ICustomLinksHandler handler);
|
||||||
|
|
|
@ -179,8 +179,8 @@ public class NetworkLibrary {
|
||||||
db.loadCustomLinks(
|
db.loadCustomLinks(
|
||||||
new NetworkDatabase.ICustomLinksHandler() {
|
new NetworkDatabase.ICustomLinksHandler() {
|
||||||
public void handleCustomLinkData(int id, String siteName,
|
public void handleCustomLinkData(int id, String siteName,
|
||||||
String title, String summary, String icon, Map<String, String> links) {
|
String title, String summary, String icon, Map<String,URLInfo> infos) {
|
||||||
final ICustomNetworkLink link = OPDSLinkReader.createCustomLink(id, siteName, title, summary, icon, links);
|
final ICustomNetworkLink link = OPDSLinkReader.createCustomLink(id, siteName, title, summary, icon, infos);
|
||||||
if (link != null) {
|
if (link != null) {
|
||||||
addLinkInternal(link);
|
addLinkInternal(link);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.Serializable;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.constants.MimeTypes;
|
import org.geometerplus.zlibrary.core.constants.MimeTypes;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
|
@ -50,10 +51,7 @@ public abstract class NetworkTree extends FBTree {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final NetworkTree.Key key = (NetworkTree.Key)other;
|
final NetworkTree.Key key = (NetworkTree.Key)other;
|
||||||
if (Parent == null) {
|
return Id.equals(key.Id) && ZLMiscUtil.equals(Parent, key.Parent);
|
||||||
return key.Parent == null && Id.equals(key.Id);
|
|
||||||
}
|
|
||||||
return Id.equals(key.Id) && Parent.equals(key.Parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
sid = mySidOption.getValue();
|
sid = mySidOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = Link.getLink(INetworkLink.URL_SIGN_IN);
|
String url = Link.getUrlInfo(INetworkLink.URL_SIGN_IN).URL;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void authorise(String password) throws ZLNetworkException {
|
public void authorise(String password) throws ZLNetworkException {
|
||||||
String url = Link.getLink(INetworkLink.URL_SIGN_IN);
|
String url = Link.getUrlInfo(INetworkLink.URL_SIGN_IN).URL;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
if (sid.length() == 0) {
|
if (sid.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final String url = Link.getLink(INetworkLink.URL_REFILL_ACCOUNT);
|
final String url = Link.getUrlInfo(INetworkLink.URL_REFILL_ACCOUNT).URL;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recoverPassword(String email) throws ZLNetworkException {
|
public void recoverPassword(String email) throws ZLNetworkException {
|
||||||
String url = Link.getLink(INetworkLink.URL_RECOVER_PASSWORD);
|
String url = Link.getUrlInfo(INetworkLink.URL_RECOVER_PASSWORD).URL;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,15 @@ import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
||||||
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||||
import org.geometerplus.fbreader.network.INetworkLink;
|
import org.geometerplus.fbreader.network.INetworkLink;
|
||||||
import org.geometerplus.fbreader.network.NetworkException;
|
import org.geometerplus.fbreader.network.NetworkException;
|
||||||
|
import org.geometerplus.fbreader.network.URLInfo;
|
||||||
|
|
||||||
class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
||||||
private int myId;
|
private int myId;
|
||||||
|
|
||||||
private boolean myHasChanges;
|
private boolean myHasChanges;
|
||||||
|
|
||||||
OPDSCustomLink(int id, String siteName, String title, String summary, String icon, Map<String, String> links) {
|
OPDSCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,URLInfo> infos) {
|
||||||
super(siteName, title, summary, icon, null, links, false);
|
super(siteName, title, summary, icon, null, infos, false);
|
||||||
myId = id;
|
myId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,17 +81,13 @@ class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
||||||
myTitle = title;
|
myTitle = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setLink(String urlKey, String url) {
|
public final void setUrl(String urlKey, String url) {
|
||||||
if (url == null) {
|
myInfos.put(urlKey, new URLInfo(url, new Date()));
|
||||||
removeLink(urlKey);
|
myHasChanges = true;
|
||||||
} else {
|
|
||||||
final String oldUrl = myLinks.put(urlKey, url);
|
|
||||||
myHasChanges = myHasChanges || !url.equals(oldUrl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void removeLink(String urlKey) {
|
public final void removeUrl(String urlKey) {
|
||||||
final String oldUrl = myLinks.remove(urlKey);
|
final URLInfo oldUrl = myInfos.remove(urlKey);
|
||||||
myHasChanges = myHasChanges || oldUrl != null;
|
myHasChanges = myHasChanges || oldUrl != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +98,7 @@ class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
||||||
|
|
||||||
ZLNetworkException error = null;
|
ZLNetworkException error = null;
|
||||||
try {
|
try {
|
||||||
ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getLink(INetworkLink.URL_MAIN)) {
|
ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(INetworkLink.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);
|
||||||
|
@ -151,7 +148,7 @@ class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
||||||
|
|
||||||
if (!descriptions.isEmpty()) {
|
if (!descriptions.isEmpty()) {
|
||||||
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
|
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
|
||||||
setLink(URL_SEARCH, descriptions.get(0).makeQuery("%s"));
|
setUrl(URL_SEARCH, descriptions.get(0).makeQuery("%s"));
|
||||||
}
|
}
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -39,17 +39,17 @@ import org.geometerplus.fbreader.network.atom.ATOMUpdated;
|
||||||
public class OPDSLinkReader {
|
public class OPDSLinkReader {
|
||||||
static final String CATALOGS_URL = "http://data.fbreader.org/catalogs/generic-1.2.xml";
|
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, String> links) {
|
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,URLInfo> infos) {
|
||||||
if (siteName == null || title == null || links.get(INetworkLink.URL_MAIN) == null) {
|
if (siteName == null || title == null || infos.get(INetworkLink.URL_MAIN) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new OPDSCustomLink(id, siteName, title, summary, icon, links);
|
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) {
|
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, String url) {
|
||||||
final HashMap<String, String> links = new HashMap<String, String>();
|
final HashMap<String,URLInfo> infos = new HashMap<String,URLInfo>();
|
||||||
links.put(INetworkLink.URL_MAIN, url);
|
infos.put(INetworkLink.URL_MAIN, new URLInfo(url));
|
||||||
return new OPDSCustomLink(id, siteName, title, summary, icon, links);
|
return new OPDSCustomLink(id, siteName, title, summary, icon, infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICustomNetworkLink createCustomLink(String siteName, String title, String summary, String icon, String url) {
|
public static ICustomNetworkLink createCustomLink(String siteName, String title, String summary, String icon, String url) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
||||||
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.NetworkCatalogItem;
|
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
||||||
|
import org.geometerplus.fbreader.network.URLInfo;
|
||||||
import org.geometerplus.fbreader.network.atom.ATOMLink;
|
import org.geometerplus.fbreader.network.atom.ATOMLink;
|
||||||
import org.geometerplus.fbreader.network.atom.ATOMUpdated;
|
import org.geometerplus.fbreader.network.atom.ATOMUpdated;
|
||||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||||
|
@ -99,7 +100,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
||||||
final String language = entry.DCLanguage;
|
final String language = entry.DCLanguage;
|
||||||
|
|
||||||
String icon = null;
|
String icon = null;
|
||||||
final HashMap<String,String> links = new HashMap<String,String>();
|
final HashMap<String,URLInfo> infos = new HashMap<String,URLInfo>();
|
||||||
final HashMap<String,NetworkCatalogItem.Accessibility> urlConditions =
|
final HashMap<String,NetworkCatalogItem.Accessibility> urlConditions =
|
||||||
new HashMap<String,NetworkCatalogItem.Accessibility>();
|
new HashMap<String,NetworkCatalogItem.Accessibility>();
|
||||||
for (ATOMLink link: entry.Links) {
|
for (ATOMLink link: entry.Links) {
|
||||||
|
@ -116,26 +117,26 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
||||||
}
|
}
|
||||||
} else if (rel == null) {
|
} else if (rel == null) {
|
||||||
if (type == MIME_APP_ATOM) {
|
if (type == MIME_APP_ATOM) {
|
||||||
links.put(INetworkLink.URL_MAIN, href);
|
infos.put(INetworkLink.URL_MAIN, new URLInfo(href));
|
||||||
}
|
}
|
||||||
} else if (rel == "search") {
|
} else if (rel == "search") {
|
||||||
if (type == MIME_APP_ATOM) {
|
if (type == MIME_APP_ATOM) {
|
||||||
final OpenSearchDescription descr = OpenSearchDescription.createDefault(href);
|
final OpenSearchDescription descr = OpenSearchDescription.createDefault(href);
|
||||||
if (descr.isValid()) {
|
if (descr.isValid()) {
|
||||||
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
|
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
|
||||||
links.put(INetworkLink.URL_SEARCH, descr.makeQuery("%s"));
|
infos.put(INetworkLink.URL_SEARCH, new URLInfo(descr.makeQuery("%s")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (rel == REL_LINK_SIGN_IN) {
|
} else if (rel == REL_LINK_SIGN_IN) {
|
||||||
links.put(INetworkLink.URL_SIGN_IN, href);
|
infos.put(INetworkLink.URL_SIGN_IN, new URLInfo(href));
|
||||||
} else if (rel == REL_LINK_SIGN_OUT) {
|
} else if (rel == REL_LINK_SIGN_OUT) {
|
||||||
links.put(INetworkLink.URL_SIGN_OUT, href);
|
infos.put(INetworkLink.URL_SIGN_OUT, new URLInfo(href));
|
||||||
} else if (rel == REL_LINK_SIGN_UP) {
|
} else if (rel == REL_LINK_SIGN_UP) {
|
||||||
links.put(INetworkLink.URL_SIGN_UP, href);
|
infos.put(INetworkLink.URL_SIGN_UP, new URLInfo(href));
|
||||||
} else if (rel == REL_LINK_REFILL_ACCOUNT) {
|
} else if (rel == REL_LINK_REFILL_ACCOUNT) {
|
||||||
links.put(INetworkLink.URL_REFILL_ACCOUNT, href);
|
infos.put(INetworkLink.URL_REFILL_ACCOUNT, new URLInfo(href));
|
||||||
} else if (rel == REL_LINK_RECOVER_PASSWORD) {
|
} else if (rel == REL_LINK_RECOVER_PASSWORD) {
|
||||||
links.put(INetworkLink.URL_RECOVER_PASSWORD, href);
|
infos.put(INetworkLink.URL_RECOVER_PASSWORD, new URLInfo(href));
|
||||||
} else if (rel == REL_CONDITION_NEVER) {
|
} else if (rel == REL_CONDITION_NEVER) {
|
||||||
urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER);
|
urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER);
|
||||||
} else if (rel == REL_CONDITION_SIGNED_IN) {
|
} else if (rel == REL_CONDITION_SIGNED_IN) {
|
||||||
|
@ -153,7 +154,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
||||||
sslCertificate = null;
|
sslCertificate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
INetworkLink result = link(siteName, title, summary, icon, language, links, urlConditions, sslCertificate);
|
INetworkLink result = link(siteName, title, summary, icon, language, infos, urlConditions, sslCertificate);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
myListener.onNewLink(result);
|
myListener.onNewLink(result);
|
||||||
}
|
}
|
||||||
|
@ -166,11 +167,11 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
||||||
String summary,
|
String summary,
|
||||||
String icon,
|
String icon,
|
||||||
String language,
|
String language,
|
||||||
Map<String,String> links,
|
Map<String,URLInfo> infos,
|
||||||
HashMap<String,NetworkCatalogItem.Accessibility> urlConditions,
|
HashMap<String,NetworkCatalogItem.Accessibility> urlConditions,
|
||||||
String sslCertificate
|
String sslCertificate
|
||||||
) {
|
) {
|
||||||
if (siteName == null || title == null || links.get(INetworkLink.URL_MAIN) == null) {
|
if (siteName == null || title == null || infos.get(INetworkLink.URL_MAIN) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +181,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
||||||
summary,
|
summary,
|
||||||
icon,
|
icon,
|
||||||
language,
|
language,
|
||||||
links,
|
infos,
|
||||||
myHasStableIdentifiers
|
myHasStableIdentifiers
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
||||||
private final boolean myHasStableIdentifiers;
|
private final boolean myHasStableIdentifiers;
|
||||||
|
|
||||||
OPDSNetworkLink(String siteName, String title, String summary, String icon, String language,
|
OPDSNetworkLink(String siteName, String title, String summary, String icon, String language,
|
||||||
Map<String, String> links, boolean hasStableIdentifiers) {
|
Map<String,URLInfo> infos, boolean hasStableIdentifiers) {
|
||||||
super(siteName, title, summary, icon, language, links);
|
super(siteName, title, summary, icon, language, infos);
|
||||||
myHasStableIdentifiers = hasStableIdentifiers;
|
myHasStableIdentifiers = hasStableIdentifiers;
|
||||||
myBooksInBasketOption = new ZLStringListOption(siteName, "Basket", null);
|
myBooksInBasketOption = new ZLStringListOption(siteName, "Basket", null);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) {
|
public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) {
|
||||||
final String url = getLink(URL_SEARCH);
|
final String url = getUrlInfo(URL_SEARCH).URL;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
||||||
|
|
||||||
public NetworkCatalogItem libraryItem() {
|
public NetworkCatalogItem libraryItem() {
|
||||||
TreeMap<Integer,String> urlMap = new TreeMap<Integer,String>();
|
TreeMap<Integer,String> urlMap = new TreeMap<Integer,String>();
|
||||||
urlMap.put(NetworkCatalogItem.URL_CATALOG, getLink(URL_MAIN));
|
urlMap.put(NetworkCatalogItem.URL_CATALOG, getUrlInfo(URL_MAIN).URL);
|
||||||
return new OPDSCatalogItem(this, getTitle(), getSummary(), getIcon(), urlMap, myExtraData);
|
return new OPDSCatalogItem(this, getTitle(), getSummary(), getIcon(), urlMap, myExtraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue