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

Merge branch 'master' into dm

Conflicts:
	src/org/geometerplus/android/fbreader/preferences/fileChooser/FileChooserPreference.java
	src/org/geometerplus/android/fbreader/preferences/fileChooser/FileChooserStringListPreference.java
This commit is contained in:
Nikolay Pultsin 2014-05-03 02:29:32 +01:00
commit 40a4619689
3 changed files with 14 additions and 42 deletions

View file

@ -19,15 +19,12 @@
package org.geometerplus.android.fbreader.preferences.fileChooser; package org.geometerplus.android.fbreader.preferences.fileChooser;
import java.util.ArrayList;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.preference.Preference; import android.preference.Preference;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.MiscUtil;
import org.geometerplus.android.util.FileChooserUtil; import org.geometerplus.android.util.FileChooserUtil;
@ -50,7 +47,7 @@ abstract class FileChooserPreference extends Preference {
@Override @Override
protected void onClick() { protected void onClick() {
FileChooserUtil.runDirectoryChooser( FileChooserUtil.runDirectoryChooser(
(Activity)getContext(), (Activity)getContext(),
myRegCode, myRegCode,
myResource.getResource("chooserTitle").getValue(), myResource.getResource("chooserTitle").getValue(),
@ -60,19 +57,5 @@ abstract class FileChooserPreference extends Preference {
} }
protected abstract String getStringValue(); protected abstract String getStringValue();
protected abstract void setValueFromIntent(Intent data); protected abstract void setValueFromIntent(Intent data);
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

@ -53,15 +53,11 @@ class FileChooserStringListPreference extends FileChooserPreference {
myRegCode, myRegCode,
myResource.getValue(), myResource.getValue(),
myResource.getResource("chooserTitle").getValue(), myResource.getResource("chooserTitle").getValue(),
getStringListValue(), new ArrayList<String>(myOption.getValue()),
myChooseWritableDirectoriesOnly myChooseWritableDirectoriesOnly
); );
} }
private ArrayList<String> getStringListValue(){
return new ArrayList<String>(myOption.getValue());
}
@Override @Override
protected String getStringValue() { protected String getStringValue() {
return MiscUtil.join(myOption.getValue(), ", "); return MiscUtil.join(myOption.getValue(), ", ");
@ -69,19 +65,7 @@ class FileChooserStringListPreference extends FileChooserPreference {
@Override @Override
protected void setValueFromIntent(Intent data) { protected void setValueFromIntent(Intent data) {
setValue(FileChooserUtil.pathArrayFromData(data)); final List<String> value = FileChooserUtil.pathArrayFromData(data);
}
@Override
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(getStringValue());
}
}
protected final void setValue(ArrayList<String> value) {
if (value.isEmpty()){ if (value.isEmpty()){
return; return;
} }

View file

@ -24,6 +24,7 @@ import android.content.Intent;
import org.geometerplus.zlibrary.core.options.ZLStringOption; import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.MiscUtil;
import org.geometerplus.android.util.FileChooserUtil; import org.geometerplus.android.util.FileChooserUtil;
@ -44,15 +45,19 @@ class FileChooserStringPreference extends FileChooserPreference {
@Override @Override
protected void setValueFromIntent(Intent data) { protected void setValueFromIntent(Intent data) {
setValue(FileChooserUtil.pathFromData(data)); final String value = FileChooserUtil.pathFromData(data);
} if (MiscUtil.isEmptyString(value)) {
return;
}
@Override
protected void setValueInternal(String value) {
final String currentValue = myOption.getValue(); final String currentValue = myOption.getValue();
if (!currentValue.equals(value)) { if (!currentValue.equals(value)) {
myOption.setValue(value); myOption.setValue(value);
setSummary(value); setSummary(value);
} }
if (myOnValueSetAction != null) {
myOnValueSetAction.run();
}
} }
} }