rescan items after copy/move too
This commit is contained in:
parent
4dff81bc4a
commit
f7d9fcedd3
|
@ -17,6 +17,7 @@ public class CopyTask extends AsyncTask<Pair<List<File>, File>, Void, Boolean> {
|
|||
private static final String TAG = CopyTask.class.getSimpleName();
|
||||
|
||||
private static WeakReference<CopyListener> mListener;
|
||||
private static File destinationDir;
|
||||
|
||||
public CopyTask(CopyListener listener) {
|
||||
mListener = new WeakReference<>(listener);
|
||||
|
@ -28,7 +29,7 @@ public class CopyTask extends AsyncTask<Pair<List<File>, File>, Void, Boolean> {
|
|||
final List<File> files = pair.first;
|
||||
for (File file : files) {
|
||||
try {
|
||||
final File destinationDir = new File(pair.second, file.getName());
|
||||
destinationDir = new File(pair.second, file.getName());
|
||||
copy(file, destinationDir);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
|
@ -74,14 +75,14 @@ public class CopyTask extends AsyncTask<Pair<List<File>, File>, Void, Boolean> {
|
|||
return;
|
||||
|
||||
if (success) {
|
||||
listener.copySucceeded();
|
||||
listener.copySucceeded(destinationDir);
|
||||
} else {
|
||||
listener.copyFailed();
|
||||
}
|
||||
}
|
||||
|
||||
public interface CopyListener {
|
||||
void copySucceeded();
|
||||
void copySucceeded(File destinationDir);
|
||||
|
||||
void copyFailed();
|
||||
}
|
||||
|
|
|
@ -414,7 +414,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||
}
|
||||
|
||||
if (currFile.renameTo(newFile)) {
|
||||
rescanFolder(newFile);
|
||||
rescanItem(newFile);
|
||||
MediaScannerConnection.scanFile(getContext(), new String[]{currFile.getAbsolutePath(), newFile.getAbsolutePath()}, null, null);
|
||||
alertDialog.dismiss();
|
||||
fillItems();
|
||||
|
@ -478,7 +478,9 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||
new CopyTask(ItemsFragment.this).execute(pair);
|
||||
} else {
|
||||
for (File f : itemsToCopy) {
|
||||
f.renameTo(new File(destinationDir, f.getName()));
|
||||
final File destination = new File(destinationDir, f.getName());
|
||||
f.renameTo(destination);
|
||||
rescanItem(destination);
|
||||
}
|
||||
|
||||
mCopyDialog.dismiss();
|
||||
|
@ -588,10 +590,10 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||
mToBeDeleted.clear();
|
||||
}
|
||||
|
||||
private void rescanFolder(File item) {
|
||||
private void rescanItem(File item) {
|
||||
if (item.isDirectory()) {
|
||||
for (File child : item.listFiles()) {
|
||||
rescanFolder(child);
|
||||
rescanItem(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,7 +626,8 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void copySucceeded() {
|
||||
public void copySucceeded(File file) {
|
||||
rescanItem(file);
|
||||
mCopyDialog.dismiss();
|
||||
fillItems();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue