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

new classes for library service

This commit is contained in:
Nikolay Pultsin 2012-01-26 21:06:56 +00:00
parent 9a6f8b2acc
commit 59b635c68c
3 changed files with 122 additions and 2 deletions

View file

@ -0,0 +1,9 @@
/*
* This code is in the public domain.
*/
package org.geometerplus.android.fbreader.libraryService;
interface LibraryInterface {
boolean isUpToDate();
}

View file

@ -23,7 +23,21 @@ import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class LibraryService extends Service {
import org.geometerplus.fbreader.library.*;
import org.geometerplus.android.fbreader.library.SQLiteBooksDatabase;
public class LibraryService extends Service implements Library.ChangeListener {
public final class LibraryImplementation extends LibraryInterface.Stub {
public boolean isUpToDate() {
return myLibrary.isUpToDate();
}
}
private LibraryImplementation myImplementation;
private BooksDatabase myDatabase;
private AbstractLibrary myLibrary;
@Override
public void onStart(Intent intent, int startId) {
onStartCommand(intent, 0, startId);
@ -32,12 +46,42 @@ public class LibraryService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
System.err.println("LibraryService started for intent " + intent);
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
System.err.println("LibraryService binded for intent " + intent);
return null;
return myImplementation;
}
@Override
public void onCreate() {
System.err.println("LibraryService.onCreate()");
super.onCreate();
myDatabase = SQLiteBooksDatabase.Instance();
if (myDatabase == null) {
myDatabase = new SQLiteBooksDatabase(this, "LIBRARY SERVICE");
}
if (myLibrary == null) {
myLibrary = Library.Instance();
myLibrary.addChangeListener(this);
((Library)myLibrary).startBuild();
}
myImplementation = new LibraryImplementation();
}
@Override
public void onDestroy() {
System.err.println("LibraryService.onDestroy()");
myLibrary.removeChangeListener(this);
myLibrary = null;
super.onDestroy();
}
public void onLibraryChanged(final Code code) {
// TODO: implement signal sending
System.err.println("LibraryService.onLibraryChanged(" + code + "): " + myLibrary.isUpToDate());
}
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (C) 2010-2012 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 org.geometerplus.fbreader.library.*;
public class LibraryShadow extends AbstractLibrary {
private final LibraryInterface myInterface;
public LibraryShadow(LibraryInterface iface) {
myInterface = iface;
}
@Override
public boolean isUpToDate() {
return myInterface.isUpToDate();
}
@Override
public boolean canRemoveBookFile(Book book) {
// TODO: implement
return false;
}
@Override
public void removeBook(Book book, int removeMode) {
// TODO: implement
}
@Override
public boolean isBookInFavorites(Book book) {
// TODO: implement
return false;
}
@Override
public void addBookToFavorites(Book book) {
// TODO: implement
}
@Override
public void removeBookFromFavorites(Book book) {
// TODO: implement
}
@Override
public void startBookSearch(final String pattern) {
// TODO: implement
}
}