mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
refactoring
This commit is contained in:
parent
471cef831c
commit
9f9b0ce63a
3 changed files with 17 additions and 24 deletions
|
@ -25,7 +25,6 @@ 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;
|
||||||
|
|
||||||
|
@ -58,20 +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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,15 +49,19 @@ class FileChooserStringListPreference 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 List<String> currentValues = myOption.getValue();
|
final List<String> currentValues = myOption.getValue();
|
||||||
if (currentValues.size() != 1 || !currentValues.get(0).equals(value)) {
|
if (currentValues.size() != 1 || !currentValues.get(0).equals(value)) {
|
||||||
myOption.setValue(Collections.singletonList(value));
|
myOption.setValue(Collections.singletonList(value));
|
||||||
setSummary(getStringValue());
|
setSummary(getStringValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myOnValueSetAction != null) {
|
||||||
|
myOnValueSetAction.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue