add breadcrumbs to Destination picker dialog too at Copy
This commit is contained in:
parent
54421678c2
commit
7dcd3ab947
|
@ -10,6 +10,8 @@ import android.view.WindowManager;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.filemanager.models.FileDirItem;
|
||||||
|
|
||||||
public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private int mDeviceWidth;
|
private int mDeviceWidth;
|
||||||
|
@ -96,17 +98,33 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
||||||
setMeasuredDimension(parentWidth, calculatedHeight);
|
setMeasuredDimension(parentWidth, calculatedHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInitialBreadcrumb() {
|
public void setInitialBreadcrumb(String fullPath) {
|
||||||
addBreadcrumb(getResources().getString(R.string.initial_breadcrumb));
|
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);
|
final View view = mInflater.inflate(R.layout.breadcrumb_item, null, false);
|
||||||
view.setTag(getChildCount());
|
|
||||||
final TextView textView = (TextView) view.findViewById(R.id.breadcrumb_text);
|
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);
|
addView(view);
|
||||||
view.setOnClickListener(this);
|
view.setOnClickListener(this);
|
||||||
|
|
||||||
|
view.setTag(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBreadcrumb() {
|
public void removeBreadcrumb() {
|
||||||
|
@ -115,8 +133,13 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
final int cnt = getChildCount();
|
||||||
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
if (getChildAt(i) != null && getChildAt(i).equals(v)) {
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.breadcrumbClicked((Integer) v.getTag());
|
mListener.breadcrumbClicked(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
|
||||||
private void initRootFileManager() {
|
private void initRootFileManager() {
|
||||||
final String path = Environment.getExternalStorageDirectory().toString();
|
final String path = Environment.getExternalStorageDirectory().toString();
|
||||||
openPath(path);
|
openPath(path);
|
||||||
mBreadcrumbs.setInitialBreadcrumb();
|
mBreadcrumbs.setInitialBreadcrumb(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openPath(String path) {
|
private void openPath(String path) {
|
||||||
|
@ -111,7 +111,7 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
|
||||||
@Override
|
@Override
|
||||||
public void itemClicked(FileDirItem item) {
|
public void itemClicked(FileDirItem item) {
|
||||||
openPath(item.getPath());
|
openPath(item.getPath());
|
||||||
mBreadcrumbs.addBreadcrumb(" -> " + item.getName());
|
mBreadcrumbs.addBreadcrumb(item, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,6 +29,7 @@ import android.widget.ListView;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.filemanager.Breadcrumbs;
|
||||||
import com.simplemobiletools.filemanager.Config;
|
import com.simplemobiletools.filemanager.Config;
|
||||||
import com.simplemobiletools.filemanager.Constants;
|
import com.simplemobiletools.filemanager.Constants;
|
||||||
import com.simplemobiletools.filemanager.R;
|
import com.simplemobiletools.filemanager.R;
|
||||||
|
@ -125,6 +126,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
final List<FileDirItem> items = new ArrayList<>();
|
final List<FileDirItem> items = new ArrayList<>();
|
||||||
final File base = new File(path);
|
final File base = new File(path);
|
||||||
File[] files = base.listFiles();
|
File[] files = base.listFiles();
|
||||||
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
final String curPath = file.getAbsolutePath();
|
final String curPath = file.getAbsolutePath();
|
||||||
final String curName = Utils.getFilename(curPath);
|
final String curName = Utils.getFilename(curPath);
|
||||||
|
@ -139,10 +141,14 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
|
|
||||||
items.add(new FileDirItem(curPath, curName, file.isDirectory(), children, size));
|
items.add(new FileDirItem(curPath, curName, file.isDirectory(), children, size));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getChildren(File file) {
|
private int getChildren(File file) {
|
||||||
|
if (file.listFiles() == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
if (mShowHidden) {
|
if (mShowHidden) {
|
||||||
return file.listFiles().length;
|
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() {
|
mCopyDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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()) {
|
if (!destinationDir.exists()) {
|
||||||
Utils.showToast(getContext(), R.string.invalid_destination);
|
Utils.showToast(getContext(), R.string.invalid_destination);
|
||||||
return;
|
return;
|
||||||
|
@ -481,6 +493,20 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
final ItemsAdapter adapter = new ItemsAdapter(getContext(), items);
|
final ItemsAdapter adapter = new ItemsAdapter(getContext(), items);
|
||||||
pickerList.setAdapter(adapter);
|
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());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(getResources().getString(R.string.select_destination));
|
builder.setTitle(getResources().getString(R.string.select_destination));
|
||||||
builder.setView(pickerView);
|
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() {
|
pickerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final FileDirItem item = items.get(position);
|
final FileDirItem item = items.get(position);
|
||||||
if (item.getIsDirectory()) {
|
if (item.getIsDirectory()) {
|
||||||
|
breadcrumbs.addBreadcrumb(item, true);
|
||||||
mCopyDestinationPath = item.getPath();
|
mCopyDestinationPath = item.getPath();
|
||||||
final List<FileDirItem> newItems = getItems(mCopyDestinationPath);
|
final List<FileDirItem> newItems = getItems(mCopyDestinationPath);
|
||||||
|
Collections.sort(newItems);
|
||||||
if (containsDirectory(newItems)) {
|
if (containsDirectory(newItems)) {
|
||||||
adapter.updateItems(newItems);
|
adapter.updateItems(newItems);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<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: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
|
<ListView
|
||||||
android:id="@+id/directory_picker_list"
|
android:id="@+id/directory_picker_list"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/directory_picker_breadcrumbs"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<string name="destination">Destination</string>
|
<string name="destination">Destination</string>
|
||||||
<string name="select_destination">Select destination</string>
|
<string name="select_destination">Select destination</string>
|
||||||
<string name="invalid_destination">Could not write to the selected 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="copy_failed">Could not copy the files</string>
|
||||||
<string name="copying">Copying</string>
|
<string name="copying">Copying</string>
|
||||||
<string name="initial_breadcrumb">home</string>
|
<string name="initial_breadcrumb">home</string>
|
||||||
|
|
Loading…
Reference in New Issue