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

Autjor/Series/Tag selection in library

This commit is contained in:
Nikolay Pultsin 2011-01-12 00:47:17 +00:00
parent e8cdee8255
commit acdfd1fdc9
7 changed files with 79 additions and 18 deletions

View file

@ -1,3 +1,7 @@
===== 0.99.4 (Jan ??, 2011) =====
* A list of dictionaries is supported (ColorDict, Fora)
* Author of currently opened book is selected in library (same for series and tags)
===== 0.99.3 (Jan 08, 2011) =====
* All word navigation mode is disabled by default; corresponding option in dictionary preferences works correctly
* Czech resources have been updated (by Marek Pavelka)

View file

@ -50,6 +50,8 @@ abstract class LibraryBaseActivity extends BaseActivity implements MenuItem.OnMe
static final ZLStringOption BookSearchPatternOption =
new ZLStringOption("BookSearch", "Pattern", "");
protected Book mySelectedBook;
@Override
protected void onActivityResult(int requestCode, int returnCode, Intent intent) {
if (requestCode == CHILD_LIST_REQUEST && returnCode == RESULT_DO_INVALIDATE_VIEWS) {
@ -114,6 +116,17 @@ abstract class LibraryBaseActivity extends BaseActivity implements MenuItem.OnMe
return myItems.size();
}
public int getFirstSelectedItemIndex() {
int index = 0;
for (FBTree t : myItems) {
if (isTreeSelected(t)) {
return index;
}
++index;
}
return -1;
}
public final FBTree getItem(int position) {
return myItems.get(position);
}
@ -133,9 +146,7 @@ abstract class LibraryBaseActivity extends BaseActivity implements MenuItem.OnMe
public View getView(int position, View convertView, final ViewGroup parent) {
final FBTree tree = getItem(position);
final View view = createView(convertView, parent, tree.getName(), tree.getSecondString());
if (tree instanceof BookTree &&
mySelectedBookPath != null &&
mySelectedBookPath.equals(((BookTree)tree).Book.File.getPath())) {
if (isTreeSelected(tree)) {
view.setBackgroundColor(0xff808080);
} else {
view.setBackgroundColor(0);
@ -180,6 +191,36 @@ abstract class LibraryBaseActivity extends BaseActivity implements MenuItem.OnMe
getListView().invalidateViews();
}
protected boolean isTreeSelected(FBTree tree) {
if (mySelectedBook == null) {
return false;
}
if (tree instanceof BookTree) {
return mySelectedBook.equals(((BookTree)tree).Book);
}
if (tree instanceof AuthorTree) {
return mySelectedBook.authors().contains(((AuthorTree)tree).Author);
}
if (tree instanceof SeriesTree) {
final SeriesInfo info = mySelectedBook.getSeriesInfo();
final String series = ((SeriesTree)tree).Series;
return info != null && series != null && series.equals(info.Name);
}
if (tree instanceof TagTree) {
final Tag tag = ((TagTree)tree).Tag;
for (Tag t : mySelectedBook.tags()) {
for (; t != null; t = t.Parent) {
if (t == tag) {
return true;
}
}
}
return false;
}
return false;
}
protected class StartTreeActivityRunnable implements Runnable {
private final String myTreePath;
private final String myParameter;

View file

@ -24,6 +24,9 @@ import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.fbreader.library.Book;
import org.geometerplus.fbreader.library.BookTree;
import org.geometerplus.fbreader.tree.FBTree;
@ -89,11 +92,21 @@ public class LibraryTreeActivity extends LibraryBaseActivity {
}
tree = tree.getSubTreeByName(path[i]);
}
mySelectedBook = null;
if (mySelectedBookPath != null) {
final ZLFile file = ZLFile.createFileByPath(mySelectedBookPath);
if (file != null) {
mySelectedBook = Book.getByFile(file);
}
}
if (tree != null) {
final LibraryAdapter adapter = new LibraryAdapter(tree.subTrees());
setListAdapter(adapter);
getListView().setOnCreateContextMenuListener(adapter);
System.err.println("SELECTED: " + adapter.getFirstSelectedItemIndex());
setSelection(adapter.getFirstSelectedItemIndex());
}
}

View file

@ -22,25 +22,26 @@ package org.geometerplus.fbreader.library;
import org.geometerplus.zlibrary.core.resources.ZLResource;
public class AuthorTree extends LibraryTree {
private final Author myAuthor;
public final Author Author;
AuthorTree(LibraryTree parent, Author author) {
super(parent);
myAuthor = author;
Author = author;
}
SeriesTree createSeriesSubTree(String series) {
return new SeriesTree(this, series);
}
@Override
public String getName() {
return
(myAuthor != null) ?
myAuthor.DisplayName :
(Author != null) ?
Author.DisplayName :
ZLResource.resource("library").getResource("unknownAuthor").getValue();
}
protected String getSortKey() {
return (myAuthor != null) ? myAuthor.SortKey : null;
return (Author != null) ? Author.SortKey : null;
}
}

View file

@ -63,7 +63,7 @@ public class Book {
}
final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
if ((physicalFile != null) && !physicalFile.exists()) {
if (physicalFile != null && !physicalFile.exists()) {
return null;
}

View file

@ -19,16 +19,17 @@
package org.geometerplus.fbreader.library;
final class SeriesTree extends LibraryTree {
private final String mySeries;
public final class SeriesTree extends LibraryTree {
public final String Series;
SeriesTree(LibraryTree parent, String series) {
super(parent);
mySeries = series;
Series = series;
}
@Override
public String getName() {
return mySeries;
return Series;
}
BookTree createBookInSeriesSubTree(Book book) {

View file

@ -22,21 +22,22 @@ package org.geometerplus.fbreader.library;
import org.geometerplus.zlibrary.core.resources.ZLResource;
public final class TagTree extends LibraryTree {
private final Tag myTag;
public final Tag Tag;
TagTree(LibraryTree parent, Tag tag) {
super(parent);
myTag = tag;
Tag = tag;
}
@Override
public String getName() {
return
(myTag != null) ?
myTag.Name :
(Tag != null) ?
Tag.Name :
ZLResource.resource("library").getResource("booksWithNoTags").getValue();
}
protected String getSortKey() {
return (myTag != null) ? myTag.Name : null;
return (Tag != null) ? Tag.Name : null;
}
}