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

open network catalogs from external applications

This commit is contained in:
Nikolay Pultsin 2011-09-25 17:47:24 +01:00
parent 557d938a55
commit cddbe40d0f
6 changed files with 51 additions and 44 deletions

View file

@ -139,6 +139,12 @@
</activity>
<activity android:name="org.geometerplus.android.fbreader.network.NetworkLibraryActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.network.NetworkSearchActivity" />
<intent-filter>
<action android:name="android.fbreader.action.OPEN_NETWORK_CATALOG" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="*" android:scheme="http" />
<data android:host="*" android:scheme="https" />
</intent-filter>
</activity>
<activity android:name="org.geometerplus.android.fbreader.network.AuthenticationActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog"/>
<activity android:name="org.geometerplus.android.fbreader.network.AddCustomCatalogActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog">

View file

@ -139,6 +139,12 @@
</activity>
<activity android:name="org.geometerplus.android.fbreader.network.NetworkLibraryActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.network.NetworkSearchActivity" />
<intent-filter>
<action android:name="android.fbreader.action.OPEN_NETWORK_CATALOG" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="*" android:scheme="http" />
<data android:host="*" android:scheme="https" />
</intent-filter>
</activity>
<activity android:name="org.geometerplus.android.fbreader.network.AuthenticationActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog"/>
<activity android:name="org.geometerplus.android.fbreader.network.AddCustomCatalogActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog">

View file

