rescan items after copy/move too

This commit is contained in:
tibbi 2016-10-09 16:51:43 +02:00
parent 4dff81bc4a
commit f7d9fcedd3
2 changed files with 12 additions and 8 deletions

View File

@ -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();
}

View File

@ -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();
}