mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 12:38:00 +01:00
reload the gallery after deleting the files
This commit is contained in:
parent
07cbc6bedb
commit
9e219d7410
2 changed files with 20 additions and 10 deletions
|
@ -38,9 +38,9 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_photos);
|
setContentView(R.layout.activity_photos);
|
||||||
|
|
||||||
photos = new ArrayList<>();
|
|
||||||
path = getIntent().getStringExtra(Constants.DIRECTORY);
|
path = getIntent().getStringExtra(Constants.DIRECTORY);
|
||||||
adapter = new PhotosAdapter(this, getPhotos());
|
photos = getPhotos();
|
||||||
|
adapter = new PhotosAdapter(this, photos);
|
||||||
gridView = (GridView) findViewById(R.id.photos_grid);
|
gridView = (GridView) findViewById(R.id.photos_grid);
|
||||||
gridView.setAdapter(adapter);
|
gridView.setAdapter(adapter);
|
||||||
gridView.setOnItemClickListener(this);
|
gridView.setOnItemClickListener(this);
|
||||||
|
@ -51,7 +51,7 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getPhotos() {
|
private List<String> getPhotos() {
|
||||||
photos.clear();
|
List<String> myPhotos = new ArrayList<>();
|
||||||
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
final String where = MediaStore.Images.Media.DATA + " like ? ";
|
final String where = MediaStore.Images.Media.DATA + " like ? ";
|
||||||
final String[] args = new String[]{path + "%"};
|
final String[] args = new String[]{path + "%"};
|
||||||
|
@ -65,12 +65,12 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
|
||||||
do {
|
do {
|
||||||
final String curPath = cursor.getString(pathIndex);
|
final String curPath = cursor.getString(pathIndex);
|
||||||
if (curPath.matches(pattern)) {
|
if (curPath.matches(pattern)) {
|
||||||
photos.add(cursor.getString(pathIndex));
|
myPhotos.add(cursor.getString(pathIndex));
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
return photos;
|
return myPhotos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteSelectedItems() {
|
private void deleteSelectedItems() {
|
||||||
|
@ -78,12 +78,22 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
|
||||||
int cnt = items.size();
|
int cnt = items.size();
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
final int id = items.keyAt(i);
|
final int id = items.keyAt(i);
|
||||||
new File(photos.get(id)).delete();
|
final File file = new File(photos.get(id));
|
||||||
|
file.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaScannerConnection.scanFile(this, new String[]{path}, null, null);
|
MediaScannerConnection.scanFile(this, new String[]{path}, null, new MediaScannerConnection.OnScanCompletedListener() {
|
||||||
adapter.updateItems(getPhotos());
|
@Override
|
||||||
adapter.notifyDataSetChanged();
|
public void onScanCompleted(final String path, final Uri uri) {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
photos = getPhotos();
|
||||||
|
adapter.updateItems(photos);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class PhotosAdapter extends BaseAdapter {
|
||||||
holder = (ViewHolder) view.getTag();
|
holder = (ViewHolder) view.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = photos.get(position);
|
final String path = photos.get(position);
|
||||||
Glide.with(context).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail);
|
Glide.with(context).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
Loading…
Reference in a new issue