mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
better in-book link processing
This commit is contained in:
parent
27e76123d9
commit
351548fdcd
5 changed files with 43 additions and 23 deletions
|
@ -314,6 +314,11 @@
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
<data android:host="*" android:scheme="litres-book"/>
|
<data android:host="*" android:scheme="litres-book"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:host="www.litres.ru" android:scheme="http" android:path="/pages/biblio_book/"/>
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.network.CatalogManagerActivity" android:process=":networkLibrary" android:theme="@style/FBReader.Activity"/>
|
<activity android:name="org.geometerplus.android.fbreader.network.CatalogManagerActivity" android:process=":networkLibrary" android:theme="@style/FBReader.Activity"/>
|
||||||
<receiver android:name="org.geometerplus.android.fbreader.network.ListenerCallback" android:process=":networkLibrary">
|
<receiver android:name="org.geometerplus.android.fbreader.network.ListenerCallback" android:process=":networkLibrary">
|
||||||
|
|
|
@ -30,8 +30,7 @@ import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
|
import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
|
||||||
import org.geometerplus.fbreader.network.NetworkLibrary;
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.network.BookDownloader;
|
import org.geometerplus.android.fbreader.network.*;
|
||||||
import org.geometerplus.android.fbreader.network.BookDownloaderService;
|
|
||||||
import org.geometerplus.android.fbreader.image.ImageViewActivity;
|
import org.geometerplus.android.fbreader.image.ImageViewActivity;
|
||||||
|
|
||||||
class ProcessHyperlinkAction extends FBAndroidAction {
|
class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
|
@ -106,7 +105,7 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
if (!url.startsWith("fbreader-action:")) {
|
if (!url.startsWith("fbreader-action:")) {
|
||||||
nLibrary.initialize(new QuietNetworkContext());
|
nLibrary.initialize(new QuietNetworkContext());
|
||||||
}
|
}
|
||||||
intent.setData(Uri.parse(nLibrary.rewriteUrl(url, externalUrl)));
|
intent.setData(Util.rewriteUri(Uri.parse(nLibrary.rewriteUrl(url, externalUrl))));
|
||||||
BaseActivity.runOnUiThread(new Runnable() {
|
BaseActivity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import android.widget.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImageProxy;
|
import org.geometerplus.zlibrary.core.image.ZLImageProxy;
|
||||||
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
|
|
||||||
|
@ -127,13 +128,17 @@ public class NetworkBookInfoActivity extends Activity implements NetworkLibrary.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myBook == null) {
|
if (myBook == null) {
|
||||||
final Uri url = getIntent().getData();
|
final Uri uri = Util.rewriteUri(getIntent().getData());
|
||||||
if (url != null && "litres-book".equals(url.getScheme())) {
|
if (uri != null && "litres-book".equals(uri.getScheme())) {
|
||||||
myBook = OPDSBookItem.create(
|
try {
|
||||||
myNetworkContext,
|
myBook = OPDSBookItem.create(
|
||||||
library.getLinkByStringId("litres.ru"),
|
myNetworkContext,
|
||||||
url.toString().replace("litres-book://", "http://")
|
library.getLinkByStringId("litres.ru"),
|
||||||
);
|
uri.toString().replace("litres-book://", "http://")
|
||||||
|
);
|
||||||
|
} catch (ZLNetworkException e) {
|
||||||
|
UIUtil.showMessageText(NetworkBookInfoActivity.this, e.getMessage());
|
||||||
|
}
|
||||||
if (myBook != null) {
|
if (myBook != null) {
|
||||||
myTree = library.getFakeBookTree(myBook);
|
myTree = library.getFakeBookTree(myBook);
|
||||||
}
|
}
|
||||||
|
@ -437,7 +442,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkLibrary.
|
||||||
|
|
||||||
public void onLibraryChanged(NetworkLibrary.ChangeListener.Code code, Object[] params) {
|
public void onLibraryChanged(NetworkLibrary.ChangeListener.Code code, Object[] params) {
|
||||||
if (code == NetworkLibrary.ChangeListener.Code.InitializationFailed) {
|
if (code == NetworkLibrary.ChangeListener.Code.InitializationFailed) {
|
||||||
// TODO: implement
|
UIUtil.showMessageText(this, (String)params[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,4 +136,20 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Uri rewriteUri(Uri uri) {
|
||||||
|
if (uri == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("http".equals(uri.getScheme()) &&
|
||||||
|
"www.litres.ru".equals(uri.getHost()) &&
|
||||||
|
"/pages/biblio_book/".equals(uri.getPath())) {
|
||||||
|
final String bookId = uri.getQueryParameter("art");
|
||||||
|
if (bookId != null && !"".equals(bookId)) {
|
||||||
|
return Uri.parse("litres-book://data.fbreader.org/catalogs/litres2/full.php5?id=" + bookId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,23 +33,18 @@ import org.geometerplus.fbreader.network.atom.*;
|
||||||
import org.geometerplus.fbreader.network.urlInfo.*;
|
import org.geometerplus.fbreader.network.urlInfo.*;
|
||||||
|
|
||||||
public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
public static OPDSBookItem create(ZLNetworkContext nc, INetworkLink link, String url) {
|
public static OPDSBookItem create(ZLNetworkContext nc, INetworkLink link, String url) throws ZLNetworkException {
|
||||||
if (link == null || url == null) {
|
if (link == null || url == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CreateBookHandler handler = new CreateBookHandler(link, url);
|
final CreateBookHandler handler = new CreateBookHandler(link, url);
|
||||||
try {
|
nc.perform(new ZLNetworkRequest.Get(url) {
|
||||||
nc.perform(new ZLNetworkRequest.Get(url) {
|
@Override
|
||||||
@Override
|
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
|
||||||
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
|
new OPDSXMLReader(handler, true).read(inputStream);
|
||||||
new OPDSXMLReader(handler, true).read(inputStream);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
} catch (ZLNetworkException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
return handler.getBook();
|
return handler.getBook();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue