mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
fmanager clean up
This commit is contained in:
parent
44a4e291e3
commit
777c6076a5
9 changed files with 75 additions and 165 deletions
|
@ -20,7 +20,20 @@
|
|||
package org.geometerplus.android.fbreader;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.io.File;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.ActionCode;
|
||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
import org.geometerplus.fbreader.library.Library;
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextView;
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.Intent;
|
||||
|
@ -33,23 +46,6 @@ import android.widget.RelativeLayout;
|
|||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextView;
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
import org.geometerplus.fbreader.fbreader.ActionCode;
|
||||
import org.geometerplus.fbreader.library.Library;
|
||||
|
||||
public final class FBReader extends ZLAndroidActivity {
|
||||
public static final String BOOK_PATH_KEY = "BookPath";
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||
public class FileListView {
|
||||
private Activity myParent;
|
||||
private String myCurDir = ".";
|
||||
private String myCurFile = ".";
|
||||
private String myFilterTypes = "";
|
||||
private String myCurFile = null;
|
||||
private String myTypes = "";
|
||||
|
||||
// Members for dynamic loading //
|
||||
private ArrayAdapter<String> myAdapter;
|
||||
|
@ -63,9 +63,9 @@ public class FileListView {
|
|||
myReturnRes = new ReturnRes(myOrders, myAdapter, myProgressDialog);
|
||||
myFilter = new SmartFilter(myParent, myOrders, myReturnRes);
|
||||
|
||||
final String startPath = myParent.getIntent().getExtras().getString(FileManager.FILE_MANAGER_PATH);
|
||||
final String fileTypes = myParent.getIntent().getExtras().getString(FileManager.FILE_MANAGER_TYPE);
|
||||
fill(startPath, fileTypes);
|
||||
myCurDir = myParent.getIntent().getExtras().getString(FileManager.FILE_MANAGER_PATH);
|
||||
myTypes = myParent.getIntent().getExtras().getString(FileManager.FILE_MANAGER_TYPE);
|
||||
fill(myCurDir);
|
||||
|
||||
listView.setTextFilterEnabled(true);
|
||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
@ -73,28 +73,23 @@ public class FileListView {
|
|||
int position, long id) {
|
||||
view.setSelected(true);
|
||||
|
||||
myCurDir = startPath;
|
||||
myCurFile = ((TextView) view).getText().toString();
|
||||
goAtDir(myCurDir + "/" + myCurFile);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public String getFilterTypes(){
|
||||
return myFilterTypes;
|
||||
public String getTypes(){
|
||||
return myTypes;
|
||||
}
|
||||
|
||||
public String getPathToFile(){
|
||||
if (myCurDir.equals(myCurFile))
|
||||
return null;
|
||||
return myCurDir + "/" + myCurFile;
|
||||
return myCurFile != null ? myCurDir + "/" + myCurFile : null;
|
||||
}
|
||||
|
||||
|
||||
public void setFilter(String filterTypes){
|
||||
if (!myFilterTypes.equals(filterTypes)){
|
||||
myFilterTypes = filterTypes;
|
||||
if (!myTypes.equals(filterTypes)){
|
||||
myTypes = filterTypes;
|
||||
goAtDir(myCurDir);
|
||||
}
|
||||
}
|
||||
|
@ -110,20 +105,21 @@ public class FileListView {
|
|||
|
||||
public void goAtDir(String path) {
|
||||
if (new File(path).isDirectory()){
|
||||
myCurFile = null;
|
||||
myCurFilterThread.interrupt();
|
||||
Intent i = new Intent(myParent, FileManager.class);
|
||||
i.putExtra(FileManager.FILE_MANAGER_PATH, path);
|
||||
i.putExtra(FileManager.FILE_MANAGER_TYPE, myFilterTypes);
|
||||
i.putExtra(FileManager.FILE_MANAGER_TYPE, myTypes);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
myParent.startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void fill(String path, String fileTypes){
|
||||
private void fill(String path){
|
||||
myProgressDialog.show();
|
||||
File file = new File(path);
|
||||
myCurDir = path;
|
||||
myFilter.setPreferences(file, fileTypes);
|
||||
myFilter.setPreferences(file, myTypes);
|
||||
myCurFilterThread = new Thread(null, myFilter, "MagentoBackground");
|
||||
myCurFilterThread.start();
|
||||
}
|
||||
|
|
|
@ -19,16 +19,11 @@
|
|||
|
||||
package org.geometerplus.android.fbreader.library;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.geometerplus.android.fbreader.FBReader;
|
||||
import org.geometerplus.fbreader.library.BookTree;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
@ -43,13 +38,18 @@ public final class FileManager extends Activity {
|
|||
|
||||
private FileListView myFileListView;
|
||||
|
||||
public static String FILE_MANAGER_PATH = "file_manager.path";
|
||||
public static String FILE_MANAGER_TYPE = "file_manager.type";
|
||||
public static String DEFAULT_START_PATH = FB_HOME_DIR;
|
||||
public static String FILE_MANAGER_LOG_TAG = "FileManager";
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.v(FILE_MANAGER_LOG_TAG, "onCreate()");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.file_manager);
|
||||
|
||||
// Obtain handles to UI objects
|
||||
ImageButton fbhomeButton = FileUtils.getImgBtn(this, R.id.fmanagerFBHomeButton, R.drawable.home);
|
||||
ImageButton cardButton = FileUtils.getImgBtn(this, R.id.fmanagerCardButton, R.drawable.sdcard);
|
||||
ImageButton rootButton = FileUtils.getImgBtn(this, R.id.fmanagerRootButton, R.drawable.root);
|
||||
|
@ -62,26 +62,9 @@ public final class FileManager extends Activity {
|
|||
ListView fileList = (ListView) findViewById(R.id.fileList1);
|
||||
myFileListView = new FileListView(this, fileList);
|
||||
|
||||
fbhomeButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// TODO
|
||||
myFileListView.goAtDir(FB_HOME_DIR);
|
||||
}
|
||||
});
|
||||
|
||||
cardButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// TODO
|
||||
myFileListView.goAtDir(SDCARD_DIR);
|
||||
}
|
||||
});
|
||||
|
||||
rootButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// TODO
|
||||
myFileListView.goAtDir(ROOT_DIR);
|
||||
}
|
||||
});
|
||||
setPathListener(fbhomeButton, FB_HOME_DIR);
|
||||
setPathListener(cardButton, ROOT_DIR);
|
||||
setPathListener(rootButton, SDCARD_DIR);
|
||||
|
||||
filterButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
|
@ -97,11 +80,7 @@ public final class FileManager extends Activity {
|
|||
|
||||
okButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
String path = myFileListView.getPathToFile();
|
||||
if (path != null){
|
||||
Log.v(FILE_MANAGER_LOG_TAG, "paht to book : " + path);
|
||||
launchFBReaderView(path);
|
||||
}
|
||||
launchFBReaderView();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -110,24 +89,8 @@ public final class FileManager extends Activity {
|
|||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void launchFBReaderView(String path){
|
||||
Intent i = new Intent(this, FBReader.class);
|
||||
i.setAction(Intent.ACTION_VIEW);
|
||||
i.putExtra(FBReader.BOOK_PATH_KEY, path);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
private void launchFilterView() {
|
||||
Intent i = new Intent(this, FilterView.class);
|
||||
i.putExtra(FILE_MANAGER_TYPE, myFileListView.getFilterTypes());
|
||||
startActivityForResult(i, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
@ -135,8 +98,33 @@ public final class FileManager extends Activity {
|
|||
myFileListView.setFilter(data.getAction());
|
||||
}
|
||||
|
||||
public static String FILE_MANAGER_PATH = "file_manager.path";
|
||||
public static String FILE_MANAGER_TYPE = "file_manager.type";
|
||||
private void launchFBReaderView(){
|
||||
String path = myFileListView.getPathToFile();
|
||||
if (path != null){
|
||||
Log.v(FILE_MANAGER_LOG_TAG, "paht to book : " + path); // TODO delete later
|
||||
path = path.substring(1);
|
||||
Intent i = new Intent(this, FBReader.class);
|
||||
i.setAction(Intent.ACTION_VIEW);
|
||||
i.putExtra(FBReader.BOOK_PATH_KEY, path);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
}
|
||||
else
|
||||
finish();
|
||||
}
|
||||
|
||||
public static String FILE_MANAGER_LOG_TAG = "FileManager";
|
||||
private void launchFilterView() {
|
||||
Intent i = new Intent(this, FilterView.class);
|
||||
i.putExtra(FILE_MANAGER_TYPE, myFileListView.getTypes());
|
||||
startActivityForResult(i, 1);
|
||||
}
|
||||
|
||||
private void setPathListener(ImageButton imgBtn, final String path){
|
||||
imgBtn.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
myFileListView.goAtDir(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,10 +55,9 @@ public class FileUtils {
|
|||
return imgBtn;
|
||||
}
|
||||
|
||||
// unstable - not testing
|
||||
// unstable - not testing // TODO
|
||||
public static void copyRecursive(String src, String path)
|
||||
throws IOException {
|
||||
// TODO
|
||||
File file = new File(src);
|
||||
if (file.isDirectory()) {
|
||||
path += src;
|
||||
|
|
|
@ -83,7 +83,6 @@ public class FilterView extends Activity{
|
|||
}
|
||||
|
||||
private void setCurrentTypes(){
|
||||
// TODO
|
||||
String types = getIntent().getExtras().getString(FileManager.FILE_MANAGER_TYPE);
|
||||
if (types.equals(""))
|
||||
return;
|
||||
|
|
|
@ -132,9 +132,6 @@ abstract class LibraryBaseActivity extends ListActivity {
|
|||
public OpenTreeRunnable(String treePath, String selectedBookPath) {
|
||||
myTreePath = treePath;
|
||||
mySelectedBookPath = selectedBookPath;
|
||||
|
||||
// TODO delete later
|
||||
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "===" + myTreePath + mySelectedBookPath);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -110,7 +110,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
|||
private void runFileManager(){
|
||||
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "runFileManager()");
|
||||
Intent i = new Intent(this, FileManager.class);
|
||||
i.putExtra(FileManager.FILE_MANAGER_PATH, "/sdcard/Books");
|
||||
i.putExtra(FileManager.FILE_MANAGER_PATH, FileManager.DEFAULT_START_PATH);
|
||||
i.putExtra(FileManager.FILE_MANAGER_TYPE, "");
|
||||
startActivity(i);
|
||||
}
|
||||
|
|
|
@ -84,9 +84,6 @@ public class LibraryTreeActivity extends LibraryBaseActivity {
|
|||
.putExtra(FBReader.BOOK_PATH_KEY, ((BookTree)tree).Book.File.getPath())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
);
|
||||
// TODO delete later
|
||||
Log.v(FileManager.FILE_MANAGER_LOG_TAG, " asasasa + " + ((BookTree)tree).Book.File.getPath());
|
||||
|
||||
} else {
|
||||
new OpenTreeRunnable(
|
||||
myTreePathString + "\000" + tree.getName(),
|
||||
|
|
|
@ -34,11 +34,7 @@ public class SmartFilter implements Runnable {
|
|||
|
||||
private File myFile;
|
||||
private String myNewTypes;
|
||||
|
||||
private String myCurPath = "";
|
||||
private List<String> myCurFiles = new ArrayList<String>();
|
||||
private String myCurTypes = "";
|
||||
|
||||
|
||||
public SmartFilter(Activity parent, List<String> orders, Runnable action) {
|
||||
myParent = parent;
|
||||
|
@ -53,61 +49,16 @@ public class SmartFilter implements Runnable {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
getOrders();
|
||||
try {
|
||||
getOrders();
|
||||
} catch (Exception e) {
|
||||
Log.e(FileManager.FILE_MANAGER_LOG_TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void getOrders() {
|
||||
try {
|
||||
if (myCurPath.equals(myFile.getPath())
|
||||
&& compareTypes(myCurTypes, myNewTypes))
|
||||
getOrderInCurrentDir();
|
||||
else
|
||||
getOrderInNewDir();
|
||||
} catch (Exception e) {
|
||||
Log.e("BACKGROUND_PROC", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void getOrderInCurrentDir() {
|
||||
String delTypes = "";
|
||||
for (String curType : myCurTypes.split("[\\s]+")) {
|
||||
if (myNewTypes.indexOf(curType.trim()) < 0)
|
||||
delTypes += curType + " ";
|
||||
}
|
||||
|
||||
List<String> newListFiles = new ArrayList<String>();
|
||||
for (String file : myCurFiles) {
|
||||
if (!Thread.currentThread().isInterrupted()) {
|
||||
|
||||
// В реальных условиях здесь
|
||||
// код будет красивее
|
||||
// timeKiller() - работаем c файлом
|
||||
// FIXME delete later!!!
|
||||
// timeKiller(); // TODO DELETE LATER
|
||||
|
||||
String fileName = null;
|
||||
if (!condition(file, delTypes))
|
||||
fileName = file;
|
||||
if (!Thread.currentThread().isInterrupted() && fileName != null) {
|
||||
myOrders.add(fileName);
|
||||
newListFiles.add(fileName);
|
||||
}
|
||||
myParent.runOnUiThread(myAction);
|
||||
}
|
||||
myCurFiles = newListFiles;
|
||||
myParent.runOnUiThread(myAction);
|
||||
}
|
||||
}
|
||||
|
||||
private void getOrderInNewDir() {
|
||||
myCurPath = myFile.getPath();
|
||||
for (File file : myFile.listFiles()) {
|
||||
if (!Thread.currentThread().isInterrupted()) {
|
||||
|
||||
// В реальных условиях здесь
|
||||
// код будет красивее
|
||||
// timeKiller() - работаем c файлом
|
||||
|
||||
String fileName = null;
|
||||
if (file.isDirectory())
|
||||
fileName = file.getName();
|
||||
|
@ -117,7 +68,6 @@ public class SmartFilter implements Runnable {
|
|||
myOrders.add(fileName);
|
||||
myCurFiles.add(fileName);
|
||||
}
|
||||
|
||||
myParent.runOnUiThread(myAction);
|
||||
}
|
||||
}
|
||||
|
@ -137,16 +87,4 @@ public class SmartFilter implements Runnable {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean compareTypes(String curTypes, String newTypes) {
|
||||
if (newTypes.equals(""))
|
||||
return false;
|
||||
if (newTypes.length() > curTypes.length())
|
||||
return false;
|
||||
for (String newType : newTypes.split("[\\s]+")) {
|
||||
if (curTypes.indexOf(newType.trim()) < 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue