mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
second (external) sd card supported
This commit is contained in:
parent
bd608b7e37
commit
605b5f12d5
2 changed files with 84 additions and 17 deletions
|
@ -79,6 +79,63 @@ public abstract class Paths {
|
|||
}
|
||||
}
|
||||
|
||||
private static void addDirToList(List<String> list, String candidate) {
|
||||
if (candidate == null || !candidate.startsWith("/")) {
|
||||
return;
|
||||
}
|
||||
for (int count = 0; count < 5; ++count) {
|
||||
while (candidate.endsWith("/")) {
|
||||
candidate = candidate.substring(0, candidate.length() - 1);
|
||||
}
|
||||
final File f = new File(candidate);
|
||||
try {
|
||||
final String canonical = f.getCanonicalPath();
|
||||
if (canonical.equals(candidate)) {
|
||||
break;
|
||||
}
|
||||
candidate = canonical;
|
||||
} catch (Throwable t) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (candidate.endsWith("/")) {
|
||||
candidate = candidate.substring(0, candidate.length() - 1);
|
||||
}
|
||||
if (!"".equals(candidate) && !list.contains(candidate) && new File(candidate).canRead()) {
|
||||
list.add(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> allCardDirectories() {
|
||||
final List<String> dirs = new LinkedList<String>();
|
||||
dirs.add(cardDirectory());
|
||||
addDirToList(dirs, System.getenv("SECONDARY_STORAGE"));
|
||||
/*
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader("/system/etc/vold.fstab"));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
final int hashIndex = line.indexOf("#");
|
||||
if (hashIndex >= 0) {
|
||||
line = line.substring(0, hashIndex);
|
||||
}
|
||||
final String[] parts = line.split("\\s+");
|
||||
if (parts.length >= 5) {
|
||||
addDirToList(dirs, parts[2]);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
return dirs;
|
||||
}
|
||||
|
||||
public static String cardDirectory() {
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
return Environment.getExternalStorageDirectory().getPath();
|
||||
|
@ -102,11 +159,9 @@ public abstract class Paths {
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +192,7 @@ public abstract class Paths {
|
|||
}
|
||||
|
||||
public static List<String> bookPath() {
|
||||
final List<String> path = new ArrayList<String>(Paths.BookPathOption.getValue());
|
||||
final List<String> path = new ArrayList<String>(BookPathOption.getValue());
|
||||
final String downloadsDirectory = DownloadsDirectoryOption.getValue();
|
||||
if (!"".equals(downloadsDirectory) && !path.contains(downloadsDirectory)) {
|
||||
path.add(downloadsDirectory);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
|
@ -43,22 +45,32 @@ public class FileFirstLevelTree extends FirstLevelTree {
|
|||
public void waitForOpening() {
|
||||
clear();
|
||||
for (String dir : Paths.BookPathOption.getValue()) {
|
||||
addChild(dir, "fileTreeLibrary", dir);
|
||||
addChild(dir, resource().getResource("fileTreeLibrary").getValue(), dir);
|
||||
}
|
||||
addChild("/", "fileTreeRoot");
|
||||
final List<String> cards = Paths.allCardDirectories();
|
||||
if (cards.size() == 1) {
|
||||
addChild(cards.get(0), "fileTreeCard");
|
||||
} else {
|
||||
final ZLResource res = resource().getResource("fileTreeCard");
|
||||
final String title = res.getResource("withIndex").getValue();
|
||||
final String summary = res.getResource("summary").getValue();
|
||||
int index = 0;
|
||||
for (String dir : cards) {
|
||||
addChild(dir, title.replaceAll("%s", String.valueOf(++index)), summary);
|
||||
}
|
||||
}
|
||||
addChild("/", "fileTreeRoot", null);
|
||||
addChild(Paths.cardDirectory(), "fileTreeCard", null);
|
||||
}
|
||||
|
||||
private void addChild(String path, String resourceKey, String summary) {
|
||||
private void addChild(String path, String title, String summary) {
|
||||
final ZLFile file = ZLFile.createFileByPath(path);
|
||||
if (file != null) {
|
||||
final ZLResource resource = resource().getResource(resourceKey);
|
||||
new FileTree(
|
||||
this,
|
||||
file,
|
||||
resource.getValue(),
|
||||
summary != null ? summary : resource.getResource("summary").getValue()
|
||||
);
|
||||
new FileTree(this, file, title, summary);
|
||||
}
|
||||
}
|
||||
|
||||
private void addChild(String path, String resourceKey) {
|
||||
final ZLResource resource = resource().getResource(resourceKey);
|
||||
addChild(path, resource.getValue(), resource.getResource("summary").getValue());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue