1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

preference getters

This commit is contained in:
Nikolay Pultsin 2011-06-23 19:52:15 +01:00
parent 47fc0d3be1
commit bb287d4b85
4 changed files with 49 additions and 6 deletions

View file

@ -4,6 +4,9 @@
package org.geometerplus.android.fbreader.api;
import java.util.List;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
@ -117,6 +120,14 @@ public abstract class ApiObject implements Parcelable {
return new String(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) {
objects.add(new String(v));
}
return objects;
}
abstract protected int type();
public int describeContents() {

View file

@ -22,6 +22,7 @@ package org.geometerplus.android.fbreader.api;
import java.util.*;
import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.core.config.ZLConfig;
import org.geometerplus.zlibrary.text.view.*;
@ -104,8 +105,13 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
try {
switch (method) {
case GET_OPTION_GROUPS:
return ApiObject.envelope(getOptionGroups());
case GET_OPTION_NAMES:
return ApiObject.envelope(getOptionNames(
((ApiObject.String)parameters[0]).Value
));
case GET_BOOK_TAGS:
return ApiObject.envelope(getBookTags());
default:
return Collections.<ApiObject>singletonList(unsupportedMethodError(method));
}
@ -137,18 +143,15 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
// preferences information
public List<String> getOptionGroups() {
// TODO: implement
return Collections.emptyList();
return ZLConfig.Instance().listGroups();
}
public List<String> getOptionNames(String group) {
// TODO: implement
return Collections.emptyList();
return ZLConfig.Instance().listNames(group);
}
public String getOptionValue(String group, String name) {
// TODO: implement
return null;
return ZLConfig.Instance().getValue(group, name, null);
}
public void setOptionValue(String group, String name, String value) {

View file

@ -19,6 +19,8 @@
package org.geometerplus.zlibrary.core.config;
import java.util.List;
public abstract class ZLConfig {
public static ZLConfig Instance() {
return ourInstance;
@ -30,6 +32,9 @@ public abstract class ZLConfig {
ourInstance = this;
}
public abstract List<String> listGroups();
public abstract List<String> listNames(String group);
public abstract String getValue(String group, String name, String defaultValue);
public abstract void setValue(String group, String name, String value);
public abstract void unsetValue(String group, String name);

View file

@ -19,7 +19,11 @@
package org.geometerplus.zlibrary.core.sqliteconfig;
import java.util.List;
import java.util.LinkedList;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
@ -78,6 +82,26 @@ public final class ZLSQLiteConfig extends ZLConfig {
*/
}
synchronized public List<String> listGroups() {
final LinkedList<String> list = new LinkedList<String>();
final Cursor cursor = myDatabase.rawQuery("SELECT DISTINCT groupName FROM config", null);
while (cursor.moveToNext()) {
list.add(cursor.getString(0));
}
cursor.close();
return list;
}
synchronized public List<String> listNames(String group) {
final LinkedList<String> list = new LinkedList<String>();
final Cursor cursor = myDatabase.rawQuery("SELECT name FROM config WHERE groupName = ?", new String[] { group });
while (cursor.moveToNext()) {
list.add(cursor.getString(0));
}
cursor.close();
return list;
}
synchronized public void removeGroup(String name) {
myDeleteGroupStatement.bindString(1, name);
try {