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

preferences code cleanup

This commit is contained in:
Nikolay Pultsin 2014-07-28 00:28:54 +01:00
parent 76bc6da867
commit 15febb11af
17 changed files with 89 additions and 90 deletions

View file

@ -325,23 +325,15 @@
<node name="summaryOn" value="Synchronise my library with FBReader book network server"/>
<node name="summaryOff" value="Do not synchronise my library with FBReader book network server"/>
</node>
<node name="uploadAllBooks" value="Upload all books to server">
<node name="values">
<node name="always" value="Always"/>
<node name="viaWifi" value="If device is connected via Wi-Fi"/>
<node name="never" value="Never"/>
</node>
<node name="positions" value="Reading positions">
<node name="summaryOn" value="Automatically synchronise reading positions"/>
<node name="summaryOff" value="Do not synchronise reading positions"/>
</node>
<node name="bookmarks" value="Bookamrks">
<node name="summaryOn" value="Automatically synchronise bookmarks"/>
<node name="summaryOff" value="Do not synchronise bookmarks"/>
</node>
<node name="metainfo" value="Metainfo (title, tags, etc.)">
<node name="summaryOn" value="Automatically synchronise book metainfo"/>
<node name="summaryOff" value="Do not synchronise book metainfo"/>
</node>
<node name="uploadAllBooks" value="Upload all books to server"/>
<node name="positions" value="Reading positions"/>
<node name="bookmarks" value="Bookmarks"/>
<node name="metainfo" value="Metainfo (title, tags, etc.)"/>
</node>
<node name="directories" value="Directories">
<node name="summary" value="Directories to seek for files"/>

View file

