mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
network link type has been introduced
This commit is contained in:
parent
a7bd1ddb95
commit
3a33fb8bc7
8 changed files with 75 additions and 18 deletions
|
@ -40,9 +40,12 @@ import org.geometerplus.fbreader.network.urlInfo.*;
|
|||
import org.geometerplus.android.util.UIUtil;
|
||||
|
||||
public class AddCustomCatalogActivity extends Activity {
|
||||
static final String TYPE = "type";
|
||||
|
||||
private ZLResource myResource;
|
||||
private volatile ICustomNetworkLink myLink;
|
||||
private boolean myEditNotAdd;
|
||||
private INetworkLink.Type myType = INetworkLink.Type.Custom;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -102,6 +105,11 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
myLink = (ICustomNetworkLink)link;
|
||||
}
|
||||
}
|
||||
|
||||
final INetworkLink.Type type = (INetworkLink.Type)intent.getSerializableExtra(TYPE);
|
||||
if (type != null) {
|
||||
myType = type;
|
||||
}
|
||||
}
|
||||
|
||||
if (myLink != null) {
|
||||
|
@ -236,7 +244,7 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
final UrlInfoCollection<UrlInfoWithDate> infos = new UrlInfoCollection<UrlInfoWithDate>();
|
||||
infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.Catalog, textUrl));
|
||||
myLink = new OPDSCustomNetworkLink(
|
||||
ICustomNetworkLink.INVALID_ID, siteName, null, null, null, infos
|
||||
ICustomNetworkLink.INVALID_ID, myType, siteName, null, null, null, infos
|
||||
);
|
||||
|
||||
final Runnable loadInfoRunnable = new Runnable() {
|
||||
|
|
|
@ -42,7 +42,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
|
||||
private void migrate() {
|
||||
final int version = myDatabase.getVersion();
|
||||
final int currentCodeVersion = 6;
|
||||
final int currentCodeVersion = 7;
|
||||
if (version >= currentCodeVersion) {
|
||||
return;
|
||||
}
|
||||
|
@ -60,6 +60,8 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
updateTables4();
|
||||
case 5:
|
||||
updateTables5();
|
||||
case 6:
|
||||
updateTables6();
|
||||
}
|
||||
myDatabase.setTransactionSuccessful();
|
||||
myDatabase.endTransaction();
|
||||
|
@ -82,15 +84,16 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
protected synchronized List<INetworkLink> listLinks() {
|
||||
final List<INetworkLink> links = new LinkedList<INetworkLink>();
|
||||
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,predefined_id,title,site_name,summary,language FROM Links", null);
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,type,predefined_id,title,site_name,summary,language FROM Links", null);
|
||||
final UrlInfoCollection<UrlInfoWithDate> linksMap = new UrlInfoCollection<UrlInfoWithDate>();
|
||||
while (cursor.moveToNext()) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String predefinedId = cursor.getString(1);
|
||||
final String title = cursor.getString(2);
|
||||
final String siteName = cursor.getString(3);
|
||||
final String summary = cursor.getString(4);
|
||||
final String language = cursor.getString(5);
|
||||
final INetworkLink.Type type = INetworkLink.Type.byIndex(cursor.getInt(1));
|
||||
final String predefinedId = cursor.getString(2);
|
||||
final String title = cursor.getString(3);
|
||||
final String siteName = cursor.getString(4);
|
||||
final String summary = cursor.getString(5);
|
||||
final String language = cursor.getString(6);
|
||||
|
||||
linksMap.clear();
|
||||
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + id, null);
|
||||
|
@ -108,7 +111,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
}
|
||||
linksCursor.close();
|
||||
|
||||
final INetworkLink l = createLink(id, predefinedId, siteName, title, summary, language, linksMap);
|
||||
final INetworkLink l = createLink(id, type, predefinedId, siteName, title, summary, language, linksMap);
|
||||
if (l != null) {
|
||||
links.add(l);
|
||||
}
|
||||
|
@ -130,7 +133,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
if (link.getId() == INetworkLink.INVALID_ID) {
|
||||
if (myInsertCustomLinkStatement == null) {
|
||||
myInsertCustomLinkStatement = myDatabase.compileStatement(
|
||||
"INSERT INTO Links (title,site_name,summary,language,predefined_id) VALUES (?,?,?,?,?)"
|
||||
"INSERT INTO Links (title,site_name,summary,language,predefined_id,type) VALUES (?,?,?,?,?,?)"
|
||||
);
|
||||
}
|
||||
statement = myInsertCustomLinkStatement;
|
||||
|
@ -159,6 +162,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
} else {
|
||||
SQLiteUtil.bindString(statement, 5, null);
|
||||
}
|
||||
statement.bindLong(6, link.getType().Index);
|
||||
id = statement.executeInsert();
|
||||
link.setId((int)id);
|
||||
} else {
|
||||
|
@ -369,4 +373,9 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
|
|||
myDatabase.execSQL("INSERT INTO Links (link_id,title,site_name,summary,language,predefined_id,is_enabled) SELECT link_id,title,site_name,summary,NULL,NULL,is_enabled FROM Links_Obsolete");
|
||||
myDatabase.execSQL("DROP TABLE Links_Obsolete");
|
||||
}
|
||||
|
||||
private void updateTables6() {
|
||||
myDatabase.execSQL("ALTER TABLE Links ADD COLUMN type INTEGER");
|
||||
myDatabase.execSQL("UPDATE Links SET type=" + INetworkLink.Type.Custom.Index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import javax.jmdns.*;
|
|||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||
import org.geometerplus.fbreader.network.INetworkLink;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
|
@ -440,7 +441,7 @@ public class ScanLocalNetworkActivity extends ListActivity {
|
|||
((ServiceInfoItem)item).URI,
|
||||
getApplicationContext(),
|
||||
AddCustomCatalogActivity.class
|
||||
));
|
||||
).putExtra(AddCustomCatalogActivity.TYPE, INetworkLink.Type.Local));
|
||||
finish();
|
||||
} catch (ActivityNotFoundException e) {
|
||||
}
|
||||
|
|
|
@ -29,6 +29,27 @@ import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
|||
import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
||||
|
||||
public interface INetworkLink extends Comparable<INetworkLink> {
|
||||
public enum Type {
|
||||
Predefined(0),
|
||||
Custom(1),
|
||||
Local(2);
|
||||
|
||||
public final int Index;
|
||||
|
||||
Type(int index) {
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public static Type byIndex(int index) {
|
||||
for (Type t : Type.values()) {
|
||||
if (t.Index == index) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return Custom;
|
||||
}
|
||||
};
|
||||
|
||||
public enum AccountStatus {
|
||||
NotSupported,
|
||||
NoUserName,
|
||||
|
@ -58,6 +79,8 @@ public interface INetworkLink extends Comparable<INetworkLink> {
|
|||
*/
|
||||
//AccountStatus getAccountStatus(boolean force);
|
||||
|
||||
Type getType();
|
||||
|
||||
/**
|
||||
* @return 2-letters language code or special token "multi"
|
||||
*/
|
||||
|
|
|
@ -39,14 +39,20 @@ public abstract class NetworkDatabase {
|
|||
|
||||
protected abstract void executeAsATransaction(Runnable actions);
|
||||
|
||||
protected INetworkLink createLink(int id, String predefinedId, String siteName, String title, String summary, String language, UrlInfoCollection<UrlInfoWithDate> infos) {
|
||||
protected INetworkLink createLink(int id, INetworkLink.Type type, String predefinedId, String siteName, String title, String summary, String language, UrlInfoCollection<UrlInfoWithDate> infos) {
|
||||
if (siteName == null || title == null || infos.getInfo(UrlInfo.Type.Catalog) == null) {
|
||||
return null;
|
||||
}
|
||||
return
|
||||
predefinedId != null
|
||||
? new OPDSPredefinedNetworkLink(id, predefinedId, siteName, title, summary, language, infos)
|
||||
: new OPDSCustomNetworkLink(id, siteName, title, summary, language, infos);
|
||||
switch (type) {
|
||||
default:
|
||||
return new OPDSCustomNetworkLink(
|
||||
id, type, siteName, title, summary, language, infos
|
||||
);
|
||||
case Predefined:
|
||||
return new OPDSPredefinedNetworkLink(
|
||||
id, predefinedId, siteName, title, summary, language, infos
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract List<INetworkLink> listLinks();
|
||||
|
|
|
@ -295,7 +295,7 @@ public class NetworkLibrary {
|
|||
// we create this copy to prevent long operations on synchronized list
|
||||
final List<INetworkLink> linksCopy = new ArrayList<INetworkLink>(myLinks);
|
||||
for (INetworkLink link : linksCopy) {
|
||||
if (link instanceof ICustomNetworkLink) {
|
||||
if (link.getType() == INetworkLink.Type.Custom) {
|
||||
final ICustomNetworkLink customLink = (ICustomNetworkLink)link;
|
||||
if (customLink.isObsolete(12 * 60 * 60 * 1000)) { // 12 hours
|
||||
try {
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.fbreader.network.NetworkException;
|
|||
import org.geometerplus.fbreader.network.urlInfo.*;
|
||||
|
||||
public class OPDSCustomNetworkLink extends OPDSNetworkLink implements ICustomNetworkLink {
|
||||
private final Type myType;
|
||||
private boolean myHasChanges;
|
||||
|
||||
private static String removeWWWPrefix(String siteName) {
|
||||
|
@ -42,8 +43,13 @@ public class OPDSCustomNetworkLink extends OPDSNetworkLink implements ICustomNet
|
|||
return siteName;
|
||||
}
|
||||
|
||||
public OPDSCustomNetworkLink(int id, String siteName, String title, String summary, String language, UrlInfoCollection<UrlInfoWithDate> infos) {
|
||||
public OPDSCustomNetworkLink(int id, Type type, String siteName, String title, String summary, String language, UrlInfoCollection<UrlInfoWithDate> infos) {
|
||||
super(id, removeWWWPrefix(siteName), title, summary, language, infos);
|
||||
myType = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
public boolean hasChanges() {
|
||||
|
|
|
@ -30,6 +30,10 @@ public class OPDSPredefinedNetworkLink extends OPDSNetworkLink implements IPrede
|
|||
myPredefinedId = predifinedId;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return Type.Predefined;
|
||||
}
|
||||
|
||||
public String getPredefinedId() {
|
||||
return myPredefinedId;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue