mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
synchronization with library-service branch
This commit is contained in:
parent
e4912a2beb
commit
d08131d68b
7 changed files with 97 additions and 31 deletions
|
@ -49,7 +49,7 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
final String type = intent.getStringExtra("type");
|
||||
if (LibraryService.BOOK_EVENT_ACTION.equals(intent.getAction())) {
|
||||
final Book book = SerializerUtil.deserializeBook(intent.getStringExtra("book"));
|
||||
fireBookEvent(Listener.BookEvent.valueOf(type), book);
|
||||
fireBookEvent(BookEvent.valueOf(type), book);
|
||||
} else {
|
||||
fireBuildEvent(Listener.BuildEvent.valueOf(type));
|
||||
}
|
||||
|
@ -121,6 +121,19 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized List<Book> books(Author author) {
|
||||
if (myInterface == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
try {
|
||||
return SerializerUtil.deserializeBookList(
|
||||
myInterface.booksForAuthor(Util.authorToString(author))
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<Book> books(String pattern) {
|
||||
if (myInterface == null) {
|
||||
return Collections.emptyList();
|
||||
|
@ -195,10 +208,7 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
final List<String> strings = myInterface.authors();
|
||||
final List<Author> authors = new ArrayList<Author>(strings.size());
|
||||
for (String s : strings) {
|
||||
final String[] splited = s.split("\000");
|
||||
if (splited.length == 2) {
|
||||
authors.add(new Author(splited[0], splited[1]));
|
||||
}
|
||||
authors.add(Util.stringToAuthor(s));
|
||||
}
|
||||
return authors;
|
||||
} catch (RemoteException e) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.geometerplus.android.fbreader.api.TextPosition;
|
|||
interface LibraryInterface {
|
||||
int size();
|
||||
List<String> books();
|
||||
List<String> booksForAuthor(in String author);
|
||||
List<String> booksForPattern(in String pattern);
|
||||
List<String> recentBooks();
|
||||
List<String> favorites();
|
||||
|
|
|
@ -119,6 +119,10 @@ public class LibraryService extends Service {
|
|||
return SerializerUtil.serializeBookList(myCollection.books());
|
||||
}
|
||||
|
||||
public List<String> booksForAuthor(String author) {
|
||||
return SerializerUtil.serializeBookList(myCollection.books(Util.stringToAuthor(author)));
|
||||
}
|
||||
|
||||
public List<String> booksForPattern(String pattern) {
|
||||
return SerializerUtil.serializeBookList(myCollection.books(pattern));
|
||||
}
|
||||
|
@ -147,12 +151,7 @@ public class LibraryService extends Service {
|
|||
final List<Author> authors = myCollection.authors();
|
||||
final List<String> strings = new ArrayList<String>(authors.size());
|
||||
for (Author a : authors) {
|
||||
strings.add(
|
||||
new StringBuilder(a.DisplayName)
|
||||
.append('\000')
|
||||
.append(a.SortKey)
|
||||
.toString()
|
||||
);
|
||||
strings.add(Util.authorToString(a));
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 org.geometerplus.fbreader.book.Author;
|
||||
|
||||
abstract class Util {
|
||||
static String authorToString(Author author) {
|
||||
return new StringBuilder(author.DisplayName).append('\000').append(author.SortKey).toString();
|
||||
}
|
||||
|
||||
static Author stringToAuthor(String string) {
|
||||
final String[] splitted = string.split("\000");
|
||||
if (splitted.length == 2) {
|
||||
return new Author(splitted[0], splitted[1]);
|
||||
} else {
|
||||
return Author.NULL;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue