mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
synchronization with beta branch
This commit is contained in:
parent
cf33d3c13b
commit
57b9e75a8d
8 changed files with 71 additions and 43 deletions
|
@ -68,8 +68,7 @@ public class BookDownloader extends Activity {
|
||||||
}
|
}
|
||||||
if ("epub".equals(uri.getScheme())) {
|
if ("epub".equals(uri.getScheme())) {
|
||||||
uri = uri.buildUpon().scheme("http").build();
|
uri = uri.buildUpon().scheme("http").build();
|
||||||
intent.putExtra(BookDownloaderService.BOOK_FORMAT_KEY,
|
intent.putExtra(BookDownloaderService.BOOK_FORMAT_KEY, BookUrlInfo.Format.EPUB.Extension);
|
||||||
BookUrlInfo.Format.EPUB);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startService(
|
startService(
|
||||||
|
|
|
@ -108,7 +108,8 @@ public class BookDownloaderService extends Service {
|
||||||
final int notifications = intent.getIntExtra(SHOW_NOTIFICATIONS_KEY, 0);
|
final int notifications = intent.getIntExtra(SHOW_NOTIFICATIONS_KEY, 0);
|
||||||
|
|
||||||
final String url = uri.toString();
|
final String url = uri.toString();
|
||||||
final int bookFormat = intent.getIntExtra(BOOK_FORMAT_KEY, BookUrlInfo.Format.NONE);
|
final BookUrlInfo.Format bookFormat =
|
||||||
|
new BookUrlInfo.Format(intent.getStringExtra(BOOK_FORMAT_KEY));
|
||||||
UrlInfo.Type referenceType = (UrlInfo.Type)intent.getSerializableExtra(REFERENCE_TYPE_KEY);
|
UrlInfo.Type referenceType = (UrlInfo.Type)intent.getSerializableExtra(REFERENCE_TYPE_KEY);
|
||||||
if (referenceType == null) {
|
if (referenceType == null) {
|
||||||
referenceType = UrlInfo.Type.Book;
|
referenceType = UrlInfo.Type.Book;
|
||||||
|
|
|
@ -123,7 +123,7 @@ public abstract class Util implements UserRegistrationConstants {
|
||||||
activity.startService(
|
activity.startService(
|
||||||
new Intent(Intent.ACTION_VIEW, Uri.parse(ref.Url),
|
new Intent(Intent.ACTION_VIEW, Uri.parse(ref.Url),
|
||||||
activity.getApplicationContext(), BookDownloaderService.class)
|
activity.getApplicationContext(), BookDownloaderService.class)
|
||||||
.putExtra(BookDownloaderService.BOOK_FORMAT_KEY, ref.BookFormat)
|
.putExtra(BookDownloaderService.BOOK_FORMAT_KEY, ref.BookFormat.Extension)
|
||||||
.putExtra(BookDownloaderService.REFERENCE_TYPE_KEY, resolvedType)
|
.putExtra(BookDownloaderService.REFERENCE_TYPE_KEY, resolvedType)
|
||||||
.putExtra(BookDownloaderService.CLEAN_URL_KEY, ref.cleanUrl())
|
.putExtra(BookDownloaderService.CLEAN_URL_KEY, ref.cleanUrl())
|
||||||
.putExtra(BookDownloaderService.TITLE_KEY, book.Title)
|
.putExtra(BookDownloaderService.TITLE_KEY, book.Title)
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class NetworkBookItem extends NetworkItem {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final BookUrlInfo br = (BookUrlInfo)r;
|
final BookUrlInfo br = (BookUrlInfo)r;
|
||||||
if (reference == null || br.BookFormat > reference.BookFormat) {
|
if (reference == null || br.BookFormat.compareTo(reference.BookFormat) > 0) {
|
||||||
reference = br;
|
reference = br;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ public class NetworkBookItem extends NetworkItem {
|
||||||
if ((type == UrlInfo.Type.Book ||
|
if ((type == UrlInfo.Type.Book ||
|
||||||
type == UrlInfo.Type.BookConditional ||
|
type == UrlInfo.Type.BookConditional ||
|
||||||
(!hasBuyReference && type == UrlInfo.Type.BookFullOrDemo)) &&
|
(!hasBuyReference && type == UrlInfo.Type.BookFullOrDemo)) &&
|
||||||
(reference == null || br.BookFormat > reference.BookFormat)) {
|
(reference == null || br.BookFormat.compareTo(reference.BookFormat) > 0)) {
|
||||||
String name = br.localCopyFileName(UrlInfo.Type.Book);
|
String name = br.localCopyFileName(UrlInfo.Type.Book);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
reference = br;
|
reference = br;
|
||||||
|
|
|
@ -152,8 +152,8 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
} else if (referenceType == UrlInfo.Type.TOC) {
|
} else if (referenceType == UrlInfo.Type.TOC) {
|
||||||
urls.addInfo(new UrlInfo(referenceType, href, mime));
|
urls.addInfo(new UrlInfo(referenceType, href, mime));
|
||||||
} else if (referenceType != null) {
|
} else if (referenceType != null) {
|
||||||
final int format = formatByMimeType(mime);
|
final BookUrlInfo.Format format = formatByMimeType(mime);
|
||||||
if (format != BookUrlInfo.Format.NONE) {
|
if (!BookUrlInfo.Format.NONE.equals(format)) {
|
||||||
urls.addInfo(new BookUrlInfo(referenceType, format, href, mime));
|
urls.addInfo(new BookUrlInfo(referenceType, format, href, mime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,8 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
boolean added = false;
|
boolean added = false;
|
||||||
for (String f : opdsLink.Formats) {
|
for (String f : opdsLink.Formats) {
|
||||||
final MimeType mime = MimeType.get(f);
|
final MimeType mime = MimeType.get(f);
|
||||||
final int format = formatByMimeType(mime);
|
final BookUrlInfo.Format format = formatByMimeType(mime);
|
||||||
if (format != BookUrlInfo.Format.NONE) {
|
if (!BookUrlInfo.Format.NONE.equals(format)) {
|
||||||
urls.addInfo(new BookBuyUrlInfo(type, format, href, mime, price));
|
urls.addInfo(new BookBuyUrlInfo(type, format, href, mime, price));
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int formatByMimeType(MimeType mime) {
|
static BookUrlInfo.Format formatByMimeType(MimeType mime) {
|
||||||
if (MimeType.TEXT_FB2.equals(mime)) {
|
if (MimeType.TEXT_FB2.equals(mime)) {
|
||||||
return BookUrlInfo.Format.FB2;
|
return BookUrlInfo.Format.FB2;
|
||||||
} else if (MimeType.APP_FB2_ZIP.equals(mime)) {
|
} else if (MimeType.APP_FB2_ZIP.equals(mime)) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = null;
|
String id = null;
|
||||||
int idType = 0;
|
BookUrlInfo.Format idType = BookUrlInfo.Format.NONE;
|
||||||
|
|
||||||
final OPDSNetworkLink opdsLink = (OPDSNetworkLink)myData.Link;
|
final OPDSNetworkLink opdsLink = (OPDSNetworkLink)myData.Link;
|
||||||
for (ATOMLink link : entry.Links) {
|
for (ATOMLink link : entry.Links) {
|
||||||
|
@ -124,14 +124,14 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
||||||
if (rel == null && MimeType.APP_ATOM_XML.weakEquals(mime)) {
|
if (rel == null && MimeType.APP_ATOM_XML.weakEquals(mime)) {
|
||||||
return ZLNetworkUtil.url(myBaseURL, link.getHref());
|
return ZLNetworkUtil.url(myBaseURL, link.getHref());
|
||||||
}
|
}
|
||||||
int relType = BookUrlInfo.Format.NONE;
|
BookUrlInfo.Format relType = BookUrlInfo.Format.NONE;
|
||||||
if (rel == null || rel.startsWith(REL_ACQUISITION_PREFIX)
|
if (rel == null || rel.startsWith(REL_ACQUISITION_PREFIX)
|
||||||
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX)) {
|
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX)) {
|
||||||
relType = OPDSBookItem.formatByMimeType(mime);
|
relType = OPDSBookItem.formatByMimeType(mime);
|
||||||
}
|
}
|
||||||
if (relType != BookUrlInfo.Format.NONE
|
if (!BookUrlInfo.Format.NONE.equals(relType)
|
||||||
&& (id == null || idType < relType
|
&& (id == null || idType.compareTo(relType) < 0
|
||||||
|| (idType == relType && REL_ACQUISITION.equals(rel)))) {
|
|| (idType.equals(relType) && REL_ACQUISITION.equals(rel)))) {
|
||||||
id = ZLNetworkUtil.url(myBaseURL, link.getHref());
|
id = ZLNetworkUtil.url(myBaseURL, link.getHref());
|
||||||
idType = relType;
|
idType = relType;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
||||||
final MimeType mime = MimeType.get(link.getType());
|
final MimeType mime = MimeType.get(link.getType());
|
||||||
final String rel = opdsLink.relation(link.getRel(), mime);
|
final String rel = opdsLink.relation(link.getRel(), mime);
|
||||||
if (rel == null
|
if (rel == null
|
||||||
? (OPDSBookItem.formatByMimeType(mime) != BookUrlInfo.Format.NONE)
|
? (!BookUrlInfo.Format.NONE.equals(OPDSBookItem.formatByMimeType(mime)))
|
||||||
: (rel.startsWith(REL_ACQUISITION_PREFIX)
|
: (rel.startsWith(REL_ACQUISITION_PREFIX)
|
||||||
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX))) {
|
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX))) {
|
||||||
hasBookLink = true;
|
hasBookLink = true;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class BookBuyUrlInfo extends BookUrlInfo {
|
||||||
|
|
||||||
public final Money Price;
|
public final Money Price;
|
||||||
|
|
||||||
public BookBuyUrlInfo(Type type, int format, String url, MimeType mime, Money price) {
|
public BookBuyUrlInfo(Type type, Format format, String url, MimeType mime, Money price) {
|
||||||
super(type, format, url, mime);
|
super(type, format, url, mime);
|
||||||
Price = price;
|
Price = price;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,36 +20,76 @@
|
||||||
package org.geometerplus.fbreader.network.urlInfo;
|
package org.geometerplus.fbreader.network.urlInfo;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.Paths;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.Paths;
|
||||||
|
|
||||||
// resolvedReferenceType -- reference type without any ambiguity (for example, DOWNLOAD_FULL_OR_DEMO is ambiguous)
|
// resolvedReferenceType -- reference type without any ambiguity (for example, DOWNLOAD_FULL_OR_DEMO is ambiguous)
|
||||||
|
|
||||||
public class BookUrlInfo extends UrlInfo {
|
public class BookUrlInfo extends UrlInfo {
|
||||||
private static final long serialVersionUID = -893514485257788221L;
|
private static final long serialVersionUID = -893514485257788221L;
|
||||||
|
|
||||||
public interface Format {
|
public static final class Format implements Comparable<Format> {
|
||||||
int NONE = 0;
|
public static final Format NONE = new Format(null, -1);
|
||||||
int MOBIPOCKET = 1;
|
public static final Format MOBIPOCKET = new Format("mobi", 1);
|
||||||
int FB2 = 2;
|
public static final Format FB2 = new Format("fb2", 2);
|
||||||
int FB2_ZIP = 3;
|
public static final Format FB2_ZIP = new Format("fb2.zip", 3);
|
||||||
int EPUB = 4;
|
public static final Format EPUB = new Format("epub", 4);
|
||||||
|
|
||||||
|
public final String Extension;
|
||||||
|
private final int myPriority;
|
||||||
|
|
||||||
|
public Format(String extension) {
|
||||||
|
Extension = extension;
|
||||||
|
int priority = 0;
|
||||||
|
for (Format f : Arrays.asList(NONE, MOBIPOCKET, FB2, FB2_ZIP, EPUB)) {
|
||||||
|
if (f.equals(this)) {
|
||||||
|
priority = f.myPriority;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myPriority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Format(String extension, int priority) {
|
||||||
|
Extension = extension;
|
||||||
|
myPriority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return other instanceof Format && MiscUtil.equals(Extension, ((Format)other).Extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return MiscUtil.hashCode(Extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Format format) {
|
||||||
|
return myPriority - format.myPriority;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int BookFormat;
|
public final Format BookFormat;
|
||||||
|
|
||||||
public BookUrlInfo(Type type, int format, String url, MimeType mime) {
|
public BookUrlInfo(Type type, Format format, String url, MimeType mime) {
|
||||||
super(type, url, mime);
|
super(type, url, mime);
|
||||||
BookFormat = format;
|
BookFormat = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TOESCAPE = "<>:\"|?*\\";
|
private static final String TOESCAPE = "<>:\"|?*\\";
|
||||||
|
|
||||||
public static String makeBookFileName(String url, int format, Type resolvedReferenceType) {
|
public static String makeBookFileName(String url, Format format, Type resolvedReferenceType) {
|
||||||
final Uri uri = Uri.parse(url);
|
final Uri uri = Uri.parse(url);
|
||||||
|
|
||||||
String host = uri.getHost();
|
String host = uri.getHost();
|
||||||
|
@ -91,21 +131,9 @@ public class BookUrlInfo extends UrlInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
String ext = null;
|
String ext = null;
|
||||||
switch (format) {
|
if (format != null && !MiscUtil.isEmptyString(format.Extension)) {
|
||||||
case Format.EPUB:
|
ext = "." + format.Extension;
|
||||||
ext = ".epub";
|
|
||||||
break;
|
|
||||||
case Format.MOBIPOCKET:
|
|
||||||
ext = ".mobi";
|
|
||||||
break;
|
|
||||||
case Format.FB2:
|
|
||||||
ext = ".fb2";
|
|
||||||
break;
|
|
||||||
case Format.FB2_ZIP:
|
|
||||||
ext = ".fb2.zip";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ext == null) {
|
if (ext == null) {
|
||||||
int j = path.indexOf(".", nameIndex); // using not lastIndexOf to preserve extensions like `.fb2.zip`
|
int j = path.indexOf(".", nameIndex); // using not lastIndexOf to preserve extensions like `.fb2.zip`
|
||||||
if (j != -1) {
|
if (j != -1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue