mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
refactoring for better compatibility with multidir settings
This commit is contained in:
parent
69b426203e
commit
471cef831c
4 changed files with 22 additions and 5 deletions
|
@ -29,8 +29,6 @@ import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
|||
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.android.util.FileChooserUtil;
|
||||
|
||||
public class FileChooserCollection {
|
||||
private final Context myContext;
|
||||
private final List<FileChooserPreference> myPreferences = new ArrayList<FileChooserPreference>();
|
||||
|
@ -57,7 +55,7 @@ public class FileChooserCollection {
|
|||
|
||||
public void update(int index, Intent data) {
|
||||
try {
|
||||
myPreferences.get(index).setValue(FileChooserUtil.pathFromData(data));
|
||||
myPreferences.get(index).setValueFromIntent(data);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.geometerplus.android.fbreader.preferences.fileChooser;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.preference.Preference;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
@ -32,7 +33,7 @@ abstract class FileChooserPreference extends Preference {
|
|||
private final int myRegCode;
|
||||
private final ZLResource myResource;
|
||||
private final boolean myChooseWritableDirectoriesOnly;
|
||||
private final Runnable myOnValueSetAction;
|
||||
protected final Runnable myOnValueSetAction;
|
||||
|
||||
FileChooserPreference(Context context, ZLResource rootResource, String resourceKey, boolean chooseWritableDirectoriesOnly, int regCode, Runnable onValueSetAction) {
|
||||
super(context);
|
||||
|
@ -58,6 +59,8 @@ abstract class FileChooserPreference extends Preference {
|
|||
|
||||
protected abstract String getStringValue();
|
||||
|
||||
protected abstract void setValueFromIntent(Intent data);
|
||||
|
||||
protected final void setValue(String value) {
|
||||
if (MiscUtil.isEmptyString(value)) {
|
||||
return;
|
||||
|
|
|
@ -23,11 +23,14 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||
|
||||
import org.geometerplus.android.util.FileChooserUtil;
|
||||
|
||||
class FileChooserStringListPreference extends FileChooserPreference {
|
||||
private final ZLStringListOption myOption;
|
||||
|
||||
|
@ -44,12 +47,17 @@ class FileChooserStringListPreference extends FileChooserPreference {
|
|||
return MiscUtil.join(myOption.getValue(), ", ");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValueFromIntent(Intent data) {
|
||||
setValue(FileChooserUtil.pathFromData(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(value);
|
||||
setSummary(getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,13 @@
|
|||
package org.geometerplus.android.fbreader.preferences.fileChooser;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.android.util.FileChooserUtil;
|
||||
|
||||
class FileChooserStringPreference extends FileChooserPreference {
|
||||
private final ZLStringOption myOption;
|
||||
|
||||
|
@ -39,6 +42,11 @@ class FileChooserStringPreference extends FileChooserPreference {
|
|||
return myOption.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValueFromIntent(Intent data) {
|
||||
setValue(FileChooserUtil.pathFromData(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValueInternal(String value) {
|
||||
final String currentValue = myOption.getValue();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue