mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
Merge branch 'library' of github.com:geometer/FBReaderJ into library
This commit is contained in:
commit
506e37c6c7
12 changed files with 271 additions and 176 deletions
|
@ -41,6 +41,7 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageLoader;
|
|||
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
import org.geometerplus.android.fbreader.FBReader;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
|
@ -48,12 +49,21 @@ import org.geometerplus.android.util.UIUtil;
|
|||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||
|
||||
abstract class LibraryBaseActivity extends ListActivity {
|
||||
public static final String SELECTED_BOOK_PATH_KEY = "SelectedBookPath";
|
||||
static final String TREE_PATH_KEY = "TreePath";
|
||||
static final String PARAMETER_KEY = "Parameter";
|
||||
|
||||
static final String PATH_FAVORITES = "favorites";
|
||||
static final String PATH_SEARCH_RESULTS = "searchResults";
|
||||
static final String PATH_RECENT = "recent";
|
||||
static final String PATH_BY_AUTHOR = "byAuthor";
|
||||
static final String PATH_BY_TAG = "byTag";
|
||||
|
||||
static Library Library;
|
||||
|
||||
static final ZLStringOption BookSearchPatternOption =
|
||||
new ZLStringOption("BookSearch", "Pattern", "");
|
||||
|
||||
public static final String SELECTED_BOOK_PATH_KEY = "SelectedBookPath";
|
||||
|
||||
protected final ZLResource myResource = ZLResource.resource("libraryView");
|
||||
protected String mySelectedBookPath;
|
||||
|
||||
|
@ -64,11 +74,6 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView listView, View view, int position, long rowId) {
|
||||
FBTree tree = ((LibraryAdapter)getListAdapter()).getItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
startSearch(BookSearchPatternOption.getValue(), true, null, false);
|
||||
|
@ -94,25 +99,45 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
).show();
|
||||
}
|
||||
|
||||
protected final class LibraryAdapter extends BaseAdapter {
|
||||
protected final class LibraryAdapter extends BaseAdapter implements View.OnCreateContextMenuListener {
|
||||
private final List<FBTree> myItems;
|
||||
|
||||
public LibraryAdapter(List<FBTree> items) {
|
||||
myItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getCount() {
|
||||
return myItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final FBTree getItem(int position) {
|
||||
return myItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int position = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
|
||||
final LibraryTree tree = (LibraryTree)getItem(position);
|
||||
if (tree instanceof BookTree) {
|
||||
menu.setHeaderTitle(tree.getName());
|
||||
menu.add(0, OPEN_BOOK_ITEM_ID, 0, myResource.getResource("openBook").getValue());
|
||||
if (Library.isBookInFavorites(((BookTree)tree).Book)) {
|
||||
menu.add(0, REMOVE_FROM_FAVORITES_ITEM_ID, 0, myResource.getResource("removeFromFavorites").getValue());
|
||||
} else {
|
||||
menu.add(0, ADD_TO_FAVORITES_ITEM_ID, 0, myResource.getResource("addToFavorites").getValue());
|
||||
}
|
||||
if ((Library.getRemoveBookMode(((BookTree)tree).Book) & Library.REMOVE_FROM_DISK) != 0) {
|
||||
menu.add(0, DELETE_BOOK_ITEM_ID, 0, myResource.getResource("deleteBook").getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int myCoverWidth = -1;
|
||||
private int myCoverHeight = -1;
|
||||
|
||||
|
@ -125,10 +150,10 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
public View getView(int position, View convertView, final ViewGroup parent) {
|
||||
final FBTree tree = getItem(position);
|
||||
final View view = (convertView != null) ? convertView :
|
||||
LayoutInflater.from(parent.getContext()).inflate(R.layout.library_ng_tree_item, parent, false);
|
||||
LayoutInflater.from(parent.getContext()).inflate(R.layout.library_tree_item, parent, false);
|
||||
|
||||
((TextView)view.findViewById(R.id.library_ng_tree_item_name)).setText(tree.getName());
|
||||
((TextView)view.findViewById(R.id.library_ng_tree_item_childrenlist)).setText(tree.getSecondString());
|
||||
((TextView)view.findViewById(R.id.library_tree_item_name)).setText(tree.getName());
|
||||
((TextView)view.findViewById(R.id.library_tree_item_childrenlist)).setText(tree.getSecondString());
|
||||
|
||||
if (myCoverWidth == -1) {
|
||||
view.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
@ -137,7 +162,7 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
view.requestLayout();
|
||||
}
|
||||
|
||||
final ImageView coverView = (ImageView)view.findViewById(R.id.library_ng_tree_item_icon);
|
||||
final ImageView coverView = (ImageView)view.findViewById(R.id.library_tree_item_icon);
|
||||
coverView.getLayoutParams().width = myCoverWidth;
|
||||
coverView.getLayoutParams().height = myCoverHeight;
|
||||
coverView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
|
@ -182,12 +207,57 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
protected void openBook(Book book) {
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), FBReader.class)
|
||||
.setAction(Intent.ACTION_VIEW)
|
||||
.putExtra(FBReader.BOOK_PATH_KEY, book.File.getPath())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
);
|
||||
}
|
||||
|
||||
private static final int OPEN_BOOK_ITEM_ID = 0;
|
||||
private static final int ADD_TO_FAVORITES_ITEM_ID = 1;
|
||||
private static final int REMOVE_FROM_FAVORITES_ITEM_ID = 2;
|
||||
private static final int DELETE_BOOK_ITEM_ID = 3;
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
final int position = ((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).position;
|
||||
final FBTree tree = ((LibraryAdapter)getListAdapter()).getItem(position);
|
||||
if (tree instanceof BookTree) {
|
||||
final BookTree bookTree = (BookTree)tree;
|
||||
switch (item.getItemId()) {
|
||||
case OPEN_BOOK_ITEM_ID:
|
||||
openBook(bookTree.Book);
|
||||
return true;
|
||||
case ADD_TO_FAVORITES_ITEM_ID:
|
||||
Library.addBookToFavorites(bookTree.Book);
|
||||
return true;
|
||||
case REMOVE_FROM_FAVORITES_ITEM_ID:
|
||||
Library.removeBookFromFavorites(bookTree.Book);
|
||||
getListView().invalidateViews();
|
||||
return true;
|
||||
case DELETE_BOOK_ITEM_ID:
|
||||
// TODO: implement
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
protected class OpenTreeRunnable implements Runnable {
|
||||
private final String myTreePath;
|
||||
private final String myParameter;
|
||||
private final String mySelectedBookPath;
|
||||
|
||||
public OpenTreeRunnable(String treePath, String selectedBookPath) {
|
||||
this(treePath, null, selectedBookPath);
|
||||
}
|
||||
|
||||
public OpenTreeRunnable(String treePath, String parameter, String selectedBookPath) {
|
||||
myTreePath = treePath;
|
||||
myParameter = parameter;
|
||||
mySelectedBookPath = selectedBookPath;
|
||||
}
|
||||
|
||||
|
@ -197,7 +267,8 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
startActivity(
|
||||
new Intent(LibraryBaseActivity.this, LibraryTreeActivity.class)
|
||||
.putExtra(SELECTED_BOOK_PATH_KEY, mySelectedBookPath)
|
||||
.putExtra(LibraryTreeActivity.TREE_PATH_KEY, myTreePath)
|
||||
.putExtra(TREE_PATH_KEY, myTreePath)
|
||||
.putExtra(PARAMETER_KEY, myParameter)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue