rescan directories too recursively

This commit is contained in:
tibbi 2016-08-24 23:51:48 +02:00
parent 3a515e5844
commit 9a75c3ae8c

View file

@ -28,11 +28,11 @@ import android.widget.GridView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.target.SimpleTarget;
import com.simplemobiletools.gallery.dialogs.ChangeSorting;
import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.Constants;
import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.Utils; import com.simplemobiletools.gallery.Utils;
import com.simplemobiletools.gallery.adapters.MediaAdapter; import com.simplemobiletools.gallery.adapters.MediaAdapter;
import com.simplemobiletools.gallery.dialogs.ChangeSorting;
import com.simplemobiletools.gallery.models.Medium; import com.simplemobiletools.gallery.models.Medium;
import java.io.File; import java.io.File;
@ -144,18 +144,18 @@ public class MediaActivity extends SimpleActivity
} }
} }
private void rescanDirectory() { private void rescanDirectory(File dir) {
final File file = new File(mPath); final File[] files = dir.listFiles();
if (file.isDirectory()) {
final File[] files = file.listFiles();
final String[] paths = new String[files.length]; final String[] paths = new String[files.length];
final int cnt = file.listFiles().length; final int cnt = dir.listFiles().length;
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
paths[i] = files[i].getPath(); paths[i] = files[i].getPath();
if (files[i].isDirectory()) {
rescanDirectory(files[i]);
}
} }
MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null); MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null);
} }
}
private void showSortingDialog() { private void showSortingDialog() {
new ChangeSorting(this, false); new ChangeSorting(this, false);
@ -442,7 +442,10 @@ public class MediaActivity extends SimpleActivity
@Override @Override
public void onRefresh() { public void onRefresh() {
rescanDirectory(); final File dir = new File(mPath);
if (dir.isDirectory()) {
rescanDirectory(dir);
}
initializeGallery(); initializeGallery();
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
} }