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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
public interface Api {
|
||||
// information about fbreader
|
||||
|
@ -21,8 +22,10 @@ public interface Api {
|
|||
String getBookTitle() throws ApiException;
|
||||
//List<String> getBookAuthors() throws ApiException;
|
||||
List<String> getBookTags() throws ApiException;
|
||||
String getBookFileName() throws ApiException;
|
||||
String getBookFilePath() throws ApiException;
|
||||
String getBookHash() throws ApiException;
|
||||
String getBookId() throws ApiException;
|
||||
Date getBookLastTurningTime() throws ApiException;
|
||||
|
||||
// text information
|
||||
int getParagraphsNumber() throws ApiException;
|
||||
|
|
|
@ -127,6 +127,14 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
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 {
|
||||
final ApiObject object = request(method, params);
|
||||
if (!(object instanceof ApiObject.Integer)) {
|
||||
|
@ -213,14 +221,22 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
return requestStringList(GET_BOOK_TAGS, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public String getBookFileName() throws ApiException {
|
||||
return requestString(GET_BOOK_FILE_NAME, EMPTY_PARAMETERS);
|
||||
public String getBookFilePath() throws ApiException {
|
||||
return requestString(GET_BOOK_FILE_PATH, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
||||
public String getBookHash() throws ApiException {
|
||||
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 {
|
||||
return requestTextPosition(GET_PAGE_START, EMPTY_PARAMETERS);
|
||||
}
|
||||
|
|
|
@ -25,8 +25,10 @@ interface ApiMethods {
|
|||
int GET_BOOK_TITLE = 502;
|
||||
int GET_BOOK_AUTHORS = 503;
|
||||
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_ID = 507;
|
||||
int GET_BOOK_LAST_TURNING_TIME = 508;
|
||||
|
||||
// text information
|
||||
int GET_PARAGRAPHS_NUMBER = 601;
|
||||
|
|
|
@ -17,6 +17,7 @@ public abstract class ApiObject implements Parcelable {
|
|||
int INT = 1;
|
||||
int STRING = 2;
|
||||
int BOOLEAN = 3;
|
||||
int DATE = 4;
|
||||
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 {
|
||||
final java.lang.String Value;
|
||||
|
||||
|
@ -120,6 +140,10 @@ public abstract class ApiObject implements Parcelable {
|
|||
return new String(value);
|
||||
}
|
||||
|
||||
static ApiObject envelope(java.util.Date value) {
|
||||
return new Date(value);
|
||||
}
|
||||
|
||||
static List<ApiObject> envelope(List<java.lang.String> values) {
|
||||
final ArrayList<ApiObject> objects = new ArrayList<ApiObject>(values.size());
|
||||
for (java.lang.String v : values) {
|
||||
|
@ -153,6 +177,8 @@ public abstract class ApiObject implements Parcelable {
|
|||
return new Integer(parcel.readInt());
|
||||
case Type.BOOLEAN:
|
||||
return new Boolean(parcel.readByte() == 1);
|
||||
case Type.DATE:
|
||||
return new Date(new java.util.Date(parcel.readLong()));
|
||||
case Type.STRING:
|
||||
return new String(parcel.readString());
|
||||
case Type.TEXT_POSITION:
|
||||
|
|
|
@ -70,10 +70,14 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
return ApiObject.envelope(getBookLanguage());
|
||||
case GET_BOOK_TITLE:
|
||||
return ApiObject.envelope(getBookTitle());
|
||||
case GET_BOOK_FILE_NAME:
|
||||
return ApiObject.envelope(getBookFileName());
|
||||
case GET_BOOK_FILE_PATH:
|
||||
return ApiObject.envelope(getBookFilePath());
|
||||
case GET_BOOK_HASH:
|
||||
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:
|
||||
return ApiObject.envelope(getParagraphsNumber());
|
||||
case GET_ELEMENTS_NUMBER:
|
||||
|
@ -180,7 +184,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public String getBookFileName() {
|
||||
public String getBookFilePath() {
|
||||
return myReader.Model.Book.File.getPath();
|
||||
}
|
||||
|
||||
|
@ -188,6 +192,16 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
return myReader.Model.Book.getContentHashCode();
|
||||
}
|
||||
|
||||
public String getBookId() {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
public Date getBookLastTurningTime() {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
// page information
|
||||
public TextPosition getPageStart() {
|
||||
return getTextPosition(myReader.getTextView().getStartCursor());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue