mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
code cleanup: ListAdapter doesnot depend on library code
This commit is contained in:
parent
63e99307bd
commit
6cbc5fd2bd
2 changed files with 12 additions and 20 deletions
|
@ -43,7 +43,7 @@ import org.geometerplus.android.fbreader.FBReader;
|
|||
import org.geometerplus.android.fbreader.BookInfoActivity;
|
||||
import org.geometerplus.android.fbreader.SQLiteBooksDatabase;
|
||||
|
||||
abstract class BaseActivity extends ListActivity {
|
||||
abstract class BaseActivity extends ListActivity implements View.OnCreateContextMenuListener {
|
||||
private static class FBTreeInfo {
|
||||
final int CoverResourceId;
|
||||
final Runnable Action;
|
||||
|
@ -111,6 +111,7 @@ abstract class BaseActivity extends ListActivity {
|
|||
}
|
||||
|
||||
setResult(RESULT_DONT_INVALIDATE_VIEWS);
|
||||
getListView().setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -236,7 +237,15 @@ abstract class BaseActivity extends ListActivity {
|
|||
);
|
||||
}
|
||||
|
||||
protected void createBookContextMenu(ContextMenu menu, Book book) {
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int position = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
|
||||
final Book book = ((LibraryTree)getListAdapter().getItem(position)).getBook();
|
||||
if (book != null) {
|
||||
createBookContextMenu(menu, book);
|
||||
}
|
||||
}
|
||||
|
||||
private void createBookContextMenu(ContextMenu menu, Book book) {
|
||||
final ZLResource resource = Library.resource();
|
||||
menu.setHeaderTitle(book.getTitle());
|
||||
menu.add(0, OPEN_BOOK_ITEM_ID, 0, resource.getResource("openBook").getValue());
|
||||
|
|
|
@ -33,11 +33,8 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
|
|||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.library.BookTree;
|
||||
import org.geometerplus.fbreader.library.FileTree;
|
||||
|
||||
public class ListAdapter extends BaseAdapter implements View.OnCreateContextMenuListener {
|
||||
public class ListAdapter extends BaseAdapter {
|
||||
private final BaseActivity myActivity;
|
||||
private final List<FBTree> myItems;
|
||||
|
||||
|
@ -45,7 +42,6 @@ public class ListAdapter extends BaseAdapter implements View.OnCreateContextMenu
|
|||
myActivity = activity;
|
||||
myItems = Collections.synchronizedList(items);
|
||||
activity.setListAdapter(this);
|
||||
activity.getListView().setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -193,17 +189,4 @@ public class ListAdapter extends BaseAdapter implements View.OnCreateContextMenu
|
|||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int position = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
|
||||
final FBTree tree = getItem(position);
|
||||
if (tree instanceof BookTree) {
|
||||
myActivity.createBookContextMenu(menu, ((BookTree)tree).Book);
|
||||
} else if (tree instanceof FileTree) {
|
||||
final Book book = ((FileTree)getItem(position)).getBook();
|
||||
if (book != null) {
|
||||
myActivity.createBookContextMenu(menu, book);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue