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

better (?) file type processing

This commit is contained in:
Nikolay Pultsin 2012-04-08 08:26:49 +01:00
parent ca274c24c6
commit 257c9fa5dd
9 changed files with 97 additions and 6 deletions

View file

@ -29,7 +29,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
import org.geometerplus.fbreader.library.Book;
import org.geometerplus.fbreader.filetype.FileTypeCollection;
public abstract class Util {
public abstract class FBUtil {
public static void shareBook(Activity activity, Book book) {
try {
final ZLPhysicalFile file = book.File.getPhysicalFile();
@ -39,7 +39,7 @@ public abstract class Util {
}
activity.startActivity(
new Intent(Intent.ACTION_SEND)
.setType(FileTypeCollection.Instance.mimeType(book.File).Name)
.setType(FileTypeCollection.Instance.simplifiedMimeType(file).Name)
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file.javaFile()))
);
} catch (ActivityNotFoundException e) {

View file

@ -33,6 +33,6 @@ public class ShareBookAction extends FBAndroidAction {
@Override
protected void run(Object ... params) {
Util.shareBook(BaseActivity, Reader.Model.Book);
FBUtil.shareBook(BaseActivity, Reader.Model.Book);
}
}

View file

@ -39,7 +39,7 @@ import org.geometerplus.fbreader.tree.FBTree;
import org.geometerplus.android.util.UIUtil;
import org.geometerplus.android.fbreader.FBReader;
import org.geometerplus.android.fbreader.Util;
import org.geometerplus.android.fbreader.FBUtil;
import org.geometerplus.android.fbreader.tree.TreeActivity;
public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItemClickListener, View.OnCreateContextMenuListener, Library.ChangeListener {
@ -218,7 +218,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem
showBookInfo(book);
return true;
case SHARE_BOOK_ITEM_ID:
Util.shareBook(this, book);
FBUtil.shareBook(this, book);
return true;
case ADD_TO_FAVORITES_ITEM_ID:
myLibrary.addBookToFavorites(book);

View file

@ -36,4 +36,7 @@ public abstract class FileType {
//public abstract String extension();
public abstract List<MimeType> mimeTypes();
public abstract MimeType mimeType(ZLFile file);
public MimeType simplifiedMimeType(ZLFile file) {
return mimeType(file);
}
}

View file

@ -30,7 +30,7 @@ public class FileTypeCollection {
private final TreeMap<String,FileType> myTypes = new TreeMap<String,FileType>();
private FileTypeCollection() {
addType(new SimpleFileType("fb2", "fb2", MimeType.TYPES_FB2));
addType(new FileTypeFB2());
addType(new FileTypeEpub());
addType(new FileTypeMobipocket());
addType(new FileTypeHtml());
@ -39,6 +39,7 @@ public class FileTypeCollection {
addType(new SimpleFileType("PDF", "pdf", MimeType.TYPES_PDF));
addType(new FileTypeDjVu());
addType(new FileTypeFB2Zip());
addType(new SimpleFileType("ZIP archive", "zip", Collections.singletonList(MimeType.APP_ZIP)));
}
private void addType(FileType type) {
@ -71,4 +72,14 @@ public class FileTypeCollection {
}
return MimeType.UNKNOWN;
}
public MimeType simplifiedMimeType(ZLFile file) {
for (FileType type : types()) {
final MimeType mime = type.simplifiedMimeType(file);
if (mime != MimeType.NULL) {
return mime;
}
}
return MimeType.UNKNOWN;
}
}

View file

@ -59,4 +59,14 @@ class FileTypeEpub extends FileType {
// TODO: process other extensions (?)
return MimeType.NULL;
}
@Override
public MimeType simplifiedMimeType(ZLFile file) {
final String extension = file.getExtension();
if ("epub".equalsIgnoreCase(extension)) {
return MimeType.APP_ZIP;
}
// TODO: process other extensions (?)
return MimeType.NULL;
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (C) 2012 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.fbreader.filetype;
import java.util.List;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.util.MimeType;
class FileTypeFB2 extends FileType {
FileTypeFB2() {
super("fb2");
}
@Override
public boolean acceptsFile(ZLFile file) {
return "fb2".equalsIgnoreCase(file.getExtension());
}
/*
@Override
public String extension() {
return "fb2";
}
*/
@Override
public List<MimeType> mimeTypes() {
return MimeType.TYPES_FB2;
}
@Override
public MimeType mimeType(ZLFile file) {
return acceptsFile(file) ? MimeType.TEXT_FB2 : MimeType.NULL;
}
@Override
public MimeType simplifiedMimeType(ZLFile file) {
return acceptsFile(file) ? MimeType.TEXT_XML : MimeType.NULL;
}
}

View file

@ -50,4 +50,9 @@ class FileTypeFB2Zip extends FileType {
public MimeType mimeType(ZLFile file) {
return acceptsFile(file) ? MimeType.APP_FB2_ZIP : MimeType.NULL;
}
@Override
public MimeType simplifiedMimeType(ZLFile file) {
return acceptsFile(file) ? MimeType.APP_ZIP : MimeType.NULL;
}
}

View file

@ -59,6 +59,8 @@ public final class MimeType {
}
// MIME types / application
// ???
public static final MimeType APP_ZIP = get("application/zip");
// unofficial, http://en.wikipedia.org/wiki/EPUB
public static final MimeType APP_EPUB_ZIP = get("application/epub+zip");
// ???
@ -81,6 +83,8 @@ public final class MimeType {
public static final MimeType APP_LITRES = get("application/litres+xml");
// MIME types / text
// ???
public static final MimeType TEXT_XML = get("text/xml");
// http://www.iana.org/assignments/media-types/text/index.html
public static final MimeType TEXT_HTML = get("text/html");
// ???