mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
opds-fbreader scheme support
This commit is contained in:
parent
07bc085d28
commit
e07dcbf47e
5 changed files with 64 additions and 36 deletions
|
@ -256,6 +256,12 @@
|
|||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:host="*" android:scheme="opds"/>
|
||||
</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>
|
||||
<action android:name="android.fbreader.action.ADD_OPDS_CATALOG_URL"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
|
|
@ -256,6 +256,12 @@
|
|||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:host="*" android:scheme="opds"/>
|
||||
</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>
|
||||
<action android:name="android.fbreader.action.ADD_OPDS_CATALOG_URL"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
|
|
@ -89,20 +89,30 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
}
|
||||
);
|
||||
|
||||
Util.initLibrary(this);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final String action = intent.getAction();
|
||||
myEditNotAdd = Util.EDIT_CATALOG_ACTION.equals(action);
|
||||
myEditNotAdd = Util.EDIT_CATALOG_ACTION.equals(intent.getAction());
|
||||
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;
|
||||
if (myEditNotAdd ||
|
||||
Intent.ACTION_VIEW.equals(action) ||
|
||||
Util.ADD_CATALOG_URL_ACTION.equals(action)) {
|
||||
uri = intent.getData();
|
||||
if (uri != null) {
|
||||
if ("opds".equals(uri.getScheme())) {
|
||||
uri = Uri.parse("http" + uri.toString().substring(4));
|
||||
final String scheme = uri.getScheme();
|
||||
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());
|
||||
if (link instanceof ICustomNetworkLink) {
|
||||
|
@ -114,14 +124,15 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
}
|
||||
|
||||
if (myLink != null) {
|
||||
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_summary, myLink.getSummary());
|
||||
setExtraFieldsVisibility(true);
|
||||
} else if (uri != null) {
|
||||
if ("opds".equals(uri.getScheme())) {
|
||||
uri = Uri.parse("http" + uri.toString().substring(4));
|
||||
if (myEditNotAdd) {
|
||||
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_summary, myLink.getSummary());
|
||||
setExtraFieldsVisibility(true);
|
||||
} else {
|
||||
openCatalog(uri);
|
||||
}
|
||||
} else if (uri != null) {
|
||||
loadInfoByUri(uri);
|
||||
} else {
|
||||
setExtraFieldsVisibility(false);
|
||||
|
@ -165,17 +176,20 @@ public class AddCustomCatalogActivity extends Activity {
|
|||
library.addCustomLink(myLink);
|
||||
library.synchronize();
|
||||
|
||||
final Intent intent = new Intent(
|
||||
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();
|
||||
openCatalog(myEditNotAdd ? null : uri);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
return s == null || s.length() == 0;
|
||||
}
|
||||
|
|
|
@ -77,8 +77,14 @@ public abstract class NetworkLibraryActivity extends TreeActivity<NetworkTree> i
|
|||
if (getCurrentTree() instanceof RootTree) {
|
||||
mySingleCatalog = intent.getBooleanExtra("SingleCatalog", false);
|
||||
if (!NetworkLibrary.Instance().isInitialized()) {
|
||||
Util.initLibrary(this);
|
||||
myDeferredIntent = intent;
|
||||
Util.initLibrary(this, new Runnable() {
|
||||
public void run() {
|
||||
NetworkLibrary.Instance().runBackgroundUpdate(false);
|
||||
if (intent != null) {
|
||||
openTreeByIntent(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
|
||||
openTreeByIntent(intent);
|
||||
|
@ -363,11 +369,6 @@ public abstract class NetworkLibraryActivity extends TreeActivity<NetworkTree> i
|
|||
showInitLibraryDialog((String)params[0]);
|
||||
break;
|
||||
case InitializationFinished:
|
||||
NetworkLibrary.Instance().runBackgroundUpdate(false);
|
||||
if (myDeferredIntent != null) {
|
||||
openTreeByIntent(myDeferredIntent);
|
||||
myDeferredIntent = null;
|
||||
}
|
||||
break;
|
||||
case Found:
|
||||
openTree((NetworkTree)params[0]);
|
||||
|
@ -407,7 +408,7 @@ public abstract class NetworkLibraryActivity extends TreeActivity<NetworkTree> i
|
|||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
Util.initLibrary(NetworkLibraryActivity.this);
|
||||
Util.initLibrary(NetworkLibraryActivity.this, null);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -49,12 +49,7 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
return intent;
|
||||
}
|
||||
|
||||
static void initLibrary(final Activity activity) {
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
if (library.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
static void initLibrary(final Activity activity, final Runnable action) {
|
||||
Config.Instance().runOnConnect(new Runnable() {
|
||||
public void run() {
|
||||
UIUtil.wait("loadingNetworkLibrary", new Runnable() {
|
||||
|
@ -63,7 +58,13 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
new SQLiteNetworkDatabase(activity.getApplication());
|
||||
}
|
||||
|
||||
library.initialize();
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
if (!library.isInitialized()) {
|
||||
library.initialize();
|
||||
}
|
||||
if (action != null) {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
}, activity);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue