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

update library on changing download directory

This commit is contained in:
Nikolay Pultsin 2014-04-19 04:11:42 +01:00
parent affff7e149
commit 7d8c3de94d
5 changed files with 43 additions and 45 deletions

View file

@ -91,30 +91,31 @@ public class PreferenceActivity extends ZLPreferenceActivity {
String.valueOf(new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator());
final Screen directoriesScreen = createPreferenceScreen("directories");
directoriesScreen.addPreference(myChooserCollection.createPreference(
directoriesScreen.Resource, "bookPath", Paths.BookPathOption, new Runnable() {
public void run() {
final BookCollectionShadow collection = new BookCollectionShadow();
collection.bindToService(PreferenceActivity.this, new Runnable() {
public void run() {
collection.reset(false);
collection.unbind();
}
});
}
final Runnable libraryUpdater = new Runnable() {
public void run() {
final BookCollectionShadow collection = new BookCollectionShadow();
collection.bindToService(PreferenceActivity.this, new Runnable() {
public void run() {
collection.reset(false);
collection.unbind();
}
});
}
};
directoriesScreen.addPreference(myChooserCollection.createPreference(
directoriesScreen.Resource, "bookPath", Paths.BookPathOption, libraryUpdater
));
directoriesScreen.addPreference(myChooserCollection.createPreference(
directoriesScreen.Resource, "downloadDir", Paths.DownloadsDirectoryOption()
directoriesScreen.Resource, "downloadDir", Paths.DownloadsDirectoryOption(), libraryUpdater
));
directoriesScreen.addPreference(myChooserCollection.createPreference(
directoriesScreen.Resource, "fontPath", Paths.FontPathOption
directoriesScreen.Resource, "fontPath", Paths.FontPathOption, null
));
directoriesScreen.addPreference(myChooserCollection.createPreference(
directoriesScreen.Resource, "wallpaperPath", Paths.WallpaperPathOption
directoriesScreen.Resource, "wallpaperPath", Paths.WallpaperPathOption, null
));
directoriesScreen.addPreference(myChooserCollection.createPreference(
directoriesScreen.Resource, "tempDir", Paths.TempDirectoryOption()
directoriesScreen.Resource, "tempDir", Paths.TempDirectoryOption(), null
));
final Screen appearanceScreen = createPreferenceScreen("appearance");

View file

@ -39,10 +39,6 @@ public class FileChooserCollection {
myContext = context;
}
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringListOption option) {
return createPreference(rootResource, resourceKey, option, null);
}
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringListOption option, Runnable onValueSetAction) {
final FileChooserPreference preference = new FileChooserStringListPreference(
myContext, rootResource, resourceKey, option, myPreferences.size(), onValueSetAction
@ -51,9 +47,9 @@ public class FileChooserCollection {
return preference;
}
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringOption option) {
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringOption option, Runnable onValueSetAction) {
final FileChooserPreference preference = new FileChooserStringPreference(
myContext, rootResource, resourceKey, option, myPreferences.size()
myContext, rootResource, resourceKey, option, myPreferences.size(), onValueSetAction
);
myPreferences.add(preference);
return preference;

View file

@ -24,6 +24,7 @@ import android.content.Context;
import android.preference.Preference;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.MiscUtil;
import org.geometerplus.android.util.FileChooserUtil;
@ -31,14 +32,17 @@ abstract class FileChooserPreference extends Preference {
private final int myRegCode;
private final ZLResource myResource;
private final boolean myChooseWritableDirectoriesOnly;
private final Runnable myOnValueSetAction;
FileChooserPreference(Context context, ZLResource rootResource, String resourceKey, boolean chooseWritableDirectoriesOnly, int regCode) {
FileChooserPreference(Context context, ZLResource rootResource, String resourceKey, boolean chooseWritableDirectoriesOnly, int regCode, Runnable onValueSetAction) {
super(context);
myRegCode = regCode;
myChooseWritableDirectoriesOnly = chooseWritableDirectoriesOnly;
myResource = rootResource.getResource(resourceKey);
setTitle(myResource.getValue());
myChooseWritableDirectoriesOnly = chooseWritableDirectoriesOnly;
myOnValueSetAction = onValueSetAction;
}
@Override
@ -53,5 +57,18 @@ abstract class FileChooserPreference extends Preference {
}
protected abstract String getStringValue();
protected abstract void setValue(String value);
protected final void setValue(String value) {
if (MiscUtil.isEmptyString(value)) {
return;
}
setValueInternal(value);
if (myOnValueSetAction != null) {
myOnValueSetAction.run();
}
}
protected abstract void setValueInternal(String value);
}

View file

@ -26,17 +26,14 @@ import android.content.Context;
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.MiscUtil;
class FileChooserStringListPreference extends FileChooserPreference {
private final ZLStringListOption myOption;
private final Runnable myOnValueSetAction;
FileChooserStringListPreference(Context context, ZLResource rootResource, String resourceKey, ZLStringListOption option, int regCode, Runnable onValueSetAction) {
super(context, rootResource, resourceKey, false, regCode);
super(context, rootResource, resourceKey, false, regCode, onValueSetAction);
myOption = option;
myOnValueSetAction = onValueSetAction;
setSummary(getStringValue());
}
@ -48,19 +45,11 @@ class FileChooserStringListPreference extends FileChooserPreference {
}
@Override
protected void setValue(String value) {
if (MiscUtil.isEmptyString(value)) {
return;
}
protected void setValueInternal(String value) {
final List<String> currentValues = myOption.getValue();
if (currentValues.size() != 1 || !currentValues.get(0).equals(value)) {
myOption.setValue(Collections.singletonList(value));
setSummary(value);
}
if (myOnValueSetAction != null) {
myOnValueSetAction.run();
}
}
}

View file

@ -23,13 +23,12 @@ import android.content.Context;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.MiscUtil;
class FileChooserStringPreference extends FileChooserPreference {
private final ZLStringOption myOption;
FileChooserStringPreference(Context context, ZLResource rootResource, String resourceKey, ZLStringOption option, int regCode) {
super(context, rootResource, resourceKey, true, regCode);
FileChooserStringPreference(Context context, ZLResource rootResource, String resourceKey, ZLStringOption option, int regCode, Runnable onValueSetAction) {
super(context, rootResource, resourceKey, true, regCode, onValueSetAction);
myOption = option;
setSummary(getStringValue());
@ -41,11 +40,7 @@ class FileChooserStringPreference extends FileChooserPreference {
}
@Override
protected void setValue(String value) {
if (MiscUtil.isEmptyString(value)) {
return;
}
protected void setValueInternal(String value) {
final String currentValue = myOption.getValue();
if (!currentValue.equals(value)) {
myOption.setValue(value);