add breadcrumbs to Destination picker dialog too at Copy

This commit is contained in:
tibbi 2016-07-17 22:08:04 +02:00
parent 54421678c2
commit 7dcd3ab947
5 changed files with 98 additions and 23 deletions

View File

@ -10,6 +10,8 @@ import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.simplemobiletools.filemanager.models.FileDirItem;
public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
private LayoutInflater mInflater;
private int mDeviceWidth;
@ -96,17 +98,33 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
setMeasuredDimension(parentWidth, calculatedHeight);
}
public void setInitialBreadcrumb() {
addBreadcrumb(getResources().getString(R.string.initial_breadcrumb));
public void setInitialBreadcrumb(String fullPath) {
removeAllViewsInLayout();
final String[] dirs = fullPath.split("/");
String currPath = "";
for (int i = 0; i < dirs.length; i++) {
final String dir = dirs[i];
currPath += dir + "/";
if (dir.isEmpty())
continue;
final FileDirItem item = new FileDirItem(currPath, dir, true, 0, 0);
addBreadcrumb(item, i > 1);
}
}
public void addBreadcrumb(String text) {
public void addBreadcrumb(FileDirItem item, boolean addPrefix) {
final View view = mInflater.inflate(R.layout.breadcrumb_item, null, false);
view.setTag(getChildCount());
final TextView textView = (TextView) view.findViewById(R.id.breadcrumb_text);
textView.setText(text);
String textToAdd = item.getName();
if (addPrefix)
textToAdd = " -> " + textToAdd;
textView.setText(textToAdd);
addView(view);
view.setOnClickListener(this);
view.setTag(item);
}
public void removeBreadcrumb() {
@ -115,8 +133,13 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.breadcrumbClicked((Integer) v.getTag());
final int cnt = getChildCount();
for (int i = 0; i < cnt; i++) {
if (getChildAt(i) != null && getChildAt(i).equals(v)) {
if (mListener != null) {
mListener.breadcrumbClicked(i);
}
}
}
}

View File

@ -52,7 +52,7 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
private void initRootFileManager() {
final String path = Environment.getExternalStorageDirectory().toString();
openPath(path);
mBreadcrumbs.setInitialBreadcrumb();
mBreadcrumbs.setInitialBreadcrumb(path);
}
private void openPath(String path) {
@ -111,7 +111,7 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
@Override
public void itemClicked(FileDirItem item) {
openPath(item.getPath());
mBreadcrumbs.addBreadcrumb(" -> " + item.getName());
mBreadcrumbs.addBreadcrumb(item, true);
}
@Override

View File

@ -29,6 +29,7 @@ import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.simplemobiletools.filemanager.Breadcrumbs;
import com.simplemobiletools.filemanager.Config;
import com.simplemobiletools.filemanager.Constants;
import com.simplemobiletools.filemanager.R;
@ -125,24 +126,29 @@ public class ItemsFragment extends android.support.v4.app.Fragment
final List<FileDirItem> items = new ArrayList<>();
final File base = new File(path);
File[] files = base.listFiles();
for (File file : files) {
final String curPath = file.getAbsolutePath();
final String curName = Utils.getFilename(curPath);
if (!mShowHidden && curName.startsWith("."))
continue;
if (files != null) {
for (File file : files) {
final String curPath = file.getAbsolutePath();
final String curName = Utils.getFilename(curPath);
if (!mShowHidden && curName.startsWith("."))
continue;
if (mToBeDeleted.contains(curPath))
continue;
if (mToBeDeleted.contains(curPath))
continue;
int children = getChildren(file);
long size = file.length();
int children = getChildren(file);
long size = file.length();
items.add(new FileDirItem(curPath, curName, file.isDirectory(), children, size));
items.add(new FileDirItem(curPath, curName, file.isDirectory(), children, size));
}
}
return items;
}
private int getChildren(File file) {
if (file.listFiles() == null)
return 0;
if (file.isDirectory()) {
if (mShowHidden) {
return file.listFiles().length;
@ -396,7 +402,13 @@ public class ItemsFragment extends android.support.v4.app.Fragment
mCopyDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final File destinationDir = new File(destination.getText().toString().trim());
final String destinationPath = destination.getText().toString().trim();
if (destinationPath.equals(getResources().getString(R.string.select_destination))) {
Utils.showToast(getContext(), R.string.please_select_destination);
return;
}
final File destinationDir = new File(destinationPath);
if (!destinationDir.exists()) {
Utils.showToast(getContext(), R.string.invalid_destination);
return;
@ -481,6 +493,20 @@ public class ItemsFragment extends android.support.v4.app.Fragment
final ItemsAdapter adapter = new ItemsAdapter(getContext(), items);
pickerList.setAdapter(adapter);
final Breadcrumbs breadcrumbs = (Breadcrumbs) pickerView.findViewById(R.id.directory_picker_breadcrumbs);
breadcrumbs.setInitialBreadcrumb(mCopyDestinationPath);
breadcrumbs.setListener(new Breadcrumbs.BreadcrumbsListener() {
@Override
public void breadcrumbClicked(int id) {
final FileDirItem item = (FileDirItem) breadcrumbs.getChildAt(id).getTag();
mCopyDestinationPath = item.getPath();
breadcrumbs.setInitialBreadcrumb(mCopyDestinationPath);
final List<FileDirItem> newItems = getItems(mCopyDestinationPath);
Collections.sort(newItems);
adapter.updateItems(newItems);
}
});
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getResources().getString(R.string.select_destination));
builder.setView(pickerView);
@ -497,13 +523,22 @@ public class ItemsFragment extends android.support.v4.app.Fragment
}
});
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mCopyDestinationPath = ((TextView) destinationView).getText().toString().trim();
}
});
pickerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final FileDirItem item = items.get(position);
if (item.getIsDirectory()) {
breadcrumbs.addBreadcrumb(item, true);
mCopyDestinationPath = item.getPath();
final List<FileDirItem> newItems = getItems(mCopyDestinationPath);
Collections.sort(newItems);
if (containsDirectory(newItems)) {
adapter.updateItems(newItems);
} else {

View File

@ -1,6 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView
android:id="@+id/directory_picker_list"
<LinearLayout
android:id="@+id/directory_picker_holder"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:orientation="vertical">
<com.simplemobiletools.filemanager.Breadcrumbs
android:id="@+id/directory_picker_breadcrumbs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin"/>
<ListView
android:id="@+id/directory_picker_list"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/directory_picker_breadcrumbs"/>
</LinearLayout>

View File

@ -21,6 +21,7 @@
<string name="destination">Destination</string>
<string name="select_destination">Select destination</string>
<string name="invalid_destination">Could not write to the selected destination</string>
<string name="please_select_destination">Please select a destination</string>
<string name="copy_failed">Could not copy the files</string>
<string name="copying">Copying</string>
<string name="initial_breadcrumb">home</string>