mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
new API methods: getBookId, getBookLastTurningTime (no implementation at this moment)
This commit is contained in:
parent
132af46089
commit
9a3ae79474
5 changed files with 68 additions and 7 deletions
|
@ -5,6 +5,7 @@
|
||||||
package org.geometerplus.android.fbreader.api;
|
package org.geometerplus.android.fbreader.api;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public interface Api {
|
public interface Api {
|
||||||
// information about fbreader
|
// information about fbreader
|
||||||
|
@ -21,8 +22,10 @@ public interface Api {
|
||||||
String getBookTitle() throws ApiException;
|
String getBookTitle() throws ApiException;
|
||||||
//List<String> getBookAuthors() throws ApiException;
|
//List<String> getBookAuthors() throws ApiException;
|
||||||
List<String> getBookTags() throws ApiException;
|
List<String> getBookTags() throws ApiException;
|
||||||
String getBookFileName() throws ApiException;
|
String getBookFilePath() throws ApiException;
|
||||||
String getBookHash() throws ApiException;
|
String getBookHash() throws ApiException;
|
||||||
|
String getBookId() throws ApiException;
|
||||||
|
Date getBookLastTurningTime() throws ApiException;
|
||||||
|
|
||||||
// text information
|
// text information
|
||||||
int getParagraphsNumber() throws ApiException;
|
int getParagraphsNumber() throws ApiException;
|
||||||
|
|
|
@ -127,6 +127,14 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
||||||
return ((ApiObject.String)object).Value;
|
return ((ApiObject.String)object).Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Date requestDate(int method, ApiObject[] params) throws ApiException {
|
||||||
|
final ApiObject object = request(method, params);
|
||||||
|
if (!(object instanceof ApiObject.Date)) {
|
||||||
|
throw new ApiException("Cannot cast return type of method " + method + " to Date");
|
||||||
|
}
|
||||||
|
return ((ApiObject.Date)object).Value;
|
||||||
|
}
|
||||||
|
|
||||||
private int requestInt(int method, ApiObject[] params) throws ApiException {
|
private int requestInt(int method, ApiObject[] params) throws ApiException {
|
||||||
final ApiObject object = request(method, params);
|
final ApiObject object = request(method, params);
|
||||||
if (!(object instanceof ApiObject.Integer)) {
|
if (!(object instanceof ApiObject.Integer)) {
|
||||||
|
@ -213,14 +221,22 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
||||||
return requestStringList(GET_BOOK_TAGS, EMPTY_PARAMETERS);
|
return requestStringList(GET_BOOK_TAGS, EMPTY_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBookFileName() throws ApiException {
|
public String getBookFilePath() throws ApiException {
|
||||||
return requestString(GET_BOOK_FILE_NAME, EMPTY_PARAMETERS);
|
return requestString(GET_BOOK_FILE_PATH, EMPTY_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBookHash() throws ApiException {
|
public String getBookHash() throws ApiException {
|
||||||
return requestString(GET_BOOK_HASH, EMPTY_PARAMETERS);
|
return requestString(GET_BOOK_HASH, EMPTY_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBookId() throws ApiException {
|
||||||
|
return requestString(GET_BOOK_ID, EMPTY_PARAMETERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getBookLastTurningTime() throws ApiException {
|
||||||
|
return requestDate(GET_BOOK_LAST_TURNING_TIME, EMPTY_PARAMETERS);
|
||||||
|
}
|
||||||
|
|
||||||
public TextPosition getPageStart() throws ApiException {
|
public TextPosition getPageStart() throws ApiException {
|
||||||
return requestTextPosition(GET_PAGE_START, EMPTY_PARAMETERS);
|
return requestTextPosition(GET_PAGE_START, EMPTY_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@ interface ApiMethods {
|
||||||
int GET_BOOK_TITLE = 502;
|
int GET_BOOK_TITLE = 502;
|
||||||
int GET_BOOK_AUTHORS = 503;
|
int GET_BOOK_AUTHORS = 503;
|
||||||
int GET_BOOK_TAGS = 504;
|
int GET_BOOK_TAGS = 504;
|
||||||
int GET_BOOK_FILE_NAME = 505;
|
int GET_BOOK_FILE_PATH = 505;
|
||||||
int GET_BOOK_HASH = 506;
|
int GET_BOOK_HASH = 506;
|
||||||
|
int GET_BOOK_ID = 507;
|
||||||
|
int GET_BOOK_LAST_TURNING_TIME = 508;
|
||||||
|
|
||||||
// text information
|
// text information
|
||||||
int GET_PARAGRAPHS_NUMBER = 601;
|
int GET_PARAGRAPHS_NUMBER = 601;
|
||||||
|
|
|
@ -17,6 +17,7 @@ public abstract class ApiObject implements Parcelable {
|
||||||
int INT = 1;
|
int INT = 1;
|
||||||
int STRING = 2;
|
int STRING = 2;
|
||||||
int BOOLEAN = 3;
|
int BOOLEAN = 3;
|
||||||
|
int DATE = 4;
|
||||||
int TEXT_POSITION = 10;
|
int TEXT_POSITION = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +71,25 @@ public abstract class ApiObject implements Parcelable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class Date extends ApiObject {
|
||||||
|
final java.util.Date Value;
|
||||||
|
|
||||||
|
Date(java.util.Date value) {
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int type() {
|
||||||
|
return Type.DATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
|
super.writeToParcel(parcel, flags);
|
||||||
|
parcel.writeLong(Value.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class String extends ApiObject {
|
static class String extends ApiObject {
|
||||||
final java.lang.String Value;
|
final java.lang.String Value;
|
||||||
|
|
||||||
|
@ -120,6 +140,10 @@ public abstract class ApiObject implements Parcelable {
|
||||||
return new String(value);
|
return new String(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ApiObject envelope(java.util.Date value) {
|
||||||
|
return new Date(value);
|
||||||
|
}
|
||||||
|
|
||||||
static List<ApiObject> envelope(List<java.lang.String> values) {
|
static List<ApiObject> envelope(List<java.lang.String> values) {
|
||||||
final ArrayList<ApiObject> objects = new ArrayList<ApiObject>(values.size());
|
final ArrayList<ApiObject> objects = new ArrayList<ApiObject>(values.size());
|
||||||
for (java.lang.String v : values) {
|
for (java.lang.String v : values) {
|
||||||
|
@ -153,6 +177,8 @@ public abstract class ApiObject implements Parcelable {
|
||||||
return new Integer(parcel.readInt());
|
return new Integer(parcel.readInt());
|
||||||
case Type.BOOLEAN:
|
case Type.BOOLEAN:
|
||||||
return new Boolean(parcel.readByte() == 1);
|
return new Boolean(parcel.readByte() == 1);
|
||||||
|
case Type.DATE:
|
||||||
|
return new Date(new java.util.Date(parcel.readLong()));
|
||||||
case Type.STRING:
|
case Type.STRING:
|
||||||
return new String(parcel.readString());
|
return new String(parcel.readString());
|
||||||
case Type.TEXT_POSITION:
|
case Type.TEXT_POSITION:
|
||||||
|
|
|
@ -70,10 +70,14 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
||||||
return ApiObject.envelope(getBookLanguage());
|
return ApiObject.envelope(getBookLanguage());
|
||||||
case GET_BOOK_TITLE:
|
case GET_BOOK_TITLE:
|
||||||
return ApiObject.envelope(getBookTitle());
|
return ApiObject.envelope(getBookTitle());
|
||||||
case GET_BOOK_FILE_NAME:
|
case GET_BOOK_FILE_PATH:
|
||||||
return ApiObject.envelope(getBookFileName());
|
return ApiObject.envelope(getBookFilePath());
|
||||||
case GET_BOOK_HASH:
|
case GET_BOOK_HASH:
|
||||||
return ApiObject.envelope(getBookHash());
|
return ApiObject.envelope(getBookHash());
|
||||||
|
case GET_BOOK_ID:
|
||||||
|
return ApiObject.envelope(getBookId());
|
||||||
|
case GET_BOOK_LAST_TURNING_TIME:
|
||||||
|
return ApiObject.envelope(getBookLastTurningTime());
|
||||||
case GET_PARAGRAPHS_NUMBER:
|
case GET_PARAGRAPHS_NUMBER:
|
||||||
return ApiObject.envelope(getParagraphsNumber());
|
return ApiObject.envelope(getParagraphsNumber());
|
||||||
case GET_ELEMENTS_NUMBER:
|
case GET_ELEMENTS_NUMBER:
|
||||||
|
@ -180,7 +184,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBookFileName() {
|
public String getBookFilePath() {
|
||||||
return myReader.Model.Book.File.getPath();
|
return myReader.Model.Book.File.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +192,16 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
||||||
return myReader.Model.Book.getContentHashCode();
|
return myReader.Model.Book.getContentHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBookId() {
|
||||||
|
// TODO: implement
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getBookLastTurningTime() {
|
||||||
|
// TODO: implement
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// page information
|
// page information
|
||||||
public TextPosition getPageStart() {
|
public TextPosition getPageStart() {
|
||||||
return getTextPosition(myReader.getTextView().getStartCursor());
|
return getTextPosition(myReader.getTextView().getStartCursor());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue