mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
BookCollectionShadow: a wrapper for LibraryInterface
This commit is contained in:
parent
7480dffedb
commit
ea45b239a1
4 changed files with 94 additions and 25 deletions
|
@ -36,16 +36,15 @@ import org.geometerplus.zlibrary.ui.android.R;
|
|||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.libraryService.LibraryInterface;
|
||||
import org.geometerplus.android.fbreader.libraryService.LibraryService;
|
||||
import org.geometerplus.android.fbreader.libraryService.*;
|
||||
import org.geometerplus.android.util.UIUtil;
|
||||
|
||||
public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuItemClickListener, ServiceConnection {
|
||||
public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
|
||||
private static final int OPEN_ITEM_ID = 0;
|
||||
private static final int EDIT_ITEM_ID = 1;
|
||||
private static final int DELETE_ITEM_ID = 2;
|
||||
|
||||
LibraryInterface myLibraryInterface;
|
||||
private final BookCollectionShadow myCollection = new BookCollectionShadow(this);
|
||||
|
||||
List<Bookmark> AllBooksBookmarks;
|
||||
private final List<Bookmark> myThisBookBookmarks = new LinkedList<Bookmark>();
|
||||
|
@ -72,7 +71,7 @@ public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuIte
|
|||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
|
||||
|
||||
bindService(new Intent(this, LibraryService.class), this, LibraryService.BIND_AUTO_CREATE);
|
||||
myCollection.bindToService();
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
@ -236,13 +235,7 @@ public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuIte
|
|||
final FBReaderApp fbreader = (FBReaderApp)FBReaderApp.Instance();
|
||||
final long bookId = bookmark.getBookId();
|
||||
if (fbreader.Model == null || fbreader.Model.Book.getId() != bookId) {
|
||||
Book book = null;
|
||||
if (myLibraryInterface != null) {
|
||||
try {
|
||||
book = BookSerializerUtil.deserialize(myLibraryInterface.bookById(bookId));
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
final Book book = myCollection.getBookById(bookId);
|
||||
if (book != null) {
|
||||
finish();
|
||||
fbreader.openBook(book, bookmark, null);
|
||||
|
@ -255,18 +248,6 @@ public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuIte
|
|||
}
|
||||
}
|
||||
|
||||
// method from ServiceConnection interface
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
myLibraryInterface = LibraryInterface.Stub.asInterface(service);
|
||||
System.err.println("onServiceConnected " + name + " : " + myLibraryInterface);
|
||||
}
|
||||
|
||||
// method from ServiceConnection interface
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
myLibraryInterface = null;
|
||||
System.err.println("onServiceDisconnected " + name);
|
||||
}
|
||||
|
||||
private final class BookmarksAdapter extends BaseAdapter implements AdapterView.OnItemClickListener, View.OnCreateContextMenuListener {
|
||||
private final List<Bookmark> myBookmarks;
|
||||
private final boolean myCurrentBook;
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2013 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.android.fbreader.libraryService;
|
||||
|
||||
import android.content.*;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
public class BookCollectionShadow implements IBookCollection, ServiceConnection {
|
||||
private final Context myContext;
|
||||
private volatile LibraryInterface myInterface;
|
||||
|
||||
public BookCollectionShadow(Context context) {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public void bindToService() {
|
||||
myContext.bindService(
|
||||
new Intent(myContext, LibraryService.class),
|
||||
this,
|
||||
LibraryService.BIND_AUTO_CREATE
|
||||
);
|
||||
}
|
||||
|
||||
public synchronized Book getBookById(long id) {
|
||||
if (myInterface == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return BookSerializerUtil.deserialize(myInterface.bookById(id));
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// method from ServiceConnection interface
|
||||
public synchronized void onServiceConnected(ComponentName name, IBinder service) {
|
||||
myInterface = LibraryInterface.Stub.asInterface(service);
|
||||
}
|
||||
|
||||
// method from ServiceConnection interface
|
||||
public synchronized void onServiceDisconnected(ComponentName name) {
|
||||
myInterface = null;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
|
|||
import org.geometerplus.fbreader.Paths;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
|
||||
public class BookCollection {
|
||||
public class BookCollection implements IBookCollection {
|
||||
private final List<Listener> myListeners = Collections.synchronizedList(new LinkedList<Listener>());
|
||||
|
||||
public interface Listener {
|
||||
|
|
24
src/org/geometerplus/fbreader/library/IBookCollection.java
Normal file
24
src/org/geometerplus/fbreader/library/IBookCollection.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2013 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
public interface IBookCollection {
|
||||
Book getBookById(long id);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue