mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
new ZLResourceFile logic has been implemented
This commit is contained in:
parent
eadd934695
commit
94c8ba1885
4 changed files with 31 additions and 9 deletions
|
@ -88,6 +88,8 @@ public abstract class ZLFile {
|
|||
} else if ((parent instanceof ZLPhysicalFile) && (parent.getParent() == null)) {
|
||||
// parent is a directory
|
||||
file = new ZLPhysicalFile(parent.getPath() + '/' + name);
|
||||
} else if (parent instanceof ZLResourceFile) {
|
||||
file = ZLResourceFile.createResourceFile((ZLResourceFile)parent, name);
|
||||
} else {
|
||||
file = ZLArchiveEntryFile.createArchiveEntryFile(parent, name);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ public abstract class ZLResourceFile extends ZLFile {
|
|||
return ZLibrary.Instance().createResourceFile(path);
|
||||
}
|
||||
|
||||
static ZLResourceFile createResourceFile(ZLResourceFile parent, String name) {
|
||||
return ZLibrary.Instance().createResourceFile(parent, name);
|
||||
}
|
||||
|
||||
private final String myPath;
|
||||
|
||||
protected ZLResourceFile(String path) {
|
||||
|
@ -33,10 +37,6 @@ public abstract class ZLResourceFile extends ZLFile {
|
|||
init();
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return myPath;
|
||||
}
|
||||
|
@ -45,10 +45,6 @@ public abstract class ZLResourceFile extends ZLFile {
|
|||
return myPath.substring(myPath.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
public ZLFile getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ZLPhysicalFile getPhysicalFile() {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ public abstract class ZLibrary {
|
|||
}
|
||||
|
||||
abstract public ZLResourceFile createResourceFile(String path);
|
||||
abstract public ZLResourceFile createResourceFile(ZLResourceFile parent, String name);
|
||||
|
||||
abstract public String getVersionName();
|
||||
abstract public String getCurrentTimeString();
|
||||
|
|
|
@ -103,6 +103,11 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
return new AndroidAssetsFile(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLResourceFile createResourceFile(ZLResourceFile parent, String name) {
|
||||
return new AndroidAssetsFile((AndroidAssetsFile)parent, name);
|
||||
}
|
||||
|
||||
public ZLImage createImage(int drawableId) {
|
||||
return new ZLAndroidResourceBasedImageData(myApplication.getResources(), drawableId);
|
||||
}
|
||||
|
@ -144,8 +149,21 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
}
|
||||
|
||||
private final class AndroidAssetsFile extends ZLResourceFile {
|
||||
private final AndroidAssetsFile myParent;
|
||||
|
||||
AndroidAssetsFile(AndroidAssetsFile parent, String name) {
|
||||
super(parent.getPath().length() == 0 ? name : parent.getPath() + '/' + name);
|
||||
myParent = parent;
|
||||
}
|
||||
|
||||
AndroidAssetsFile(String path) {
|
||||
super(path);
|
||||
if (path.length() == 0) {
|
||||
myParent = null;
|
||||
} else {
|
||||
final int index = path.lastIndexOf('/');
|
||||
myParent = new AndroidAssetsFile(index >= 0 ? path.substring(0, path.lastIndexOf('/')) : "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,7 +173,7 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
if (names != null && names.length != 0) {
|
||||
ArrayList<ZLFile> files = new ArrayList<ZLFile>(names.length);
|
||||
for (String n : names) {
|
||||
files.add(new AndroidAssetsFile(getPath() + "/" + n));
|
||||
files.add(new AndroidAssetsFile(this, n));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
@ -202,5 +220,10 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
public InputStream getInputStream() throws IOException {
|
||||
return myApplication.getAssets().open(getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLFile getParent() {
|
||||
return myParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue