mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
refactoring: INetworkLink constants replaced by UrlInfo.Type elements
This commit is contained in:
parent
5c2775b46e
commit
aa590a5002
15 changed files with 119 additions and 86 deletions
|
@ -39,6 +39,7 @@ import org.geometerplus.zlibrary.ui.android.R;
|
|||
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSCustomLink;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
import org.geometerplus.android.util.UIUtil;
|
||||
|
@ -89,7 +90,7 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
final Uri uri = intent.getData();
|
||||
|
||||
if (myLink != null) {
|
||||
setTextById(R.id.add_custom_catalog_url, myLink.getUrlInfo(INetworkLink.URL_MAIN).URL);
|
||||
setTextById(R.id.add_custom_catalog_url, myLink.getUrlInfo(UrlInfo.Type.Catalog).URL);
|
||||
setTextById(R.id.add_custom_catalog_title, myLink.getTitle());
|
||||
setTextById(R.id.add_custom_catalog_summary, myLink.getSummary());
|
||||
setExtraFieldsVisibility(true);
|
||||
|
@ -130,7 +131,7 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
} else {
|
||||
myLink.setTitle(title);
|
||||
myLink.setSummary(summary);
|
||||
myLink.setUrl(INetworkLink.URL_MAIN, uri.toString());
|
||||
myLink.setUrl(UrlInfo.Type.Catalog, uri.toString());
|
||||
|
||||
Intent intent = new Intent(
|
||||
NetworkLibraryActivity.ADD_CATALOG,
|
||||
|
@ -240,8 +241,8 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
setErrorByKey("invalidUrl");
|
||||
return;
|
||||
}
|
||||
final HashMap<String,UrlInfoWithDate> infos = new HashMap<String,UrlInfoWithDate>();
|
||||
infos.put(INetworkLink.URL_MAIN, new UrlInfoWithDate(textUrl));
|
||||
final HashMap<UrlInfo.Type,UrlInfoWithDate> infos = new HashMap<UrlInfo.Type,UrlInfoWithDate>();
|
||||
infos.put(UrlInfo.Type.Catalog, new UrlInfoWithDate(textUrl));
|
||||
myLink = new OPDSCustomLink(
|
||||
ICustomNetworkLink.INVALID_ID, siteName, null, null, infos
|
||||
);
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.geometerplus.android.util.UIUtil;
|
|||
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSCustomLink;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public class NetworkLibraryActivity extends NetworkBaseActivity {
|
||||
|
@ -52,7 +53,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
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;
|
||||
final String textUrl = link.getUrlInfo(UrlInfo.Type.Catalog).URL;
|
||||
intent.setData(Uri.parse(textUrl));
|
||||
intent
|
||||
.putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle())
|
||||
|
@ -72,7 +73,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
uri.getHost(),
|
||||
intent.getStringExtra(ADD_CATALOG_TITLE_KEY),
|
||||
intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY),
|
||||
(HashMap<String,UrlInfoWithDate>)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY)
|
||||
(HashMap<UrlInfo.Type,UrlInfoWithDate>)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
|||
|
||||
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||
import org.geometerplus.fbreader.network.NetworkDatabase;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
import org.geometerplus.android.util.SQLiteUtil;
|
||||
|
@ -77,7 +78,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
@Override
|
||||
protected void loadCustomLinks(ICustomLinksHandler handler) {
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary FROM Links", null);
|
||||
final HashMap<String,UrlInfoWithDate> linksMap = new HashMap<String,UrlInfoWithDate>();
|
||||
final HashMap<UrlInfo.Type,UrlInfoWithDate> linksMap = new HashMap<UrlInfo.Type,UrlInfoWithDate>();
|
||||
while (cursor.moveToNext()) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String title = cursor.getString(1);
|
||||
|
@ -88,7 +89,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + id, null);
|
||||
while (linksCursor.moveToNext()) {
|
||||
linksMap.put(
|
||||
linksCursor.getString(0),
|
||||
UrlInfo.Type.fromFixedName(linksCursor.getString(0)),
|
||||
new UrlInfoWithDate(
|
||||
linksCursor.getString(1),
|
||||
SQLiteUtil.getDate(linksCursor, 2)
|
||||
|
@ -134,7 +135,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
SQLiteUtil.bindString(statement, 3, link.getSummary());
|
||||
|
||||
final long id;
|
||||
final HashMap<String,UrlInfoWithDate> linksMap = new HashMap<String,UrlInfoWithDate>();
|
||||
final HashMap<UrlInfo.Type,UrlInfoWithDate> linksMap = new HashMap<UrlInfo.Type,UrlInfoWithDate>();
|
||||
|
||||
if (statement == myInsertCustomLinkStatement) {
|
||||
id = statement.executeInsert();
|
||||
|
@ -147,7 +148,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + link.getId(), null);
|
||||
while (linksCursor.moveToNext()) {
|
||||
linksMap.put(
|
||||
linksCursor.getString(0),
|
||||
UrlInfo.Type.fromFixedName(linksCursor.getString(0)),
|
||||
new UrlInfoWithDate(
|
||||
linksCursor.getString(1),
|
||||
SQLiteUtil.getDate(linksCursor, 2)
|
||||
|
@ -157,7 +158,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
linksCursor.close();
|
||||
}
|
||||
|
||||
for (String key : link.getUrlKeys()) {
|
||||
for (UrlInfo.Type key : link.getUrlKeys()) {
|
||||
final UrlInfoWithDate info = link.getUrlInfo(key);
|
||||
final UrlInfoWithDate dbInfo = linksMap.remove(key);
|
||||
final SQLiteStatement urlStatement;
|
||||
|
@ -179,16 +180,16 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
SQLiteUtil.bindString(urlStatement, 1, info.URL);
|
||||
SQLiteUtil.bindDate(urlStatement, 2, info.Updated);
|
||||
urlStatement.bindLong(3, id);
|
||||
urlStatement.bindString(4, key);
|
||||
urlStatement.bindString(4, key.getFixedName());
|
||||
urlStatement.execute();
|
||||
}
|
||||
for (String key: linksMap.keySet()) {
|
||||
for (UrlInfo.Type key: linksMap.keySet()) {
|
||||
if (myDeleteCustomLinkUrlStatement == null) {
|
||||
myDeleteCustomLinkUrlStatement = myDatabase.compileStatement(
|
||||
"DELETE FROM LinkUrls WHERE link_id = ? AND key = ?");
|
||||
}
|
||||
myDeleteCustomLinkUrlStatement.bindLong(1, id);
|
||||
myDeleteCustomLinkUrlStatement.bindString(2, key);
|
||||
myDeleteCustomLinkUrlStatement.bindString(2, key.getFixedName());
|
||||
myDeleteCustomLinkUrlStatement.execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
|||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||
import org.geometerplus.fbreader.network.tree.NetworkBookTree;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
|
||||
import org.geometerplus.android.util.PackageUtil;
|
||||
|
||||
|
@ -53,7 +54,7 @@ abstract class Util implements UserRegistrationConstants {
|
|||
return testService(
|
||||
activity,
|
||||
REGISTRATION_ACTION,
|
||||
link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL
|
||||
link.getUrlInfo(UrlInfo.Type.SignUp).URL
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -61,12 +62,12 @@ abstract class Util implements UserRegistrationConstants {
|
|||
try {
|
||||
final Intent intent = new Intent(
|
||||
REGISTRATION_ACTION,
|
||||
Uri.parse(link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL)
|
||||
Uri.parse(link.getUrlInfo(UrlInfo.Type.SignUp).URL)
|
||||
);
|
||||
if (PackageUtil.canBeStarted(activity, intent, true)) {
|
||||
activity.startActivityForResult(new Intent(
|
||||
REGISTRATION_ACTION,
|
||||
Uri.parse(link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL)
|
||||
Uri.parse(link.getUrlInfo(UrlInfo.Type.SignUp).URL)
|
||||
), USER_REGISTRATION_REQUEST_CODE);
|
||||
}
|
||||
} catch (ActivityNotFoundException e) {
|
||||
|
@ -99,7 +100,7 @@ abstract class Util implements UserRegistrationConstants {
|
|||
return testService(
|
||||
activity,
|
||||
action,
|
||||
link.getUrlInfo(INetworkLink.URL_MAIN).URL
|
||||
link.getUrlInfo(UrlInfo.Type.Catalog).URL
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,7 @@ abstract class Util implements UserRegistrationConstants {
|
|||
try {
|
||||
final Intent intent = new Intent(
|
||||
action,
|
||||
Uri.parse(link.getUrlInfo(INetworkLink.URL_MAIN).URL)
|
||||
Uri.parse(link.getUrlInfo(UrlInfo.Type.Catalog).URL)
|
||||
);
|
||||
final NetworkAuthenticationManager mgr = link.authenticationManager();
|
||||
if (mgr != null) {
|
||||
|
@ -123,7 +124,7 @@ abstract class Util implements UserRegistrationConstants {
|
|||
}
|
||||
|
||||
static boolean isBrowserTopupSupported(Activity activity, INetworkLink link) {
|
||||
return link.getUrlInfo(INetworkLink.URL_TOPUP).URL != null;
|
||||
return link.getUrlInfo(UrlInfo.Type.TopUp).URL != null;
|
||||
}
|
||||
|
||||
static void openInBrowser(Context context, String url) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public abstract class AbstractNetworkLink implements INetworkLink, Basket {
|
||||
|
@ -31,7 +32,7 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
|
|||
protected String myTitle;
|
||||
protected String mySummary;
|
||||
protected final String myLanguage;
|
||||
protected final TreeMap<String,UrlInfoWithDate> myInfos;
|
||||
protected final TreeMap<UrlInfo.Type,UrlInfoWithDate> myInfos;
|
||||
|
||||
private ZLStringListOption myBooksInBasketOption;
|
||||
|
||||
|
@ -42,14 +43,14 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
|
|||
* @param title title of the corresponding library item. Must be not <code>null</code>.
|
||||
* @param summary description of the corresponding library item. Can be <code>null</code>.
|
||||
* @param language language of the catalog. If <code>null</code> we assume this catalog is multilanguage.
|
||||
* @param infos map contains URL infos with their identifiers; must always contain one URL with <code>URL_MAIN</code> identifier
|
||||
* @param infos collection of URL infos; must always contain one URL with <code>UrlInfo.Type.Catalog</code> identifier
|
||||
*/
|
||||
public AbstractNetworkLink(String siteName, String title, String summary, String language, Map<String,UrlInfoWithDate> infos) {
|
||||
public AbstractNetworkLink(String siteName, String title, String summary, String language, Map<UrlInfo.Type,UrlInfoWithDate> infos) {
|
||||
mySiteName = siteName;
|
||||
myTitle = title;
|
||||
mySummary = summary;
|
||||
myLanguage = language != null ? language : "multi";
|
||||
myInfos = new TreeMap<String,UrlInfoWithDate>(infos);
|
||||
myInfos = new TreeMap<UrlInfo.Type,UrlInfoWithDate>(infos);
|
||||
}
|
||||
|
||||
public final String getSiteName() {
|
||||
|
@ -68,16 +69,16 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
|
|||
return myLanguage;
|
||||
}
|
||||
|
||||
public final HashMap<String,UrlInfoWithDate> urlInfoMap() {
|
||||
return new HashMap<String,UrlInfoWithDate>(myInfos);
|
||||
public final HashMap<UrlInfo.Type,UrlInfoWithDate> urlInfoMap() {
|
||||
return new HashMap<UrlInfo.Type,UrlInfoWithDate>(myInfos);
|
||||
}
|
||||
|
||||
public final UrlInfoWithDate getUrlInfo(String urlKey) {
|
||||
final UrlInfoWithDate info = myInfos.get(urlKey);
|
||||
public final UrlInfoWithDate getUrlInfo(UrlInfo.Type type) {
|
||||
final UrlInfoWithDate info = myInfos.get(type);
|
||||
return info != null ? info : UrlInfoWithDate.NULL;
|
||||
}
|
||||
|
||||
public final Set<String> getUrlKeys() {
|
||||
public final Set<UrlInfo.Type> getUrlKeys() {
|
||||
return myInfos.keySet();
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,7 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
String icon = getUrlInfo(URL_ICON).URL;
|
||||
String icon = getUrlInfo(UrlInfo.Type.Catalog).URL;
|
||||
if (icon != null) {
|
||||
if (icon.length() > 64) {
|
||||
icon = icon.substring(0, 61) + "...";
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.HashMap;
|
|||
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public interface ICustomNetworkLink extends INetworkLink {
|
||||
|
@ -35,9 +36,9 @@ public interface ICustomNetworkLink extends INetworkLink {
|
|||
void setTitle(String title);
|
||||
void setSummary(String summary);
|
||||
|
||||
HashMap<String,UrlInfoWithDate> urlInfoMap();
|
||||
void setUrl(String urlKey, String url);
|
||||
void removeUrl(String urlKey);
|
||||
HashMap<UrlInfo.Type,UrlInfoWithDate> urlInfoMap();
|
||||
void setUrl(UrlInfo.Type type, String url);
|
||||
void removeUrl(UrlInfo.Type type);
|
||||
|
||||
boolean isObsolete(long milliSeconds);
|
||||
void reloadInfo(boolean urlsOnly) throws ZLNetworkException;
|
||||
|
|
|
@ -24,24 +24,16 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.network.ZLNetworkRequest;
|
||||
|
||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public interface INetworkLink {
|
||||
String URL_MAIN = "main";
|
||||
String URL_SEARCH = "search";
|
||||
String URL_ICON = "icon";
|
||||
String URL_SIGN_IN = "signIn";
|
||||
String URL_SIGN_OUT = "signOut";
|
||||
String URL_SIGN_UP = "signUp";
|
||||
String URL_TOPUP = "topup";
|
||||
String URL_RECOVER_PASSWORD = "recoverPassword";
|
||||
|
||||
String getSiteName();
|
||||
String getTitle();
|
||||
String getSummary();
|
||||
|
||||
UrlInfoWithDate getUrlInfo(String urlKey);
|
||||
Set<String> getUrlKeys();
|
||||
UrlInfoWithDate getUrlInfo(UrlInfo.Type type);
|
||||
Set<UrlInfo.Type> getUrlKeys();
|
||||
|
||||
/**
|
||||
* @return 2-letters language code or special token "multi"
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.geometerplus.fbreader.network;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public abstract class NetworkDatabase {
|
||||
|
@ -37,7 +38,7 @@ public abstract class NetworkDatabase {
|
|||
protected abstract void executeAsATransaction(Runnable actions);
|
||||
|
||||
public interface ICustomLinksHandler {
|
||||
void handleCustomLinkData(int id, String siteName, String title, String summary, Map<String,UrlInfoWithDate> infos);
|
||||
void handleCustomLinkData(int id, String siteName, String title, String summary, Map<UrlInfo.Type,UrlInfoWithDate> infos);
|
||||
}
|
||||
|
||||
protected abstract void loadCustomLinks(ICustomLinksHandler handler);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.fbreader.tree.FBTree;
|
|||
import org.geometerplus.fbreader.network.tree.*;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSCustomLink;
|
||||
import org.geometerplus.fbreader.network.opds.OPDSLinkReader;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public class NetworkLibrary {
|
||||
|
@ -180,10 +181,10 @@ public class NetworkLibrary {
|
|||
db.loadCustomLinks(
|
||||
new NetworkDatabase.ICustomLinksHandler() {
|
||||
public void handleCustomLinkData(int id, String siteName,
|
||||
String title, String summary, Map<String,UrlInfoWithDate> infos) {
|
||||
String title, String summary, Map<UrlInfo.Type,UrlInfoWithDate> infos) {
|
||||
if (title != null &&
|
||||
siteName != null &&
|
||||
infos.get(INetworkLink.URL_MAIN) != null) {
|
||||
infos.get(UrlInfo.Type.Catalog) != null) {
|
||||
final ICustomNetworkLink link = new OPDSCustomLink(
|
||||
id, siteName, title, summary, infos
|
||||
);
|
||||
|
|
|
@ -90,7 +90,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
sid = mySidOption.getValue();
|
||||
}
|
||||
|
||||
String url = Link.getUrlInfo(INetworkLink.URL_SIGN_IN).URL;
|
||||
String url = Link.getUrlInfo(UrlInfo.Type.SignIn).URL;
|
||||
if (url == null) {
|
||||
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
|
||||
@Override
|
||||
public void authorise(String password) throws ZLNetworkException {
|
||||
String url = Link.getUrlInfo(INetworkLink.URL_SIGN_IN).URL;
|
||||
String url = Link.getUrlInfo(UrlInfo.Type.SignIn).URL;
|
||||
if (url == null) {
|
||||
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
if (sid.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
final String url = Link.getUrlInfo(INetworkLink.URL_TOPUP).URL;
|
||||
final String url = Link.getUrlInfo(UrlInfo.Type.TopUp).URL;
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
|
||||
@Override
|
||||
public void recoverPassword(String email) throws ZLNetworkException {
|
||||
String url = Link.getUrlInfo(INetworkLink.URL_RECOVER_PASSWORD).URL;
|
||||
String url = Link.getUrlInfo(UrlInfo.Type.RecoverPassword).URL;
|
||||
if (url == null) {
|
||||
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
|||
|
||||
import org.geometerplus.fbreader.network.ICustomNetworkLink;
|
||||
import org.geometerplus.fbreader.network.NetworkException;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
||||
|
@ -45,7 +46,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
|
|||
return siteName;
|
||||
}
|
||||
|
||||
public OPDSCustomLink(int id, String siteName, String title, String summary, Map<String,UrlInfoWithDate> infos) {
|
||||
public OPDSCustomLink(int id, String siteName, String title, String summary, Map<UrlInfo.Type,UrlInfoWithDate> infos) {
|
||||
super(removeWWWPrefix(siteName), title, summary, null, infos, false);
|
||||
myId = id;
|
||||
}
|
||||
|
@ -81,26 +82,26 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
|
|||
myTitle = title;
|
||||
}
|
||||
|
||||
public final void setUrl(String urlKey, String url) {
|
||||
myInfos.put(urlKey, new UrlInfoWithDate(url, new Date()));
|
||||
public final void setUrl(UrlInfo.Type type, String url) {
|
||||
myInfos.put(type, new UrlInfoWithDate(url, new Date()));
|
||||
myHasChanges = true;
|
||||
}
|
||||
|
||||
public final void removeUrl(String urlKey) {
|
||||
final UrlInfoWithDate oldUrl = myInfos.remove(urlKey);
|
||||
public final void removeUrl(UrlInfo.Type type) {
|
||||
final UrlInfoWithDate oldUrl = myInfos.remove(type);
|
||||
myHasChanges = myHasChanges || oldUrl != null;
|
||||
}
|
||||
|
||||
public boolean isObsolete(long milliSeconds) {
|
||||
final long old = System.currentTimeMillis() - milliSeconds;
|
||||
|
||||
final Date searchUpdateDate = getUrlInfo(URL_SEARCH).Updated;
|
||||
if (searchUpdateDate == null || searchUpdateDate.getTime() < old) {
|
||||
Date updateDate = getUrlInfo(UrlInfo.Type.Search).Updated;
|
||||
if (updateDate == null || updateDate.getTime() < old) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Date iconUpdateDate = getUrlInfo(URL_ICON).Updated;
|
||||
if (iconUpdateDate == null || iconUpdateDate.getTime() < old) {
|
||||
updateDate = getUrlInfo(UrlInfo.Type.Image).Updated;
|
||||
if (updateDate == null || updateDate.getTime() < old) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -113,7 +114,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
|
|||
|
||||
ZLNetworkException error = null;
|
||||
try {
|
||||
ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(URL_MAIN).URL) {
|
||||
ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(UrlInfo.Type.Catalog).URL) {
|
||||
@Override
|
||||
public void handleStream(URLConnection connection, InputStream inputStream) throws IOException, ZLNetworkException {
|
||||
final CatalogInfoReader info = new CatalogInfoReader(URL, OPDSCustomLink.this, opensearchDescriptionURLs);
|
||||
|
@ -125,7 +126,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
|
|||
if (info.Title == null) {
|
||||
throw new ZLNetworkException(NetworkException.ERROR_NO_REQUIRED_INFORMATION);
|
||||
}
|
||||
setUrl(URL_ICON, info.Icon);
|
||||
setUrl(UrlInfo.Type.Image, info.Icon);
|
||||
if (info.DirectOpenSearchDescription != null) {
|
||||
descriptions.add(info.DirectOpenSearchDescription);
|
||||
}
|
||||
|
@ -161,9 +162,9 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
|
|||
|
||||
if (!descriptions.isEmpty()) {
|
||||
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
|
||||
setUrl(URL_SEARCH, descriptions.get(0).makeQuery("%s"));
|
||||
setUrl(UrlInfo.Type.Search, descriptions.get(0).makeQuery("%s"));
|
||||
} else {
|
||||
setUrl(URL_SEARCH, null);
|
||||
setUrl(UrlInfo.Type.Search, null);
|
||||
}
|
||||
if (error != null) {
|
||||
throw error;
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.geometerplus.fbreader.network.atom.ATOMLink;
|
|||
import org.geometerplus.fbreader.network.atom.ATOMUpdated;
|
||||
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
|
||||
import org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticationManager;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeTypes {
|
||||
|
@ -97,7 +98,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
|||
final String summary = entry.Content;
|
||||
final String language = entry.DCLanguage;
|
||||
|
||||
final HashMap<String,UrlInfoWithDate> infos = new HashMap<String,UrlInfoWithDate>();
|
||||
final HashMap<UrlInfo.Type,UrlInfoWithDate> infos = new HashMap<UrlInfo.Type,UrlInfoWithDate>();
|
||||
final HashMap<String,NetworkCatalogItem.Accessibility> urlConditions =
|
||||
new HashMap<String,NetworkCatalogItem.Accessibility>();
|
||||
for (ATOMLink link: entry.Links) {
|
||||
|
@ -106,35 +107,34 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
|||
final String rel = link.getRel();
|
||||
if (rel == REL_IMAGE_THUMBNAIL || rel == REL_THUMBNAIL) {
|
||||
if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) {
|
||||
infos.put(INetworkLink.URL_ICON, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.Thumbnail, new UrlInfoWithDate(href));
|
||||
}
|
||||
} else if ((rel != null && rel.startsWith(REL_IMAGE_PREFIX)) || rel == REL_COVER) {
|
||||
if (infos.get(INetworkLink.URL_ICON) == null &&
|
||||
(type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG)) {
|
||||
infos.put(INetworkLink.URL_ICON, new UrlInfoWithDate(href));
|
||||
if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) {
|
||||
infos.put(UrlInfo.Type.Image, new UrlInfoWithDate(href));
|
||||
}
|
||||
} else if (rel == null) {
|
||||
if (type == MIME_APP_ATOM) {
|
||||
infos.put(INetworkLink.URL_MAIN, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.Catalog, new UrlInfoWithDate(href));
|
||||
}
|
||||
} else if (rel == "search") {
|
||||
if (type == MIME_APP_ATOM) {
|
||||
final OpenSearchDescription descr = OpenSearchDescription.createDefault(href);
|
||||
if (descr.isValid()) {
|
||||
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
|
||||
infos.put(INetworkLink.URL_SEARCH, new UrlInfoWithDate(descr.makeQuery("%s")));
|
||||
infos.put(UrlInfo.Type.Search, new UrlInfoWithDate(descr.makeQuery("%s")));
|
||||
}
|
||||
}
|
||||
} else if (rel == REL_LINK_SIGN_IN) {
|
||||
infos.put(INetworkLink.URL_SIGN_IN, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.SignIn, new UrlInfoWithDate(href));
|
||||
} else if (rel == REL_LINK_SIGN_OUT) {
|
||||
infos.put(INetworkLink.URL_SIGN_OUT, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.SignOut, new UrlInfoWithDate(href));
|
||||
} else if (rel == REL_LINK_SIGN_UP) {
|
||||
infos.put(INetworkLink.URL_SIGN_UP, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.SignUp, new UrlInfoWithDate(href));
|
||||
} else if (rel == REL_LINK_TOPUP) {
|
||||
infos.put(INetworkLink.URL_TOPUP, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.TopUp, new UrlInfoWithDate(href));
|
||||
} else if (rel == REL_LINK_RECOVER_PASSWORD) {
|
||||
infos.put(INetworkLink.URL_RECOVER_PASSWORD, new UrlInfoWithDate(href));
|
||||
infos.put(UrlInfo.Type.RecoverPassword, new UrlInfoWithDate(href));
|
||||
} else if (rel == REL_CONDITION_NEVER) {
|
||||
urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER);
|
||||
} else if (rel == REL_CONDITION_SIGNED_IN) {
|
||||
|
@ -164,11 +164,11 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
|
|||
String title,
|
||||
String summary,
|
||||
String language,
|
||||
Map<String,UrlInfoWithDate> infos,
|
||||
Map<UrlInfo.Type,UrlInfoWithDate> infos,
|
||||
HashMap<String,NetworkCatalogItem.Accessibility> urlConditions,
|
||||
String sslCertificate
|
||||
) {
|
||||
if (siteName == null || title == null || infos.get(INetworkLink.URL_MAIN) == null) {
|
||||
if (siteName == null || title == null || infos.get(UrlInfo.Type.Catalog) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
private final boolean myHasStableIdentifiers;
|
||||
|
||||
OPDSNetworkLink(String siteName, String title, String summary, String language,
|
||||
Map<String,UrlInfoWithDate> infos, boolean hasStableIdentifiers) {
|
||||
Map<UrlInfo.Type,UrlInfoWithDate> infos, boolean hasStableIdentifiers) {
|
||||
super(siteName, title, summary, language, infos);
|
||||
myHasStableIdentifiers = hasStableIdentifiers;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
}
|
||||
|
||||
public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) {
|
||||
final String url = getUrlInfo(URL_SEARCH).URL;
|
||||
final String url = getUrlInfo(UrlInfo.Type.Search).URL;
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -135,8 +135,8 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
|
||||
public NetworkCatalogItem libraryItem() {
|
||||
final UrlInfoCollection urlMap = new UrlInfoCollection();
|
||||
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, getUrlInfo(URL_MAIN).URL));
|
||||
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Image, getUrlInfo(URL_ICON).URL));
|
||||
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, getUrlInfo(UrlInfo.Type.Catalog).URL));
|
||||
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Image, getUrlInfo(UrlInfo.Type.Image).URL));
|
||||
return new OPDSCatalogItem(this, getTitle(), getSummary(), urlMap, myExtraData);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,16 +25,45 @@ public class UrlInfo implements Serializable {
|
|||
private static final long serialVersionUID = -893514485257788222L;
|
||||
|
||||
public static enum Type {
|
||||
Catalog,
|
||||
Catalog("main"),
|
||||
HtmlPage,
|
||||
Image,
|
||||
Image("icon"),
|
||||
Thumbnail,
|
||||
Search("search"),
|
||||
SignIn,
|
||||
SignOut,
|
||||
SignUp,
|
||||
TopUp,
|
||||
RecoverPassword,
|
||||
Book,
|
||||
BookConditional,
|
||||
BookDemo,
|
||||
BookFullOrDemo,
|
||||
BookBuy,
|
||||
BookBuyInBrowser
|
||||
BookBuyInBrowser;
|
||||
|
||||
public static Type fromFixedName(String fixedName) {
|
||||
for (Type t : values()) {
|
||||
if (t.getFixedName().equals(fixedName)) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final String myFixedName;
|
||||
|
||||
Type(String fixedName) {
|
||||
myFixedName = fixedName;
|
||||
}
|
||||
|
||||
Type() {
|
||||
myFixedName = null;
|
||||
}
|
||||
|
||||
public String getFixedName() {
|
||||
return myFixedName != null ? myFixedName : toString();
|
||||
}
|
||||
}
|
||||
|
||||
public final Type InfoType;
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
package org.geometerplus.fbreader.network.urlInfo;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class UrlInfoCollection<T extends UrlInfo> implements Serializable {
|
||||
private static final long serialVersionUID = -834589080548958222L;
|
||||
|
||||
public class UrlInfoCollection<T extends UrlInfo> {
|
||||
private final LinkedList<T> myInfos = new LinkedList<T>();
|
||||
|
||||
public UrlInfoCollection() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue