mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
preference getters
This commit is contained in:
parent
47fc0d3be1
commit
bb287d4b85
4 changed files with 49 additions and 6 deletions
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader.api;
|
package org.geometerplus.android.fbreader.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
@ -117,6 +120,14 @@ public abstract class ApiObject implements Parcelable {
|
||||||
return new String(value);
|
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();
|
abstract protected int type();
|
||||||
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.android.fbreader.api;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||||
|
import org.geometerplus.zlibrary.core.config.ZLConfig;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
|
@ -104,8 +105,13 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
||||||
try {
|
try {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case GET_OPTION_GROUPS:
|
case GET_OPTION_GROUPS:
|
||||||
|
return ApiObject.envelope(getOptionGroups());
|
||||||
case GET_OPTION_NAMES:
|
case GET_OPTION_NAMES:
|
||||||
|
return ApiObject.envelope(getOptionNames(
|
||||||
|
((ApiObject.String)parameters[0]).Value
|
||||||
|
));
|
||||||
case GET_BOOK_TAGS:
|
case GET_BOOK_TAGS:
|
||||||
|
return ApiObject.envelope(getBookTags());
|
||||||
default:
|
default:
|
||||||
return Collections.<ApiObject>singletonList(unsupportedMethodError(method));
|
return Collections.<ApiObject>singletonList(unsupportedMethodError(method));
|
||||||
}
|
}
|
||||||
|
@ -137,18 +143,15 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
||||||
|
|
||||||
// preferences information
|
// preferences information
|
||||||
public List<String> getOptionGroups() {
|
public List<String> getOptionGroups() {
|
||||||
// TODO: implement
|
return ZLConfig.Instance().listGroups();
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getOptionNames(String group) {
|
public List<String> getOptionNames(String group) {
|
||||||
// TODO: implement
|
return ZLConfig.Instance().listNames(group);
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOptionValue(String group, String name) {
|
public String getOptionValue(String group, String name) {
|
||||||
// TODO: implement
|
return ZLConfig.Instance().getValue(group, name, null);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOptionValue(String group, String name, String value) {
|
public void setOptionValue(String group, String name, String value) {
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.core.config;
|
package org.geometerplus.zlibrary.core.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ZLConfig {
|
public abstract class ZLConfig {
|
||||||
public static ZLConfig Instance() {
|
public static ZLConfig Instance() {
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
|
@ -30,6 +32,9 @@ public abstract class ZLConfig {
|
||||||
ourInstance = this;
|
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 String getValue(String group, String name, String defaultValue);
|
||||||
public abstract void setValue(String group, String name, String value);
|
public abstract void setValue(String group, String name, String value);
|
||||||
public abstract void unsetValue(String group, String name);
|
public abstract void unsetValue(String group, String name);
|
||||||
|
|
|
@ -19,7 +19,11 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.core.sqliteconfig;
|
package org.geometerplus.zlibrary.core.sqliteconfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.database.SQLException;
|
import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteStatement;
|
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) {
|
synchronized public void removeGroup(String name) {
|
||||||
myDeleteGroupStatement.bindString(1, name);
|
myDeleteGroupStatement.bindString(1, name);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue