mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
Directories manager, draft
This commit is contained in:
parent
4794423739
commit
2db6151b21
12 changed files with 277 additions and 32 deletions
BIN
res/drawable/delete_icon.png
Normal file
BIN
res/drawable/delete_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
res/drawable/delete_icon_pressed.png
Normal file
BIN
res/drawable/delete_icon_pressed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
5
res/drawable/selection_delete.xml
Normal file
5
res/drawable/selection_delete.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/delete_icon_pressed" />
|
||||
<item android:drawable="@drawable/delete_icon" />
|
||||
</selector>
|
21
res/layout/dir_list.xml
Normal file
21
res/layout/dir_list.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/delete"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:src="@drawable/selection_delete"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="5dp"
|
||||
android:layout_toLeftOf="@id/delete"
|
||||
android:textSize="16dp"/>
|
||||
</RelativeLayout>
|
|
@ -1,22 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
>
|
||||
<ListView
|
||||
android:id="@+id/directories"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentTop="true"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_action_buttons"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
android:id="@+id/button_ok"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
|
@ -36,4 +28,12 @@
|
|||
android:text="Cancel"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<ListView
|
||||
android:id="@+id/directories"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_above="@id/layout_action_buttons"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -20,34 +20,173 @@
|
|||
package org.geometerplus.android.fbreader;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.app.Activity;
|
||||
|
||||
import android.widget.Button;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.Runnable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.widget.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.android.util.FileChooserUtil;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
public class DirectoriesManagerActivity extends Activity{
|
||||
private final int ADD_NEW_DIR_POSITION = 0;
|
||||
public static final String DIR_LIST = "dir_list";
|
||||
private DirectoriesAdapter myAdapter;
|
||||
private ListView myListView;
|
||||
private Intent myResultIntent;
|
||||
private String myDefaultDir = "/";
|
||||
private ArrayList<String> myDirList;
|
||||
private int myAddNewDirPosition = 0;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dir_manager);
|
||||
|
||||
myResultIntent = new Intent();
|
||||
myDirList = getIntent().getStringArrayListExtra(DIR_LIST);
|
||||
|
||||
System.out.println(ZLResource.resource("dialog").getResource("waitMessage").getResource("search").getValue());
|
||||
|
||||
setupActionButtons();
|
||||
myListView = (ListView) findViewById(R.id.directories);
|
||||
|
||||
myDirList.add(ADD_NEW_DIR_POSITION, "Add a new dir");
|
||||
|
||||
setupDirectoriesAdapter(myDirList);
|
||||
}
|
||||
|
||||
private void openFileChooser(int index, String dirName){
|
||||
FileChooserUtil.runDirectoryChooser(
|
||||
this,
|
||||
index,
|
||||
"",
|
||||
dirName,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
private void showMessage(String msg){
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void updateDirs(int index, Intent data){
|
||||
String path = FileChooserUtil.pathFromData(data);
|
||||
if(!myDirList.contains(path)){
|
||||
myDirList.remove(index);
|
||||
myDirList.add(index, path);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}else{
|
||||
showMessage("Cannot add the duplicate directory "+path);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewDir(Intent data){
|
||||
String path = FileChooserUtil.pathFromData(data);
|
||||
if(!myDirList.contains(path)){
|
||||
myDirList.add(FileChooserUtil.pathFromData(data));
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}else{
|
||||
showMessage("Cannot add the duplicate directory "+path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
System.out.println("DirectoriesManagerActivity::onActivityResult() "+requestCode);
|
||||
if(requestCode != ADD_NEW_DIR_POSITION){
|
||||
updateDirs(requestCode, data);
|
||||
}else{
|
||||
addNewDir(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDirectoriesAdapter(ArrayList<String> dirs){
|
||||
myAdapter = new DirectoriesAdapter(this, dirs);
|
||||
myListView.setAdapter(myAdapter);
|
||||
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
|
||||
String dirName = (String) parent.getItemAtPosition(position);
|
||||
if(position <= 0){
|
||||
dirName = myDefaultDir;
|
||||
}
|
||||
openFileChooser(position, dirName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupActionButtons(){
|
||||
final Button okButton = (Button) findViewById(R.id.button_ok);
|
||||
okButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
onBackPressed();
|
||||
myDirList.remove(0);
|
||||
myResultIntent.putStringArrayListExtra(DIR_LIST, myDirList);
|
||||
setResult(RESULT_OK, myResultIntent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
final Button cancelButton = (Button) findViewById(R.id.button_cancel);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
onBackPressed();
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class DirectoriesAdapter extends ArrayAdapter<String>{
|
||||
public DirectoriesAdapter(Context context, ArrayList<String> dirs){
|
||||
super(context, R.layout.dir_list, dirs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView (final int position, View convertView, ViewGroup parent){
|
||||
|
||||
final View view = LayoutInflater.from(getContext()).inflate(R.layout.dir_list, parent, false);
|
||||
|
||||
final String dirName = (String) getItem(position);
|
||||
|
||||
TextView title = (TextView) view.findViewById(R.id.title);
|
||||
title.setText(dirName);
|
||||
ImageView deleteButton = (ImageView) view.findViewById(R.id.delete);
|
||||
|
||||
if(position != ADD_NEW_DIR_POSITION){
|
||||
deleteButton.setVisibility(View.VISIBLE);
|
||||
deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
System.out.println("DELETE: "+dirName);
|
||||
view.animate()
|
||||
.setDuration(300)
|
||||
.alpha(0)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
myDirList.remove(position);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
view.setAlpha(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}else{
|
||||
deleteButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
|||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
System.out.println("PreferenceActivity::onActivityResult() "+requestCode);
|
||||
if (resultCode == RESULT_OK) {
|
||||
System.out.println("PreferenceActivity::onActivityResult() "+requestCode);
|
||||
myChooserCollection.update(requestCode, data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,12 @@ public class FileChooserCollection {
|
|||
|
||||
public void update(int index, Intent data) {
|
||||
try {
|
||||
myPreferences.get(index).setValue(FileChooserUtil.pathFromData(data));
|
||||
String path = FileChooserUtil.pathFromData(data);
|
||||
if(path != null){
|
||||
myPreferences.get(index).setValue(path);
|
||||
}else{
|
||||
myPreferences.get(index).setValue(FileChooserUtil.pathArrayFromData(data));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.geometerplus.android.fbreader.preferences.fileChooser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.preference.Preference;
|
||||
|
@ -29,7 +31,7 @@ import org.geometerplus.zlibrary.core.util.MiscUtil;
|
|||
import org.geometerplus.android.util.FileChooserUtil;
|
||||
|
||||
abstract class FileChooserPreference extends Preference {
|
||||
private final int myRegCode;
|
||||
protected final int myRegCode;
|
||||
private final ZLResource myResource;
|
||||
private final boolean myChooseWritableDirectoriesOnly;
|
||||
private final Runnable myOnValueSetAction;
|
||||
|
@ -47,16 +49,13 @@ abstract class FileChooserPreference extends Preference {
|
|||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
FileChooserUtil.runDirectoriesManager(
|
||||
(Activity)getContext(),
|
||||
myRegCode*2);
|
||||
/*FileChooserUtil.runDirectoryChooser(
|
||||
FileChooserUtil.runDirectoryChooser(
|
||||
(Activity)getContext(),
|
||||
myRegCode,
|
||||
myResource.getResource("chooserTitle").getValue(),
|
||||
getStringValue(),
|
||||
myChooseWritableDirectoriesOnly
|
||||
);*/
|
||||
);
|
||||
}
|
||||
|
||||
protected abstract String getStringValue();
|
||||
|
@ -73,5 +72,18 @@ abstract class FileChooserPreference extends Preference {
|
|||
}
|
||||
}
|
||||
|
||||
protected final void setValue(ArrayList<String> value) {
|
||||
if (value.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
setValueInternal(value);
|
||||
|
||||
if (myOnValueSetAction != null) {
|
||||
myOnValueSetAction.run();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void setValueInternal(String value);
|
||||
protected abstract void setValueInternal(ArrayList<String> value);
|
||||
}
|
||||
|
|
|
@ -21,9 +21,12 @@ package org.geometerplus.android.fbreader.preferences.fileChooser;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import org.geometerplus.android.util.FileChooserUtil;
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
|
@ -38,6 +41,22 @@ class FileChooserStringListPreference extends FileChooserPreference {
|
|||
setSummary(getStringValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
FileChooserUtil.runDirectoriesManager(
|
||||
(Activity)getContext(),
|
||||
myRegCode,
|
||||
getStringListValue()
|
||||
);
|
||||
}
|
||||
|
||||
private ArrayList<String> getStringListValue(){
|
||||
final List<String> values = myOption.getValue();
|
||||
ArrayList<String> resList = new ArrayList<String>();
|
||||
resList.addAll(values);
|
||||
return resList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStringValue() {
|
||||
final List<String> values = myOption.getValue();
|
||||
|
@ -46,10 +65,35 @@ class FileChooserStringListPreference extends FileChooserPreference {
|
|||
|
||||
@Override
|
||||
protected void setValueInternal(String value) {
|
||||
final List<String> currentValues = myOption.getValue();
|
||||
//System.out.println("FileChooserStringListPreference::setValueInternal() "+value);
|
||||
List<String> currentValues = myOption.getValue();
|
||||
//System.out.println("1 FileChooserStringListPreference::setValueInternal() currentValue "+currentValues);
|
||||
if (currentValues.size() != 1 || !currentValues.get(0).equals(value)) {
|
||||
myOption.setValue(Collections.singletonList(value));
|
||||
setSummary(value);
|
||||
}
|
||||
/*boolean found = false;
|
||||
for(int i = 0; i < currentValues.size();i++){
|
||||
if(currentValues.get(i).equals(value)){
|
||||
currentValues.remove(i);
|
||||
currentValues.add(i, value);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if(!found){
|
||||
currentValues.add(value);
|
||||
}
|
||||
myOption.setValue(currentValues);
|
||||
setSummary(value);
|
||||
System.out.println("2 FileChooserStringListPreference::setValueInternal() currentValue "+currentValues);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValueInternal(ArrayList<String> value) {
|
||||
System.out.println("FileChooserStringListPreference::setValueInternal() "+value);
|
||||
if(value.size() > 0){
|
||||
myOption.setValue(value);
|
||||
setSummary(value.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.geometerplus.android.fbreader.preferences.fileChooser;
|
||||
|
||||
import android.content.Context;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
@ -47,4 +48,11 @@ class FileChooserStringPreference extends FileChooserPreference {
|
|||
setSummary(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValueInternal(ArrayList<String> value) {
|
||||
if(value.size() > 0){
|
||||
setValueInternal(value.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.geometerplus.android.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -37,8 +38,14 @@ public abstract class FileChooserUtil {
|
|||
private FileChooserUtil() {
|
||||
}
|
||||
|
||||
public static void runDirectoriesManager(Activity activity, int requestCode){
|
||||
public static void runDirectoriesManager(
|
||||
Activity activity,
|
||||
int requestCode,
|
||||
ArrayList<String> initinalValue
|
||||
) {
|
||||
final Intent intent = new Intent(activity, DirectoriesManagerActivity.class);
|
||||
System.out.println(">>>>>>>>>>>>>>> "+initinalValue);
|
||||
intent.putStringArrayListExtra(DirectoriesManagerActivity.DIR_LIST, initinalValue);
|
||||
activity.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
|
||||
|
@ -68,6 +75,10 @@ public abstract class FileChooserUtil {
|
|||
return data.getStringExtra(FileChooserActivity._FolderPath);
|
||||
}
|
||||
|
||||
public static ArrayList<String> pathArrayFromData(Intent data) {
|
||||
return data.getStringArrayListExtra(DirectoriesManagerActivity.DIR_LIST);
|
||||
}
|
||||
|
||||
private static HashMap<String,String> textResources(String title) {
|
||||
final HashMap<String,String> map = new HashMap<String,String>();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue