|
1 | 1 | package com.simplemobiletools.filemanager.fragments; |
2 | 2 |
|
3 | 3 | import android.content.ActivityNotFoundException; |
4 | | -import android.content.DialogInterface; |
5 | 4 | import android.content.Intent; |
6 | 5 | import android.content.res.Resources; |
7 | 6 | import android.graphics.Color; |
|
12 | 11 | import android.support.annotation.Nullable; |
13 | 12 | import android.support.design.widget.CoordinatorLayout; |
14 | 13 | import android.support.design.widget.Snackbar; |
15 | | -import android.support.v4.util.Pair; |
16 | 14 | import android.support.v4.widget.SwipeRefreshLayout; |
17 | 15 | import android.support.v7.app.AlertDialog; |
18 | 16 | import android.util.SparseBooleanArray; |
|
26 | 24 | import android.webkit.MimeTypeMap; |
27 | 25 | import android.widget.AdapterView; |
28 | 26 | import android.widget.ListView; |
29 | | -import android.widget.RadioGroup; |
30 | 27 | import android.widget.TextView; |
31 | 28 |
|
32 | 29 | import com.simplemobiletools.filemanager.Config; |
|
35 | 32 | import com.simplemobiletools.filemanager.Utils; |
36 | 33 | import com.simplemobiletools.filemanager.adapters.ItemsAdapter; |
37 | 34 | import com.simplemobiletools.filemanager.asynctasks.CopyTask; |
| 35 | +import com.simplemobiletools.filemanager.dialogs.CopyDialog; |
38 | 36 | import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog; |
39 | 37 | import com.simplemobiletools.filemanager.dialogs.PropertiesDialog; |
40 | 38 | import com.simplemobiletools.filemanager.dialogs.RenameItemDialog; |
41 | | -import com.simplemobiletools.filepicker.dialogs.FilePickerDialog; |
42 | 39 | import com.simplemobiletools.filepicker.models.FileDirItem; |
43 | 40 |
|
44 | 41 | import java.io.File; |
@@ -370,65 +367,20 @@ private void displayCopyDialog() { |
370 | 367 | if (itemIndexes.isEmpty()) |
371 | 368 | return; |
372 | 369 |
|
373 | | - final View copyView = getActivity().getLayoutInflater().inflate(R.layout.copy_item, null); |
374 | | - |
375 | | - final TextView source = (TextView) copyView.findViewById(R.id.source); |
376 | | - source.setText(mPath + "/"); |
377 | | - |
378 | | - mDestinationView = (TextView) copyView.findViewById(R.id.destination); |
379 | | - mDestinationView.setOnClickListener(destinationPicker); |
380 | | - |
381 | | - final int copyString = (itemIndexes.size() == 1) ? R.string.copy_item : R.string.copy_items; |
382 | | - final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); |
383 | | - builder.setTitle(getResources().getString(copyString)); |
384 | | - builder.setView(copyView); |
385 | | - builder.setPositiveButton(R.string.ok, null); |
386 | | - builder.setNegativeButton(R.string.cancel, null); |
| 370 | + final List<File> itemsToCopy = new ArrayList<>(itemIndexes.size()); |
| 371 | + for (Integer i : itemIndexes) { |
| 372 | + FileDirItem item = mItems.get(i); |
| 373 | + itemsToCopy.add(new File(item.getPath())); |
| 374 | + } |
387 | 375 |
|
388 | | - mCopyDialog = builder.create(); |
389 | | - mCopyDialog.show(); |
390 | | - mCopyDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { |
| 376 | + new CopyDialog(getActivity(), itemsToCopy, mPath, this, new CopyDialog.OnCopyListener() { |
391 | 377 | @Override |
392 | | - public void onClick(View v) { |
393 | | - final String destinationPath = mDestinationView.getText().toString().trim(); |
394 | | - if (destinationPath.equals(getResources().getString(R.string.select_destination))) { |
395 | | - Utils.showToast(getContext(), R.string.please_select_destination); |
396 | | - return; |
397 | | - } |
398 | | - |
399 | | - final File destinationDir = new File(destinationPath); |
400 | | - if (!destinationDir.exists()) { |
401 | | - Utils.showToast(getContext(), R.string.invalid_destination); |
402 | | - return; |
403 | | - } |
404 | | - |
405 | | - final List<File> itemsToCopy = new ArrayList<>(itemIndexes.size()); |
406 | | - for (Integer i : itemIndexes) { |
407 | | - FileDirItem item = mItems.get(i); |
408 | | - itemsToCopy.add(new File(item.getPath())); |
409 | | - } |
410 | | - |
411 | | - final RadioGroup radio = (RadioGroup) copyView.findViewById(R.id.dialog_radio_group); |
412 | | - if (radio.getCheckedRadioButtonId() == R.id.dialog_radio_copy) { |
413 | | - Utils.showToast(getContext(), R.string.copying); |
414 | | - final Pair<List<File>, File> pair = new Pair<>(itemsToCopy, destinationDir); |
415 | | - new CopyTask(ItemsFragment.this).execute(pair); |
416 | | - } else { |
417 | | - for (File f : itemsToCopy) { |
418 | | - final File destination = new File(destinationDir, f.getName()); |
419 | | - f.renameTo(destination); |
420 | | - rescanItem(destination); |
421 | | - } |
422 | | - |
423 | | - mCopyDialog.dismiss(); |
424 | | - fillItems(); |
425 | | - } |
| 378 | + public void onSuccess() { |
| 379 | + fillItems(); |
426 | 380 | } |
427 | | - }); |
428 | 381 |
|
429 | | - mCopyDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
430 | 382 | @Override |
431 | | - public void onDismiss(DialogInterface dialog) { |
| 383 | + public void onCancel() { |
432 | 384 | mCopyDestinationPath = mPath; |
433 | 385 | } |
434 | 386 | }); |
@@ -482,26 +434,6 @@ private void notifyDeletion(int cnt) { |
482 | 434 | fillItems(); |
483 | 435 | } |
484 | 436 |
|
485 | | - private View.OnClickListener destinationPicker = new View.OnClickListener() { |
486 | | - @Override |
487 | | - public void onClick(final View view) { |
488 | | - final boolean showHiddenItems = mConfig.getShowHidden(); |
489 | | - final boolean showFullPath = mConfig.getShowFullPath(); |
490 | | - new FilePickerDialog(getContext(), mCopyDestinationPath, false, showHiddenItems, showFullPath, new FilePickerDialog.OnFilePickerListener() { |
491 | | - @Override |
492 | | - public void onFail(FilePickerDialog.FilePickerResult pickFolderResult) { |
493 | | - |
494 | | - } |
495 | | - |
496 | | - @Override |
497 | | - public void onSuccess(String path) { |
498 | | - mCopyDestinationPath = path; |
499 | | - mDestinationView.setText(path); |
500 | | - } |
501 | | - }); |
502 | | - } |
503 | | - }; |
504 | | - |
505 | 437 | @Override |
506 | 438 | public boolean onTouch(View v, MotionEvent event) { |
507 | 439 | if (mSnackbar != null && mSnackbar.isShown()) { |
@@ -567,7 +499,6 @@ public void onDestroyActionMode(ActionMode mode) { |
567 | 499 | @Override |
568 | 500 | public void copySucceeded(File file) { |
569 | 501 | rescanItem(file); |
570 | | - mCopyDialog.dismiss(); |
571 | 502 | fillItems(); |
572 | 503 | } |
573 | 504 |
|
|
0 commit comments