1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

Merge branch 'multidir' into rusnavu-master

Conflicts:
	src/org/geometerplus/android/fbreader/libraryService/BookCollectionShadow.java
	src/org/geometerplus/android/fbreader/libraryService/LibraryService.java
	src/org/geometerplus/fbreader/Paths.java
	src/org/geometerplus/fbreader/library/FileFirstLevelTree.java
This commit is contained in:
Nikolay Pultsin 2013-10-12 12:28:10 +01:00
commit faa64fe9a1
7 changed files with 81 additions and 29 deletions

View file

@ -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();
} }

View file

@ -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);
Util.splitDirectories(Paths.BooksDirectoryOption().getValue()), force
);
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }

View file

@ -89,7 +89,7 @@ public class LibraryService extends Service {
LibraryImplementation() { LibraryImplementation() {
myDatabase = SQLiteBooksDatabase.Instance(LibraryService.this); myDatabase = SQLiteBooksDatabase.Instance(LibraryService.this);
reset(Util.splitDirectories(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) {

View file

@ -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);

View file

@ -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);
}
}

View file

@ -19,18 +19,25 @@
package org.geometerplus.fbreader; package org.geometerplus.fbreader;
import java.util.List;
import android.os.Environment; import android.os.Environment;
import org.geometerplus.android.fbreader.libraryService.Util; import org.geometerplus.android.fbreader.libraryService.Util;
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() {
@ -42,7 +49,8 @@ public abstract class Paths {
} }
public static String mainBookDirectory() { public static String mainBookDirectory() {
return Util.splitDirectories(BooksDirectoryOption().getValue()).get(0); final List<String> bookPath = BookPathOption().getValue();
return bookPath.isEmpty() ? defaultBookDirectory() : bookPath.get(0);
} }
public static String cacheDirectory() { public static String cacheDirectory() {

View file

@ -30,27 +30,14 @@ import org.geometerplus.android.fbreader.libraryService.Util;
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);
List<String> directories = Util.splitDirectories(Paths.BooksDirectoryOption().getValue()); for (String dir : Paths.BookPathOption().getValue()) {
if (directories.size() == 1) addChild(dir, "fileTreeLibrary", dir);
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());
}
}
} }
addChild("/", "fileTreeRoot"); addChild("/", "fileTreeRoot", null);
addChild(Paths.cardDirectory(), "fileTreeCard"); 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);
@ -58,7 +45,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()
); );
} }
} }