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())) {
|
||||
uri = uri.buildUpon().scheme("http").build();
|
||||
intent.putExtra(BookDownloaderService.BOOK_FORMAT_KEY,
|
||||
BookUrlInfo.Format.EPUB);
|
||||
intent.putExtra(BookDownloaderService.BOOK_FORMAT_KEY, BookUrlInfo.Format.EPUB.Extension);
|
||||
}
|
||||
|
||||
startService(
|
||||
|
|
|
@ -108,7 +108,8 @@ public class BookDownloaderService extends Service {
|
|||
final int notifications = intent.getIntExtra(SHOW_NOTIFICATIONS_KEY, 0);
|
||||
|
||||
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);
|
||||
if (referenceType == null) {
|
||||
referenceType = UrlInfo.Type.Book;
|
||||
|
|
|
@ -123,7 +123,7 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
activity.startService(
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse(ref.Url),
|
||||
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.CLEAN_URL_KEY, ref.cleanUrl())
|
||||
.putExtra(BookDownloaderService.TITLE_KEY, book.Title)
|
||||
|
|
|
@ -151,7 +151,7 @@ public class NetworkBookItem extends NetworkItem {
|
|||
continue;
|
||||
}
|
||||
final BookUrlInfo br = (BookUrlInfo)r;
|
||||
if (reference == null || br.BookFormat > reference.BookFormat) {
|
||||
if (reference == null || br.BookFormat.compareTo(reference.BookFormat) > 0) {
|
||||
reference = br;
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public class NetworkBookItem extends NetworkItem {
|
|||
if ((type == UrlInfo.Type.Book ||
|
||||
type == UrlInfo.Type.BookConditional ||
|
||||
(!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);
|
||||
if (name != null) {
|
||||
reference = br;
|
||||
|
|
|
@ -152,8 +152,8 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
|||
} else if (referenceType == UrlInfo.Type.TOC) {
|
||||
urls.addInfo(new UrlInfo(referenceType, href, mime));
|
||||
} else if (referenceType != null) {
|
||||
final int format = formatByMimeType(mime);
|
||||
if (format != BookUrlInfo.Format.NONE) {
|
||||
final BookUrlInfo.Format format = formatByMimeType(mime);
|
||||
if (!BookUrlInfo.Format.NONE.equals(format)) {
|
||||
urls.addInfo(new BookUrlInfo(referenceType, format, href, mime));
|
||||
}
|
||||
}
|
||||
|
@ -194,8 +194,8 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
|||
boolean added = false;
|
||||
for (String f : opdsLink.Formats) {
|
||||
final MimeType mime = MimeType.get(f);
|
||||
final int format = formatByMimeType(mime);
|
||||
if (format != BookUrlInfo.Format.NONE) {
|
||||
final BookUrlInfo.Format format = formatByMimeType(mime);
|
||||
if (!BookUrlInfo.Format.NONE.equals(format)) {
|
||||
urls.addInfo(new BookBuyUrlInfo(type, format, href, mime, price));
|
||||
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)) {
|
||||
return BookUrlInfo.Format.FB2;
|
||||
} else if (MimeType.APP_FB2_ZIP.equals(mime)) {
|
||||
|
|
|
@ -114,7 +114,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
|||
}
|
||||
|
||||
String id = null;
|
||||
int idType = 0;
|
||||
BookUrlInfo.Format idType = BookUrlInfo.Format.NONE;
|
||||
|
||||
final OPDSNetworkLink opdsLink = (OPDSNetworkLink)myData.Link;
|
||||
for (ATOMLink link : entry.Links) {
|
||||
|
@ -124,14 +124,14 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
|||
if (rel == null && MimeType.APP_ATOM_XML.weakEquals(mime)) {
|
||||
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)
|
||||
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX)) {
|
||||
relType = OPDSBookItem.formatByMimeType(mime);
|
||||
}
|
||||
if (relType != BookUrlInfo.Format.NONE
|
||||
&& (id == null || idType < relType
|
||||
|| (idType == relType && REL_ACQUISITION.equals(rel)))) {
|
||||
if (!BookUrlInfo.Format.NONE.equals(relType)
|
||||
&& (id == null || idType.compareTo(relType) < 0
|
||||
|| (idType.equals(relType) && REL_ACQUISITION.equals(rel)))) {
|
||||
id = ZLNetworkUtil.url(myBaseURL, link.getHref());
|
||||
idType = relType;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
|||
final MimeType mime = MimeType.get(link.getType());
|
||||
final String rel = opdsLink.relation(link.getRel(), mime);
|
||||
if (rel == null
|
||||
? (OPDSBookItem.formatByMimeType(mime) != BookUrlInfo.Format.NONE)
|
||||
? (!BookUrlInfo.Format.NONE.equals(OPDSBookItem.formatByMimeType(mime)))
|
||||
: (rel.startsWith(REL_ACQUISITION_PREFIX)
|
||||
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX))) {
|
||||
hasBookLink = true;
|
||||
|
|
|
@ -27,7 +27,7 @@ public class BookBuyUrlInfo extends BookUrlInfo {
|
|||
|
||||
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);
|
||||
Price = price;
|
||||
}
|
||||
|
|
|
@ -20,36 +20,76 @@
|
|||
package org.geometerplus.fbreader.network.urlInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
|
||||
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)
|
||||
|
||||
public class BookUrlInfo extends UrlInfo {
|
||||
private static final long serialVersionUID = -893514485257788221L;
|
||||
|
||||
public interface Format {
|
||||
int NONE = 0;
|
||||
int MOBIPOCKET = 1;
|
||||
int FB2 = 2;
|
||||
int FB2_ZIP = 3;
|
||||
int EPUB = 4;
|
||||
public static final class Format implements Comparable<Format> {
|
||||
public static final Format NONE = new Format(null, -1);
|
||||
public static final Format MOBIPOCKET = new Format("mobi", 1);
|
||||
public static final Format FB2 = new Format("fb2", 2);
|
||||
public static final Format FB2_ZIP = new Format("fb2.zip", 3);
|
||||
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;
|
||||
}
|
||||
|
||||
public final int BookFormat;
|
||||
private Format(String extension, int priority) {
|
||||
Extension = extension;
|
||||
myPriority = priority;
|
||||
}
|
||||
|
||||
public BookUrlInfo(Type type, int format, String url, MimeType mime) {
|
||||
@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 Format BookFormat;
|
||||
|
||||
public BookUrlInfo(Type type, Format format, String url, MimeType mime) {
|
||||
super(type, url, mime);
|
||||
BookFormat = format;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
String host = uri.getHost();
|
||||
|
@ -91,21 +131,9 @@ public class BookUrlInfo extends UrlInfo {
|
|||
}
|
||||
|
||||
String ext = null;
|
||||
switch (format) {
|
||||
case Format.EPUB:
|
||||
ext = ".epub";
|
||||
break;
|
||||
case Format.MOBIPOCKET:
|
||||
ext = ".mobi";
|
||||
break;
|
||||
case Format.FB2:
|
||||
ext = ".fb2";
|
||||
break;
|
||||
case Format.FB2_ZIP:
|
||||
ext = ".fb2.zip";
|
||||
break;
|
||||
if (format != null && !MiscUtil.isEmptyString(format.Extension)) {
|
||||
ext = "." + format.Extension;
|
||||
}
|
||||
|
||||
if (ext == null) {
|
||||
int j = path.indexOf(".", nameIndex); // using not lastIndexOf to preserve extensions like `.fb2.zip`
|
||||
if (j != -1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue