From b0ef1d911e678b42d93b7760f7b6f0a0c019fb90 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Wed, 24 Jun 2015 13:58:48 +0100 Subject: [PATCH] code cleanup (fit coding standards + small fixes) --- .../android/fbreader/api/Api.java | 3 ++- .../fbreader/api/ApiClientImplementation.java | 4 ++-- .../android/fbreader/api/ApiObject.java | 1 + .../fbreader/api/ApiServerImplementation.java | 19 ++++++++----------- .../fbreader/book/AbstractBook.java | 4 ---- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/org/geometerplus/android/fbreader/api/Api.java b/src/org/geometerplus/android/fbreader/api/Api.java index c1924e947..bcdccd611 100644 --- a/src/org/geometerplus/android/fbreader/api/Api.java +++ b/src/org/geometerplus/android/fbreader/api/Api.java @@ -22,7 +22,7 @@ public interface Api { // book information for current book String getBookLanguage() throws ApiException; String getBookTitle() throws ApiException; - //List getBookAuthors() throws ApiException; + List getBookAuthors() throws ApiException; List getBookTags() throws ApiException; String getBookFilePath() throws ApiException; String getBookHash() throws ApiException; @@ -38,6 +38,7 @@ public interface Api { String getBookHash(long id) throws ApiException; String getBookUniqueId(long id) throws ApiException; Date getBookLastTurningTime(long id) throws ApiException; + float getBookProgress() throws ApiException; //long findBookIdByUniqueId(String uniqueId) throws ApiException; //long findBookIdByFilePath(String uniqueId) throws ApiException; diff --git a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java index ae25b9b4b..02c63f5b0 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiClientImplementation.java @@ -147,12 +147,12 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho } return ((ApiObject.Integer)object).Value; } - + private float requestFloat(int method, ApiObject[] params) throws ApiException { final ApiObject object = request(method, params); if (!(object instanceof ApiObject.Float)) { throw new ApiException("Cannot cast return type of method " + method + " to float"); - } + } return ((ApiObject.Float)object).Value; } diff --git a/src/org/geometerplus/android/fbreader/api/ApiObject.java b/src/org/geometerplus/android/fbreader/api/ApiObject.java index f36ac427f..0fd1cea1d 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiObject.java +++ b/src/org/geometerplus/android/fbreader/api/ApiObject.java @@ -219,6 +219,7 @@ public abstract class ApiObject implements Parcelable { static ApiObject envelope(float value) { return new Float(value); } + static ApiObject envelope(boolean value) { return new Boolean(value); } diff --git a/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java b/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java index bc8a87571..57709f6d6 100644 --- a/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java +++ b/src/org/geometerplus/android/fbreader/api/ApiServerImplementation.java @@ -352,24 +352,21 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A if (book == null) { return -1.0f; } - RationalNumber progress=book.getProgress(); - return progress.toFloat(); + final RationalNumber progress = book.getProgress(); + return progress != null ? progress.toFloat() : -1.0f; } public List getBookAuthors() { - final Book book=getReader().getCurrentBook(); + final Book book = getReader().getCurrentBook(); if (book == null) { return null; } - List authors=book.getAuthors(); - if (authors == null) { - return Collections.emptyList(); + final List authors = book.authors(); + final List authorNames = new ArrayList(authors.size()); + for (Author a : authors) { + authorNames.add(a.DisplayName); } - List result=new LinkedList(); - for (Author author:authors) { - result.add(author.DisplayName); - } - return result; + return authorNames; } public String getBookFilePath() { diff --git a/src/org/geometerplus/fbreader/book/AbstractBook.java b/src/org/geometerplus/fbreader/book/AbstractBook.java index ae16d3aed..59993cf28 100644 --- a/src/org/geometerplus/fbreader/book/AbstractBook.java +++ b/src/org/geometerplus/fbreader/book/AbstractBook.java @@ -60,10 +60,6 @@ public abstract class AbstractBook extends TitledEntity { public abstract String getPath(); - public List getAuthors() { - return myAuthors!=null ? myAuthors: null; - } - public void updateFrom(AbstractBook book) { if (book == null || myId != book.myId) { return;