@ -42,37 +42,11 @@ import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.android.util.UIUtil;
public class AddCustomCatalogActivity extends Activity {
private static final String ADD_CATALOG_TITLE_KEY = "title";
private static final String ADD_CATALOG_SUMMARY_KEY = "summary";
private static final String ADD_CATALOG_ID_KEY = "id";
private static final String ADD_CATALOG_URLS_MAP_KEY = "urls";
public static void addLinkToIntent(Intent intent, ICustomNetworkLink link) {
Util.intentByLink(intent, link)
.putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle())
.putExtra(ADD_CATALOG_SUMMARY_KEY, link.getSummary())
.putExtra(ADD_CATALOG_ID_KEY, link.getId())
.putExtra(ADD_CATALOG_URLS_MAP_KEY, link.urlInfoMap());
}
static ICustomNetworkLink getLinkFromIntent(Intent intent) {
final Uri uri = intent.getData();
if (uri == null || !intent.hasExtra(ADD_CATALOG_ID_KEY)) {
return null;
}
return new OPDSCustomNetworkLink(
intent.getIntExtra(ADD_CATALOG_ID_KEY, ICustomNetworkLink.INVALID_ID),
uri.getHost(),
intent.getStringExtra(ADD_CATALOG_TITLE_KEY),
intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY),
null,
(UrlInfoCollection<UrlInfoWithDate>)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY)
);
}
public static String EDIT_KEY = "EditNotAdd";
private ZLResource myResource;
private volatile ICustomNetworkLink myLink;
private boolean myEditNotAdd;
@Override
public void onCreate(Bundle icicle) {
@ -114,8 +88,18 @@ public class AddCustomCatalogActivity extends Activity {
Util.initLibrary(this);
final Intent intent = getIntent();
myLink = getLinkFromIntent(intent);
final Uri uri = intent.getData();
myLink = null;
Uri uri = intent.getData();
if (uri != null) {
if ("opds".equals(uri.getScheme())) {
uri = Uri.parse("http" + uri.toString().substring(4));
}
final INetworkLink link = NetworkLibrary.Instance().getLinkByUrl(uri.toString());
if (link instanceof ICustomNetworkLink) {
myLink = (ICustomNetworkLink)link;
}
}
myEditNotAdd = intent.getBooleanExtra(EDIT_KEY, false);
if (myLink != null) {
setTextById(R.id.add_custom_catalog_url, myLink.getUrl(UrlInfo.Type.Catalog));
@ -123,6 +107,9 @@ public class AddCustomCatalogActivity extends Activity {
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));
}
loadInfoByUri(uri);
} else {
setExtraFieldsVisibility(false);
@ -167,12 +154,10 @@ public class AddCustomCatalogActivity extends Activity {
final Intent intent = new Intent(
NetworkLibraryActivity.OPEN_CATALOG_ACTION,
uri,
myEditNotAdd ? null : uri,
AddCustomCatalogActivity.this,
NetworkLibraryActivity.class
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
addLinkToIntent(intent, myLink);
startActivity(intent);
finish();
}
@ -265,8 +250,6 @@ public class AddCustomCatalogActivity extends Activity {
if (isEmptyString(uri.getScheme())) {
textUrl = "http://" + textUrl;
uri = Uri.parse(textUrl);
} else if ("opds".equals(uri.getScheme())) {
textUrl = "http" + uri.toString().substring(4);
}
setTextById(R.id.add_custom_catalog_url, textUrl);

View file

@ -24,6 +24,7 @@ import java.util.*;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.view.*;
import android.widget.AdapterView;
@ -55,6 +56,7 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
final List<Action> myOptionsMenuActions = new ArrayList<Action>();
final List<Action> myContextMenuActions = new ArrayList<Action>();
final List<Action> myListClickActions = new ArrayList<Action>();
private Intent myDeferredIntent;
@Override
public void onCreate(Bundle icicle) {
@ -71,18 +73,19 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
setListAdapter(new NetworkLibraryAdapter(this));
init(getIntent());
myDeferredIntent = null;
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
if (getCurrentTree() instanceof RootTree) {
if (!NetworkLibrary.Instance().isInitialized()) {
Util.initLibrary(this);
myDeferredIntent = getIntent();
} else {
NetworkLibrary.Instance().fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
openTreeByIntent(getIntent());
}
}
openTreeByIntent(getIntent());
}
@Override
@ -124,11 +127,14 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
private boolean openTreeByIntent(Intent intent) {
if (OPEN_CATALOG_ACTION.equals(intent.getAction())) {
final NetworkTree tree =
NetworkLibrary.Instance().getCatalogTreeByUrl(intent.getData().toString());
if (tree != null) {
new OpenCatalogAction(this).run(tree);
return true;
final Uri uri = intent.getData();
if (uri != null) {
final NetworkTree tree =
NetworkLibrary.Instance().getCatalogTreeByUrl(uri.toString());
if (tree != null) {
new OpenCatalogAction(this).run(tree);
return true;
}
}
}
return false;
@ -361,6 +367,10 @@ public class NetworkLibraryActivity extends TreeActivity implements NetworkLibra
break;
case InitializationFinished:
NetworkLibrary.Instance().runBackgroundUpdate(false);
if (myDeferredIntent != null) {
openTreeByIntent(myDeferredIntent);
myDeferredIntent = null;
}
break;
case Found:
openTree((NetworkTree)params[0]);

View file

@ -47,7 +47,7 @@ public abstract class Util implements UserRegistrationConstants {
return uri != null ? NetworkLibrary.Instance().getLinkByUrl(uri.toString()) : null;
}
static Intent intentByLink(Intent intent, INetworkLink link) {
public static Intent intentByLink(Intent intent, INetworkLink link) {
if (link != null) {
intent.setData(Uri.parse(link.getUrl(UrlInfo.Type.Catalog)));
}

View file

@ -26,6 +26,7 @@ import org.geometerplus.fbreader.network.NetworkTree;
import org.geometerplus.fbreader.network.ICustomNetworkLink;
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
import org.geometerplus.android.fbreader.network.Util;
import org.geometerplus.android.fbreader.network.AddCustomCatalogActivity;
public class EditCustomCatalogAction extends CatalogAction {
@ -43,7 +44,8 @@ public class EditCustomCatalogAction extends CatalogAction {
@Override
protected void run(NetworkTree tree) {
final Intent intent = new Intent(myActivity, AddCustomCatalogActivity.class);
AddCustomCatalogActivity.addLinkToIntent(intent, (ICustomNetworkLink)tree.getLink());
Util.intentByLink(intent, tree.getLink());
intent.putExtra(AddCustomCatalogActivity.EDIT_KEY, true);
myActivity.startActivity(intent);
}
}