diff --git a/src/org/geometerplus/android/fbreader/crash/FixBooksDirectoryActivity.java b/src/org/geometerplus/android/fbreader/crash/FixBooksDirectoryActivity.java index 65fb394a0..6fac52c97 100644 --- a/src/org/geometerplus/android/fbreader/crash/FixBooksDirectoryActivity.java +++ b/src/org/geometerplus/android/fbreader/crash/FixBooksDirectoryActivity.java @@ -19,6 +19,9 @@ package org.geometerplus.android.fbreader.crash; +import java.util.LinkedList; +import java.util.List; + import android.app.Activity; import android.content.Intent; import android.os.Bundle; @@ -56,7 +59,12 @@ public class FixBooksDirectoryActivity extends Activity { okButton.setText(buttonResource.getResource("ok").getValue()); okButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { - Paths.BooksDirectoryOption().setValue(directoryView.getText().toString()); + final List bookPath = + new LinkedList(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)); finish(); } diff --git a/src/org/geometerplus/android/fbreader/libraryService/BookCollectionShadow.java b/src/org/geometerplus/android/fbreader/libraryService/BookCollectionShadow.java index 35f6594c7..4e2eefb95 100644 --- a/src/org/geometerplus/android/fbreader/libraryService/BookCollectionShadow.java +++ b/src/org/geometerplus/android/fbreader/libraryService/BookCollectionShadow.java @@ -111,9 +111,7 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv public synchronized void reset(boolean force) { if (myInterface != null) { try { - myInterface.reset( - Util.splitDirectories(Paths.BooksDirectoryOption().getValue()), force - ); + myInterface.reset(Paths.BookPathOption().getValue(), force); } catch (RemoteException e) { } } diff --git a/src/org/geometerplus/android/fbreader/libraryService/LibraryService.java b/src/org/geometerplus/android/fbreader/libraryService/LibraryService.java index e5be3e7c5..a807b51f7 100644 --- a/src/org/geometerplus/android/fbreader/libraryService/LibraryService.java +++ b/src/org/geometerplus/android/fbreader/libraryService/LibraryService.java @@ -89,7 +89,7 @@ public class LibraryService extends Service { LibraryImplementation() { myDatabase = SQLiteBooksDatabase.Instance(LibraryService.this); - reset(Util.splitDirectories(Paths.BooksDirectoryOption().getValue()), true); + reset(Paths.BookPathOption().getValue(), true); } public void reset(List bookDirectories, boolean force) { diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index e3e14c369..40551c7f0 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -80,8 +80,8 @@ public class PreferenceActivity extends ZLPreferenceActivity { String.valueOf(new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator()); final Screen directoriesScreen = createPreferenceScreen("directories"); - directoriesScreen.addPreference(new ZLStringOptionPreference( - this, Paths.BooksDirectoryOption(), directoriesScreen.Resource, "books" + directoriesScreen.addPreference(new ZLStringListOptionPreference( + this, Paths.BookPathOption(), directoriesScreen.Resource, "books" ) { protected void setValue(String value) { super.setValue(value); diff --git a/src/org/geometerplus/android/fbreader/preferences/ZLStringListOptionPreference.java b/src/org/geometerplus/android/fbreader/preferences/ZLStringListOptionPreference.java new file mode 100644 index 000000000..244e2433f --- /dev/null +++ b/src/org/geometerplus/android/fbreader/preferences/ZLStringListOptionPreference.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2009-2013 Geometer Plus + * + * 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 optionValues = myOption.getValue(); + super.setValue(optionValues.isEmpty() ? "" : optionValues.get(0)); + } + + @Override + protected void setValue(String value) { + super.setValue(value); + final List optionValues = new ArrayList(myOption.getValue()); + if (optionValues.isEmpty()) { + optionValues.add(value); + } else { + optionValues.set(0, value); + } + myOption.setValue(optionValues); + } +} diff --git a/src/org/geometerplus/fbreader/Paths.java b/src/org/geometerplus/fbreader/Paths.java index ccf588b1f..d8eeffd8a 100644 --- a/src/org/geometerplus/fbreader/Paths.java +++ b/src/org/geometerplus/fbreader/Paths.java @@ -19,18 +19,25 @@ package org.geometerplus.fbreader; +import java.util.List; + import android.os.Environment; import org.geometerplus.android.fbreader.libraryService.Util; import org.geometerplus.zlibrary.core.options.ZLStringOption; +import org.geometerplus.zlibrary.core.options.ZLStringListOption; public abstract class Paths { public static String cardDirectory() { return Environment.getExternalStorageDirectory().getPath(); } - public static ZLStringOption BooksDirectoryOption() { - return new ZLStringOption("Files", "BooksDirectory", cardDirectory() + "/Books"); + private static String defaultBookDirectory() { + return cardDirectory() + "/Books"; + } + + public static ZLStringListOption BookPathOption() { + return new ZLStringListOption("Files", "BooksDirectory", defaultBookDirectory(), "\n"); } public static ZLStringOption FontsDirectoryOption() { @@ -42,7 +49,8 @@ public abstract class Paths { } public static String mainBookDirectory() { - return Util.splitDirectories(BooksDirectoryOption().getValue()).get(0); + final List bookPath = BookPathOption().getValue(); + return bookPath.isEmpty() ? defaultBookDirectory() : bookPath.get(0); } public static String cacheDirectory() { diff --git a/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java b/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java index ab8d8a544..06b58e489 100644 --- a/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java +++ b/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java @@ -30,27 +30,14 @@ import org.geometerplus.android.fbreader.libraryService.Util; public class FileFirstLevelTree extends FirstLevelTree { FileFirstLevelTree(RootTree root) { super(root, ROOT_FILE_TREE); - List directories = Util.splitDirectories(Paths.BooksDirectoryOption().getValue()); - if (directories.size() == 1) - addChild(directories.get(0), NODE_LIBRARY_DIRECTORY); - else { - FirstLevelTree libraryGroup = new FirstLevelTree(this, NODE_LIBRARY_DIRECTORY); - for (String d : directories) { - final ZLFile file = ZLFile.createFileByPath(d); - if (file != null) { - new FileTree( - libraryGroup, - file, - file.getShortName(), - file.getPath()); - } - } + for (String dir : Paths.BookPathOption().getValue()) { + addChild(dir, "fileTreeLibrary", dir); } - addChild("/", "fileTreeRoot"); - 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); if (file != null) { final ZLResource resource = resource().getResource(resourceKey); @@ -58,7 +45,7 @@ public class FileFirstLevelTree extends FirstLevelTree { this, file, resource.getValue(), - resource.getResource("summary").getValue() + summary != null ? summary : resource.getResource("summary").getValue() ); } }