1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

opds-fbreader scheme support

This commit is contained in:
Nikolay Pultsin 2014-05-06 02:14:02 +01:00
parent 07bc085d28
commit e07dcbf47e
5 changed files with 64 additions and 36 deletions

View file

@ -256,6 +256,12 @@
<category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="opds"/> <data android:host="*" android:scheme="opds"/>
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="opds-fbreader"/>
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.fbreader.action.ADD_OPDS_CATALOG_URL"/> <action android:name="android.fbreader.action.ADD_OPDS_CATALOG_URL"/>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>

View file

@ -256,6 +256,12 @@
<category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="opds"/> <data android:host="*" android:scheme="opds"/>
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="opds-fbreader"/>
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.fbreader.action.ADD_OPDS_CATALOG_URL"/> <action android:name="android.fbreader.action.ADD_OPDS_CATALOG_URL"/>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>

View file

@ -89,20 +89,30 @@ public class AddCustomCatalogActivity extends Activity {
} }
); );
Util.initLibrary(this);
final Intent intent = getIntent(); final Intent intent = getIntent();
final String action = intent.getAction(); myEditNotAdd = Util.EDIT_CATALOG_ACTION.equals(intent.getAction());
myEditNotAdd = Util.EDIT_CATALOG_ACTION.equals(action);
myLink = null; myLink = null;
Util.initLibrary(this, new Runnable() {
public void run() {
init(intent);
}
});
}
private void init(Intent intent) {
final String action = intent.getAction();
Uri uri = null; Uri uri = null;
if (myEditNotAdd || if (myEditNotAdd ||
Intent.ACTION_VIEW.equals(action) || Intent.ACTION_VIEW.equals(action) ||
Util.ADD_CATALOG_URL_ACTION.equals(action)) { Util.ADD_CATALOG_URL_ACTION.equals(action)) {
uri = intent.getData(); uri = intent.getData();
if (uri != null) { if (uri != null) {
if ("opds".equals(uri.getScheme())) { final String scheme = uri.getScheme();
uri = Uri.parse("http" + uri.toString().substring(4)); if ("opds".equals(scheme)) {
uri = Uri.parse("http" + uri.toString().substring(scheme.length()));
} else if ("opds-fbreader".equals(scheme)) {
uri = Uri.parse("https" + uri.toString().substring(scheme.length()));
} }
final INetworkLink link = NetworkLibrary.Instance().getLinkByUrl(uri.toString()); final INetworkLink link = NetworkLibrary.Instance().getLinkByUrl(uri.toString());
if (link instanceof ICustomNetworkLink) { if (link instanceof ICustomNetworkLink) {
@ -114,14 +124,15 @@ public class AddCustomCatalogActivity extends Activity {
} }
if (myLink != null) { if (myLink != null) {
if (myEditNotAdd) {
setTextById(R.id.add_custom_catalog_url, myLink.getUrl(UrlInfo.Type.Catalog)); setTextById(R.id.add_custom_catalog_url, myLink.getUrl(UrlInfo.Type.Catalog));
setTextById(R.id.add_custom_catalog_title, myLink.getTitle()); setTextById(R.id.add_custom_catalog_title, myLink.getTitle());
setTextById(R.id.add_custom_catalog_summary, myLink.getSummary()); setTextById(R.id.add_custom_catalog_summary, myLink.getSummary());
setExtraFieldsVisibility(true); setExtraFieldsVisibility(true);
} else if (uri != null) { } else {
if ("opds".equals(uri.getScheme())) { openCatalog(uri);
uri = Uri.parse("http" + uri.toString().substring(4));
} }
} else if (uri != null) {
loadInfoByUri(uri); loadInfoByUri(uri);
} else { } else {
setExtraFieldsVisibility(false); setExtraFieldsVisibility(false);
@ -165,17 +176,20 @@ public class AddCustomCatalogActivity extends Activity {
library.addCustomLink(myLink); library.addCustomLink(myLink);
library.synchronize(); library.synchronize();
final Intent intent = new Intent( openCatalog(myEditNotAdd ? null : uri);
FBReaderIntents.Action.OPEN_NETWORK_CATALOG,
myEditNotAdd ? null : uri,
AddCustomCatalogActivity.this,
NetworkLibraryPrimaryActivity.class
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
} }
} }
private void openCatalog(Uri uri) {
startActivity(new Intent(
FBReaderIntents.Action.OPEN_NETWORK_CATALOG,
uri,
this,
NetworkLibraryPrimaryActivity.class
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP));
finish();
}
private boolean isEmptyString(String s) { private boolean isEmptyString(String s) {
return s == null || s.length() == 0; return s == null || s.length() == 0;
} }

View file

@ -77,8 +77,14 @@ public abstract class NetworkLibraryActivity extends TreeActivity<NetworkTree> i
if (getCurrentTree() instanceof RootTree) { if (getCurrentTree() instanceof RootTree) {
mySingleCatalog = intent.getBooleanExtra("SingleCatalog", false); mySingleCatalog = intent.getBooleanExtra("SingleCatalog", false);
if (!NetworkLibrary.Instance().isInitialized()) { if (!NetworkLibrary.Instance().isInitialized()) {
Util.initLibrary(this); Util.initLibrary(this, new Runnable() {
myDeferredIntent = intent; public void run() {
NetworkLibrary.Instance().runBackgroundUpdate(false);
if (intent != null) {
openTreeByIntent(intent);
}
}
});
} else { } else {
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode); NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
openTreeByIntent(intent); openTreeByIntent(intent);
@ -363,11 +369,6 @@ public abstract class NetworkLibraryActivity extends TreeActivity<NetworkTree> i
showInitLibraryDialog((String)params[0]); showInitLibraryDialog((String)params[0]);
break; break;
case InitializationFinished: case InitializationFinished:
NetworkLibrary.Instance().runBackgroundUpdate(false);
if (myDeferredIntent != null) {
openTreeByIntent(myDeferredIntent);
myDeferredIntent = null;
}
break; break;
case Found: case Found:
openTree((NetworkTree)params[0]); openTree((NetworkTree)params[0]);
@ -407,7 +408,7 @@ public abstract class NetworkLibraryActivity extends TreeActivity<NetworkTree> i
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
Util.initLibrary(NetworkLibraryActivity.this); Util.initLibrary(NetworkLibraryActivity.this, null);
} else { } else {
finish(); finish();
} }

View file

@ -49,12 +49,7 @@ public abstract class Util implements UserRegistrationConstants {
return intent; return intent;
} }
static void initLibrary(final Activity activity) { static void initLibrary(final Activity activity, final Runnable action) {
final NetworkLibrary library = NetworkLibrary.Instance();
if (library.isInitialized()) {
return;
}
Config.Instance().runOnConnect(new Runnable() { Config.Instance().runOnConnect(new Runnable() {
public void run() { public void run() {
UIUtil.wait("loadingNetworkLibrary", new Runnable() { UIUtil.wait("loadingNetworkLibrary", new Runnable() {
@ -63,8 +58,14 @@ public abstract class Util implements UserRegistrationConstants {
new SQLiteNetworkDatabase(activity.getApplication()); new SQLiteNetworkDatabase(activity.getApplication());
} }
final NetworkLibrary library = NetworkLibrary.Instance();
if (!library.isInitialized()) {
library.initialize(); library.initialize();
} }
if (action != null) {
action.run();
}
}
}, activity); }, activity);
} }
}); });