@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
class BatteryLevelToTurnScreenOffPreference extends ZLStringListPreference {
private final ZLIntegerRangeOption myOption;
BatteryLevelToTurnScreenOffPreference(Context context, ZLIntegerRangeOption option, ZLResource rootResource, String resourceKey) {
super(context, rootResource, resourceKey);
BatteryLevelToTurnScreenOffPreference(Context context, ZLIntegerRangeOption option, ZLResource resource) {
super(context, resource);
myOption = option;
String[] entries = { "0", "25", "50", "100" };
setList(entries);

View file

@ -31,8 +31,8 @@ import org.geometerplus.android.fbreader.DictionaryUtil;
class DictionaryPreference extends ZLStringListPreference {
private final ZLStringOption myOption;
DictionaryPreference(Context context, ZLResource resource, String resourceKey, ZLStringOption dictionaryOption, List<DictionaryUtil.PackageInfo> infos) {
super(context, resource, resourceKey);
DictionaryPreference(Context context, ZLResource resource, ZLStringOption dictionaryOption, List<DictionaryUtil.PackageInfo> infos) {
super(context, resource);
myOption = dictionaryOption;

View file

@ -68,8 +68,8 @@ class BookLanguagePreference extends LanguagePreference {
return new ArrayList<Language>(set);
}
BookLanguagePreference(Context context, ZLResource rootResource, String resourceKey, Book book) {
super(context, rootResource, resourceKey, languages());
BookLanguagePreference(Context context, ZLResource resource, Book book) {
super(context, resource, languages());
myBook = book;
final String language = myBook.getLanguage();
if (language == null || !setInitialValue(language)) {
@ -91,8 +91,8 @@ class BookLanguagePreference extends LanguagePreference {
class EncodingPreference extends ZLStringListPreference {
private final Book myBook;
EncodingPreference(Context context, ZLResource rootResource, String resourceKey, Book book) {
super(context, rootResource, resourceKey);
EncodingPreference(Context context, ZLResource resource, Book book) {
super(context, resource);
myBook = book;
final FormatPlugin plugin;
@ -278,8 +278,8 @@ public class EditBookInfoActivity extends ZLPreferenceActivity {
addPreference(new BookTitlePreference(EditBookInfoActivity.this, Resource, "title", myBook));
myEditAuthorsPreference = (EditAuthorsPreference)addPreference(new EditAuthorsPreference(EditBookInfoActivity.this, Resource, "authors", myBook));
myEditTagsPreference = (EditTagsPreference)addPreference(new EditTagsPreference(EditBookInfoActivity.this, Resource, "tags", myBook));
addPreference(new BookLanguagePreference(EditBookInfoActivity.this, Resource, "language", myBook));
addPreference(new EncodingPreference(EditBookInfoActivity.this, Resource, "encoding", myBook));
addPreference(new BookLanguagePreference(EditBookInfoActivity.this, Resource.getResource("language"), myBook));
addPreference(new EncodingPreference(EditBookInfoActivity.this, Resource.getResource("encoding"), myBook));
}
});
}

View file

@ -34,8 +34,8 @@ class FontPreference extends ZLStringListPreference implements ReloadablePrefere
private static String UNCHANGED = "inherit";
FontPreference(Context context, ZLResource resource, String resourceKey, ZLStringOption option, boolean includeDummyValue) {
super(context, resource, resourceKey);
FontPreference(Context context, ZLResource resource, ZLStringOption option, boolean includeDummyValue) {
super(context, resource);
myOption = option;
myIncludeDummyValue = includeDummyValue;

View file

@ -29,8 +29,8 @@ class FontStylePreference extends ZLStringListPreference {
private final ZLBooleanOption myItalicOption;
private final String[] myValues = { "regular", "bold", "italic", "boldItalic" };
FontStylePreference(Context context, ZLResource resource, String resourceKey, ZLBooleanOption boldOption, ZLBooleanOption italicOption) {
super(context, resource, resourceKey);
FontStylePreference(Context context, ZLResource resource, ZLBooleanOption boldOption, ZLBooleanOption italicOption) {
super(context, resource);
myBoldOption = boldOption;
myItalicOption = italicOption;

View file

@ -28,9 +28,9 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
abstract class LanguagePreference extends ZLStringListPreference {
LanguagePreference(
Context context, ZLResource rootResource, String resourceKey, List<Language> languages
Context context, ZLResource resource, List<Language> languages
) {
super(context, rootResource, resourceKey);
super(context, resource);
final int size = languages.size();
String[] codes = new String[size];

View file

@ -138,15 +138,15 @@ public class PreferenceActivity extends ZLPreferenceActivity {
syncPreferences.run();
}
});
syncPreferences.add(syncScreen.addOption(syncOptions.UploadAllBooks, "uploadAllBooks"));
syncPreferences.add(syncScreen.addOption(syncOptions.Positions, "positions"));
//syncPreferences.add(syncScreen.addOption(syncOptions.Metainfo, "metainfo"));
//syncPreferences.add(syncScreen.addOption(syncOptions.Bookmarks, "bookmarks"));
syncPreferences.add(syncScreen.addOption(syncOptions.UploadAllBooks, "uploadAllBooks", "values"));
syncPreferences.add(syncScreen.addOption(syncOptions.Positions, "positions", "values"));
//syncPreferences.add(syncScreen.addOption(syncOptions.Metainfo, "metainfo", "values"));
//syncPreferences.add(syncScreen.addOption(syncOptions.Bookmarks, "bookmarks", "values"));
syncPreferences.run();
final Screen appearanceScreen = createPreferenceScreen("appearance");
appearanceScreen.addPreference(new LanguagePreference(
this, appearanceScreen.Resource, "language", ZLResource.interfaceLanguages()
this, appearanceScreen.Resource.getResource("language"), ZLResource.interfaceLanguages()
) {
@Override
protected void init() {
@ -166,7 +166,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
}
});
appearanceScreen.addPreference(new ZLStringChoicePreference(
this, appearanceScreen.Resource, "screenOrientation",
this, appearanceScreen.Resource.getResource("screenOrientation"),
androidLibrary.getOrientationOption(), androidLibrary.allOrientations()
));
appearanceScreen.addPreference(new ZLBooleanPreference(
@ -192,8 +192,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
appearanceScreen.addPreference(new BatteryLevelToTurnScreenOffPreference(
this,
androidLibrary.BatteryLevelToTurnScreenOffOption,
appearanceScreen.Resource,
"dontTurnScreenOff"
appearanceScreen.Resource.getResource("dontTurnScreenOff")
));
/*
appearanceScreen.addPreference(new ZLBooleanPreference(
@ -245,19 +244,16 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final ZLTextBaseStyle baseStyle = collection.getBaseStyle();
final FontPreference fontPreference = new FontPreference(
this, textScreen.Resource, "font",
fontReloader.add(textScreen.addPreference(new FontPreference(
this, textScreen.Resource.getResource("font"),
baseStyle.FontFamilyOption, false
);
textScreen.addPreference(fontPreference);
fontReloader.add(fontPreference);
)));
textScreen.addPreference(new ZLIntegerRangePreference(
this, textScreen.Resource.getResource("fontSize"),
baseStyle.FontSizeOption
));
textScreen.addPreference(new FontStylePreference(
this, textScreen.Resource, "fontStyle",
this, textScreen.Resource.getResource("fontStyle"),
baseStyle.BoldOption, baseStyle.ItalicOption
));
final ZLIntegerRangeOption spaceOption = baseStyle.LineSpaceOption;
@ -267,12 +263,12 @@ public class PreferenceActivity extends ZLPreferenceActivity {
spacings[i] = (char)(val / 10 + '0') + decimalSeparator + (char)(val % 10 + '0');
}
textScreen.addPreference(new ZLChoicePreference(
this, textScreen.Resource, "lineSpacing",
this, textScreen.Resource.getResource("lineSpacing"),
spaceOption, spacings
));
final String[] alignments = { "left", "right", "center", "justify" };
textScreen.addPreference(new ZLChoicePreference(
this, textScreen.Resource, "alignment",
this, textScreen.Resource.getResource("alignment"),
baseStyle.AlignmentOption, alignments
));
textScreen.addOption(baseStyle.AutoHyphenationOption, "autoHyphenations");
@ -281,7 +277,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
for (ZLTextNGStyleDescription description : collection.getDescriptionList()) {
final Screen ngScreen = moreStylesScreen.createPreferenceScreen(description.Name);
ngScreen.addPreference(new FontPreference(
this, textScreen.Resource, "font",
this, textScreen.Resource.getResource("font"),
description.FontFamilyOption, true
));
ngScreen.addPreference(new StringPreference(
@ -290,27 +286,27 @@ public class PreferenceActivity extends ZLPreferenceActivity {
textScreen.Resource, "fontSize"
));
ngScreen.addPreference(new ZLStringChoicePreference(
this, textScreen.Resource, "bold",
this, textScreen.Resource.getResource("bold"),
description.FontWeightOption,
new String[] { "inherit", "normal", "bold" }
));
ngScreen.addPreference(new ZLStringChoicePreference(
this, textScreen.Resource, "italic",
this, textScreen.Resource.getResource("italic"),
description.FontStyleOption,
new String[] { "inherit", "normal", "italic" }
));
ngScreen.addPreference(new ZLStringChoicePreference(
this, textScreen.Resource, "textDecoration",
this, textScreen.Resource.getResource("textDecoration"),
description.TextDecorationOption,
new String[] { "inherit", "none", "underline", "line-through" }
));
ngScreen.addPreference(new ZLStringChoicePreference(
this, textScreen.Resource, "allowHyphenations",
this, textScreen.Resource.getResource("allowHyphenations"),
description.HyphenationOption,
new String[] { "inherit", "none", "auto" }
));
ngScreen.addPreference(new ZLStringChoicePreference(
this, textScreen.Resource, "alignment",
this, textScreen.Resource.getResource("alignment"),
description.AlignmentOption,
new String[] { "inherit", "left", "right", "center", "justify" }
));
@ -373,7 +369,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final Screen colorsScreen = createPreferenceScreen("colors");
final WallpaperPreference wallpaperPreference = new WallpaperPreference(
this, profile, colorsScreen.Resource, "background"
this, profile, colorsScreen.Resource.getResource("background")
) {
@Override
protected void onDialogClosed(boolean result) {
@ -422,7 +418,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final String[] scrollBarTypes = {"hide", "show", "showAsProgress", "showAsFooter"};
statusLineScreen.addPreference(new ZLChoicePreference(
this, statusLineScreen.Resource, "scrollbarType",
this, statusLineScreen.Resource.getResource("scrollbarType"),
viewOptions.ScrollbarType, scrollBarTypes
) {
@Override
@ -443,7 +439,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
footerPreferences.add(statusLineScreen.addOption(footerOptions.ShowClock, "showClock"));
footerPreferences.add(statusLineScreen.addOption(footerOptions.ShowBattery, "showBattery"));
footerPreferences.add(statusLineScreen.addPreference(new FontPreference(
this, statusLineScreen.Resource, "font",
this, statusLineScreen.Resource.getResource("font"),
footerOptions.Font, false
)));
footerPreferences.run();
@ -533,7 +529,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
Language.ANY_CODE, dictionaryScreen.Resource.getResource("targetLanguage")
));
final LanguagePreference targetLanguagePreference = new LanguagePreference(
this, dictionaryScreen.Resource, "targetLanguage", languages
this, dictionaryScreen.Resource.getResource("targetLanguage"), languages
) {
@Override
protected void init() {
@ -550,8 +546,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
public void run() {
dictionaryScreen.addPreference(new DictionaryPreference(
PreferenceActivity.this,
dictionaryScreen.Resource,
"dictionary",
dictionaryScreen.Resource.getResource("dictionary"),
DictionaryUtil.singleWordTranslatorOption(),
DictionaryUtil.dictionaryInfos(PreferenceActivity.this, true)
) {
@ -565,8 +560,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
});
dictionaryScreen.addPreference(new DictionaryPreference(
PreferenceActivity.this,
dictionaryScreen.Resource,
"translator",
dictionaryScreen.Resource.getResource("translator"),
DictionaryUtil.multiWordTranslatorOption(),
DictionaryUtil.dictionaryInfos(PreferenceActivity.this, false)
));
@ -599,13 +593,13 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final String[] backKeyActions =
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU };
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
this, cancelMenuScreen.Resource, "backKeyAction",
this, cancelMenuScreen.Resource.getResource("backKeyAction"),
keyBindings.getOption(KeyEvent.KEYCODE_BACK, false), backKeyActions
));
final String[] backKeyLongPressActions =
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU, FBReaderApp.NoAction };
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
this, cancelMenuScreen.Resource, "backKeyLongPressAction",
this, cancelMenuScreen.Resource.getResource("backKeyLongPressAction"),
keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions
));

View file

@ -33,8 +33,8 @@ import org.geometerplus.fbreader.fbreader.options.ColorProfile;
class WallpaperPreference extends ZLStringListPreference implements ReloadablePreference {
private final ZLStringOption myOption;
WallpaperPreference(Context context, ColorProfile profile, ZLResource resource, String resourceKey) {
super(context, resource, resourceKey);
WallpaperPreference(Context context, ColorProfile profile, ZLResource resource) {
super(context, resource);
myOption = profile.WallpaperOption;
reload();
@ -49,12 +49,12 @@ class WallpaperPreference extends ZLStringListPreference implements ReloadablePr
final String[] texts = new String[size];
values[0] = "";
texts[0] = myResource.getResource("solidColor").getValue();
texts[0] = myValuesResource.getResource("solidColor").getValue();
int index = 1;
for (ZLFile f : predefined) {
values[index] = f.getPath();
final String name = f.getShortName();
texts[index] = myResource.getResource(
texts[index] = myValuesResource.getResource(
name.substring(0, name.indexOf("."))
).getValue();
++index;

View file

@ -32,8 +32,8 @@ class ZLBoolean3Preference extends ZLStringListPreference {
private final ZLBoolean3Option myOption;
ZLBoolean3Preference(Context context, ZLResource resource, String resourceKey, ZLBoolean3Option option) {
super(context, resource, resourceKey);
ZLBoolean3Preference(Context context, ZLResource resource, ZLBoolean3Option option) {
super(context, resource);
myOption = option;
setList(new String[] { ON, OFF, UNCHANGED });

View file

@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
class ZLChoicePreference extends ZLStringListPreference {
private final ZLIntegerRangeOption myOption;
ZLChoicePreference(Context context, ZLResource resource, String resourceKey, ZLIntegerRangeOption option, String[] valueResourceKeys) {
super(context, resource, resourceKey);
ZLChoicePreference(Context context, ZLResource resource, ZLIntegerRangeOption option, String[] valueResourceKeys) {
super(context, resource);
assert(option.MaxValue - option.MinValue + 1 == valueResourceKeys.length);

View file

@ -27,8 +27,12 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
class ZLEnumPreference<T extends Enum<T>> extends ZLStringListPreference {
private final ZLEnumOption<T> myOption;
ZLEnumPreference(Context context, ZLEnumOption<T> option, ZLResource resource, String resourceKey) {
super(context, resource, resourceKey);
ZLEnumPreference(Context context, ZLEnumOption<T> option, ZLResource resource) {
this(context, option, resource, resource);
}
ZLEnumPreference(Context context, ZLEnumOption<T> option, ZLResource resource, ZLResource valuesResource) {
super(context, resource, valuesResource);
myOption = option;
final T initialValue = option.getValue();

View file

@ -28,8 +28,8 @@ class ZLIntegerChoicePreference extends ZLStringListPreference {
private final ZLIntegerOption myOption;
private final int[] myValues;
ZLIntegerChoicePreference(Context context, ZLResource resource, String resourceKey, ZLIntegerOption option, int[] values, String[] valueResourceKeys) {
super(context, resource, resourceKey);
ZLIntegerChoicePreference(Context context, ZLResource resource, ZLIntegerOption option, int[] values, String[] valueResourceKeys) {
super(context, resource);
assert(values.length == valueResourceKeys.length);
myOption = option;

View file

@ -73,9 +73,15 @@ abstract class ZLPreferenceActivity extends android.preference.PreferenceActivit
);
}
public <T extends Enum<T>> Preference addOption(ZLEnumOption<T> option, String resourceKey) {
public <T extends Enum<T>> Preference addOption(ZLEnumOption<T> option, String key) {
return addPreference(
new ZLEnumPreference<T>(ZLPreferenceActivity.this, option, Resource, resourceKey)
new ZLEnumPreference<T>(ZLPreferenceActivity.this, option, Resource.getResource(key))
);
}
public <T extends Enum<T>> Preference addOption(ZLEnumOption<T> option, String key, String valuesKey) {
return addPreference(
new ZLEnumPreference<T>(ZLPreferenceActivity.this, option, Resource.getResource(key), Resource.getResource(valuesKey))
);
}
}

View file

@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
class ZLStringChoicePreference extends ZLStringListPreference {
private final ZLStringOption myOption;
ZLStringChoicePreference(Context context, ZLResource rootResource, String resourceKey, ZLStringOption option, String[] values) {
super(context, rootResource, resourceKey);
ZLStringChoicePreference(Context context, ZLResource resource, ZLStringOption option, String[] values) {
super(context, resource);
setList(values);
setInitialValue(option.getValue());
myOption = option;

View file

@ -25,19 +25,22 @@ import android.preference.ListPreference;
import org.geometerplus.zlibrary.core.resources.ZLResource;
abstract class ZLStringListPreference extends ListPreference {
protected final ZLResource myResource;
protected final ZLResource myValuesResource;
ZLStringListPreference(Context context, ZLResource rootResource, String resourceKey) {
ZLStringListPreference(Context context, ZLResource resource) {
this(context, resource, resource);
}
ZLStringListPreference(Context context, ZLResource resource, ZLResource valuesResource) {
super(context);
myResource = rootResource.getResource(resourceKey);
setTitle(myResource.getValue());
setTitle(resource.getValue());
myValuesResource = valuesResource;
}
protected final void setList(String[] values) {
String[] texts = new String[values.length];
for (int i = 0; i < values.length; ++i) {
final ZLResource resource = myResource.getResource(values[i]);
final ZLResource resource = myValuesResource.getResource(values[i]);
texts[i] = resource.hasValue() ? resource.getValue() : values[i];
}
setLists(values, texts);

View file

@ -30,10 +30,10 @@ public class SyncOptions {
}
public final ZLEnumOption<SyncCondition> UploadAllBooks =
new ZLEnumOption<SyncCondition>("Sync", "UploadAllBooks", SyncCondition.viaWifi);
public final ZLBooleanOption Positions =
new ZLBooleanOption("Sync", "Positions", true);
public final ZLBooleanOption Bookmarks =
new ZLBooleanOption("Sync", "Bookmarks", true);
public final ZLBooleanOption Metainfo =
new ZLBooleanOption("Sync", "Metainfo", true);
public final ZLEnumOption<SyncCondition> Positions =
new ZLEnumOption<SyncCondition>("Sync", "Positions", SyncCondition.always);
public final ZLEnumOption<SyncCondition> Bookmarks =
new ZLEnumOption<SyncCondition>("Sync", "Bookmarks", SyncCondition.always);
public final ZLEnumOption<SyncCondition> Metainfo =
new ZLEnumOption<SyncCondition>("Sync", "Metainfo", SyncCondition.always);
}