diff --git a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java index 337d97a5..5d9845f1 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java @@ -90,6 +90,12 @@ public class ItemsAdapter extends BaseAdapter { return 0; } + public void updateItems(List newItems) { + mItems.clear(); + mItems.addAll(newItems); + notifyDataSetChanged(); + } + static class ViewHolder { @BindView(R.id.item_name) TextView name; @BindView(R.id.item_icon) ImageView icon; diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index 8d05323f..51965f40 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -1,6 +1,7 @@ package com.simplemobiletools.filemanager.fragments; import android.content.ActivityNotFoundException; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.graphics.Color; @@ -56,6 +57,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment private ItemInteractionListener mListener; private List mToBeDeleted; private String mPath; + private String mCopyDestinationPath; private Snackbar mSnackbar; private boolean mShowHidden; @@ -96,7 +98,8 @@ public class ItemsFragment extends android.support.v4.app.Fragment private void fillItems() { mPath = getArguments().getString(Constants.PATH); - final List newItems = getItems(); + mCopyDestinationPath = mPath; + final List newItems = getItems(mPath); Collections.sort(newItems); if (mItems != null && newItems.toString().equals(mItems.toString())) { return; @@ -115,9 +118,9 @@ public class ItemsFragment extends android.support.v4.app.Fragment mListener = listener; } - private List getItems() { + private List getItems(String path) { final List items = new ArrayList<>(); - final File base = new File(mPath); + final File base = new File(path); File[] files = base.listFiles(); for (File file : files) { final String curPath = file.getAbsolutePath(); @@ -390,7 +393,36 @@ public class ItemsFragment extends android.support.v4.app.Fragment alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + final File destinationDir = new File(destination.getText().toString().trim()); + if (!destinationDir.exists()) { + Utils.showToast(getContext(), R.string.invalid_destination); + return; + } + List itemsToCopy = new ArrayList<>(itemIndexes.size()); + for (Integer i : itemIndexes) { + FileDirItem item = mItems.get(i); + itemsToCopy.add(new File(item.getPath())); + } + + final RadioGroup radio = (RadioGroup) copyView.findViewById(R.id.dialog_radio_group); + if (radio.getCheckedRadioButtonId() == R.id.dialog_radio_copy) { + + } else { + for (File f : itemsToCopy) { + f.renameTo(new File(destinationDir, f.getName())); + } + + alertDialog.dismiss(); + fillItems(); + } + } + }); + + alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + mCopyDestinationPath = mPath; } }); } @@ -436,20 +468,13 @@ public class ItemsFragment extends android.support.v4.app.Fragment private View.OnClickListener destinationPicker = new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(final View destinationView) { final View pickerView = getActivity().getLayoutInflater().inflate(R.layout.directory_picker, null); final ListView pickerList = (ListView) pickerView.findViewById(R.id.directory_picker_list); - final ItemsAdapter adapter = new ItemsAdapter(getContext(), mItems); + final List items = getItems(mCopyDestinationPath); + Collections.sort(items); + final ItemsAdapter adapter = new ItemsAdapter(getContext(), items); pickerList.setAdapter(adapter); - pickerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - final FileDirItem item = mItems.get(position); - if (item.getIsDirectory()) { - - } - } - }); final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(getResources().getString(R.string.select_destination)); @@ -462,12 +487,39 @@ public class ItemsFragment extends android.support.v4.app.Fragment alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + alertDialog.dismiss(); + ((TextView) destinationView).setText(mCopyDestinationPath); + } + }); + 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()) { + mCopyDestinationPath = item.getPath(); + final List newItems = getItems(mCopyDestinationPath); + if (containsDirectory(newItems)) { + adapter.updateItems(newItems); + } else { + alertDialog.dismiss(); + ((TextView) destinationView).setText(mCopyDestinationPath); + } + } } }); } }; + private boolean containsDirectory(List items) { + for (FileDirItem item : items) { + if (item.getIsDirectory()) { + return true; + } + } + return false; + } + @Override public boolean onTouch(View v, MotionEvent event) { if (mSnackbar != null && mSnackbar.isShown()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 562f21c3..7c82ddd4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,6 +20,7 @@ Source Destination Select destination + Could not write to the selected destination 1 item deleted