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

platform-independent code has been moved to non-android directory

This commit is contained in:
Nikolay Pultsin 2011-07-14 15:45:30 +01:00
parent 15a0394ccf
commit 0ae1f66dda
6 changed files with 44 additions and 35 deletions

View file

@ -167,41 +167,8 @@ abstract class BaseActivity extends ListActivity implements View.OnCreateContext
}
boolean isTreeSelected(FBTree tree) {
if (mySelectedBook == null) {
return false;
}
if (((LibraryTree)tree).containsBook(mySelectedBook)) {
return true;
}
final Book book = ((LibraryTree)tree).getBook();
if (book != null) {
return mySelectedBook.equals(book);
} else if (tree instanceof SeriesTree) {
final SeriesInfo info = mySelectedBook.getSeriesInfo();
final String series = ((SeriesTree)tree).Series;
return info != null && series != null && series.equals(info.Name);
} else if (tree instanceof FileTree) {
final FileTree fileTree = (FileTree)tree;
if (!fileTree.isSelectable()) {
return false;
}
final ZLFile file = fileTree.getFile();
String prefix = file.getPath();
if (file.isDirectory()) {
if (!prefix.endsWith("/")) {
prefix += '/';
}
} else if (file.isArchive()) {
prefix += ':';
} else {
return false;
}
return mySelectedBookPath.startsWith(prefix);
}
return false;
final LibraryTree lTree = (LibraryTree)tree;
return lTree.isSelectable() && lTree.containsBook(mySelectedBook);
}
protected void openBook(Book book) {

View file

@ -69,4 +69,9 @@ public class BookTree extends LibraryTree {
protected ZLImage createCover() {
return Library.getCover(Book.File);
}
@Override
public boolean containsBook(Book book) {
return book != null && book.equals(Book);
}
}

View file

@ -91,6 +91,7 @@ public class FileTree extends LibraryTree {
return null;
}
@Override
public boolean isSelectable() {
return myIsSelectable;
}
@ -109,6 +110,24 @@ public class FileTree extends LibraryTree {
return Book.getByFile(myFile);
}
@Override
public boolean containsBook(Book book) {
if (book == null) {
return false;
}
if (myFile.isDirectory()) {
String prefix = myFile.getPath();
if (!prefix.endsWith("/")) {
prefix += "/";
}
return book.File.getPath().startsWith(prefix);
} else if (myFile.isArchive()) {
return book.File.getPath().startsWith(myFile.getPath() + ":");
} else {
return book.equals(getBook());
}
}
@Override
public Status getOpeningStatus() {
if (!myFile.isReadable()) {

View file

@ -44,6 +44,10 @@ public abstract class LibraryTree extends FBTree {
return false;
}
public boolean isSelectable() {
return true;
}
TagTree createTagSubTree(Tag tag) {
return new TagTree(this, tag);
}

View file

@ -69,4 +69,9 @@ public class RootTree extends LibraryTree {
public void waitForOpening() {
myLibrary.waitForState(Library.STATE_FULLY_INITIALIZED);
}
@Override
public boolean isSelectable() {
return false;
}
}

View file

@ -40,4 +40,13 @@ public final class SeriesTree extends LibraryTree {
BookTree createBookInSeriesSubTree(Book book) {
return new BookInSeriesTree(this, book);
}
@Override
public boolean containsBook(Book book) {
if (book == null) {
return false;
}
final SeriesInfo info = book.getSeriesInfo();
return info != null && Series.equals(info.Name);
}
}