mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
string list as book path (only first element can be set from preferences)
This commit is contained in:
parent
56d7de4620
commit
9b5718e104
7 changed files with 82 additions and 15 deletions
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader.crash;
|
package org.geometerplus.android.fbreader.crash;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -56,7 +59,12 @@ public class FixBooksDirectoryActivity extends Activity {
|
||||||
okButton.setText(buttonResource.getResource("ok").getValue());
|
okButton.setText(buttonResource.getResource("ok").getValue());
|
||||||
okButton.setOnClickListener(new Button.OnClickListener() {
|
okButton.setOnClickListener(new Button.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Paths.BooksDirectoryOption().setValue(directoryView.getText().toString());
|
final List<String> bookPath =
|
||||||
|
new LinkedList<String>(Paths.BookPathOption().getValue());
|
||||||
|
final String newDirectory = directoryView.getText().toString();
|
||||||
|
bookPath.remove(newDirectory);
|
||||||
|
bookPath.add(0, newDirectory);
|
||||||
|
Paths.BookPathOption().setValue(bookPath);
|
||||||
startActivity(new Intent(FixBooksDirectoryActivity.this, FBReader.class));
|
startActivity(new Intent(FixBooksDirectoryActivity.this, FBReader.class));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,9 +111,7 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
||||||
public synchronized void reset(boolean force) {
|
public synchronized void reset(boolean force) {
|
||||||
if (myInterface != null) {
|
if (myInterface != null) {
|
||||||
try {
|
try {
|
||||||
myInterface.reset(
|
myInterface.reset(Paths.BookPathOption().getValue(), force);
|
||||||
Collections.singletonList(Paths.BooksDirectoryOption().getValue()), force
|
|
||||||
);
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class LibraryService extends Service {
|
||||||
|
|
||||||
LibraryImplementation() {
|
LibraryImplementation() {
|
||||||
myDatabase = SQLiteBooksDatabase.Instance(LibraryService.this);
|
myDatabase = SQLiteBooksDatabase.Instance(LibraryService.this);
|
||||||
reset(Collections.singletonList(Paths.BooksDirectoryOption().getValue()), true);
|
reset(Paths.BookPathOption().getValue(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(List<String> bookDirectories, boolean force) {
|
public void reset(List<String> bookDirectories, boolean force) {
|
||||||
|
|
|
@ -80,8 +80,8 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
String.valueOf(new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator());
|
String.valueOf(new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator());
|
||||||
|
|
||||||
final Screen directoriesScreen = createPreferenceScreen("directories");
|
final Screen directoriesScreen = createPreferenceScreen("directories");
|
||||||
directoriesScreen.addPreference(new ZLStringOptionPreference(
|
directoriesScreen.addPreference(new ZLStringListOptionPreference(
|
||||||
this, Paths.BooksDirectoryOption(), directoriesScreen.Resource, "books"
|
this, Paths.BookPathOption(), directoriesScreen.Resource, "books"
|
||||||
) {
|
) {
|
||||||
protected void setValue(String value) {
|
protected void setValue(String value) {
|
||||||
super.setValue(value);
|
super.setValue(value);
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2009-2013 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.preferences;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
class ZLStringListOptionPreference extends ZLStringPreference {
|
||||||
|
private final ZLStringListOption myOption;
|
||||||
|
|
||||||
|
ZLStringListOptionPreference(Context context, ZLStringListOption option, ZLResource rootResource, String resourceKey) {
|
||||||
|
super(context, rootResource, resourceKey);
|
||||||
|
myOption = option;
|
||||||
|
final List<String> optionValues = myOption.getValue();
|
||||||
|
super.setValue(optionValues.isEmpty() ? "" : optionValues.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setValue(String value) {
|
||||||
|
super.setValue(value);
|
||||||
|
final List<String> optionValues = new ArrayList<String>(myOption.getValue());
|
||||||
|
if (optionValues.isEmpty()) {
|
||||||
|
optionValues.add(value);
|
||||||
|
} else {
|
||||||
|
optionValues.set(0, value);
|
||||||
|
}
|
||||||
|
myOption.setValue(optionValues);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,17 +19,24 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader;
|
package org.geometerplus.fbreader;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||||
|
|
||||||
public abstract class Paths {
|
public abstract class Paths {
|
||||||
public static String cardDirectory() {
|
public static String cardDirectory() {
|
||||||
return Environment.getExternalStorageDirectory().getPath();
|
return Environment.getExternalStorageDirectory().getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZLStringOption BooksDirectoryOption() {
|
private static String defaultBookDirectory() {
|
||||||
return new ZLStringOption("Files", "BooksDirectory", cardDirectory() + "/Books");
|
return cardDirectory() + "/Books";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ZLStringListOption BookPathOption() {
|
||||||
|
return new ZLStringListOption("Files", "BooksDirectory", defaultBookDirectory(), "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZLStringOption FontsDirectoryOption() {
|
public static ZLStringOption FontsDirectoryOption() {
|
||||||
|
@ -41,7 +48,8 @@ public abstract class Paths {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String mainBookDirectory() {
|
public static String mainBookDirectory() {
|
||||||
return BooksDirectoryOption().getValue();
|
final List<String> bookPath = BookPathOption().getValue();
|
||||||
|
return bookPath.isEmpty() ? defaultBookDirectory() : bookPath.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String cacheDirectory() {
|
public static String cacheDirectory() {
|
||||||
|
|
|
@ -27,12 +27,14 @@ import org.geometerplus.fbreader.Paths;
|
||||||
public class FileFirstLevelTree extends FirstLevelTree {
|
public class FileFirstLevelTree extends FirstLevelTree {
|
||||||
FileFirstLevelTree(RootTree root) {
|
FileFirstLevelTree(RootTree root) {
|
||||||
super(root, ROOT_FILE_TREE);
|
super(root, ROOT_FILE_TREE);
|
||||||
addChild(Paths.BooksDirectoryOption().getValue(), "fileTreeLibrary");
|
for (String dir : Paths.BookPathOption().getValue()) {
|
||||||
addChild("/", "fileTreeRoot");
|
addChild(dir, "fileTreeLibrary", dir);
|
||||||
addChild(Paths.cardDirectory(), "fileTreeCard");
|
}
|
||||||
|
addChild("/", "fileTreeRoot", null);
|
||||||
|
addChild(Paths.cardDirectory(), "fileTreeCard", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addChild(String path, String resourceKey) {
|
private void addChild(String path, String resourceKey, String summary) {
|
||||||
final ZLFile file = ZLFile.createFileByPath(path);
|
final ZLFile file = ZLFile.createFileByPath(path);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
final ZLResource resource = resource().getResource(resourceKey);
|
final ZLResource resource = resource().getResource(resourceKey);
|
||||||
|
@ -40,7 +42,7 @@ public class FileFirstLevelTree extends FirstLevelTree {
|
||||||
this,
|
this,
|
||||||
file,
|
file,
|
||||||
resource.getValue(),
|
resource.getValue(),
|
||||||
resource.getResource("summary").getValue()
|
summary != null ? summary : resource.getResource("summary").getValue()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue