diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5f36f8e62..3143652b2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,7 +3,7 @@ package="com.simplemobiletools.gallery" xmlns:android="http://schemas.android.com/apk/res/android"> - + photos; private int selectedItemsCnt; private GridView gridView; + private String path; + private PhotosAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -34,8 +39,8 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI setContentView(R.layout.activity_photos); photos = new ArrayList<>(); - final String path = getIntent().getStringExtra(Constants.DIRECTORY); - final PhotosAdapter adapter = new PhotosAdapter(this, getPhotos(path)); + path = getIntent().getStringExtra(Constants.DIRECTORY); + adapter = new PhotosAdapter(this, getPhotos()); gridView = (GridView) findViewById(R.id.photos_grid); gridView.setAdapter(adapter); gridView.setOnItemClickListener(this); @@ -45,7 +50,7 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI setTitle(dirName); } - private List getPhotos(final String path) { + private List getPhotos() { photos.clear(); final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final String where = MediaStore.Images.Media.DATA + " like ? "; @@ -68,6 +73,19 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI return photos; } + private void deleteSelectedItems() { + final SparseBooleanArray items = gridView.getCheckedItemPositions(); + int cnt = items.size(); + for (int i = 0; i < cnt; i++) { + final int id = items.keyAt(i); + new File(photos.get(id)).delete(); + } + + MediaScannerConnection.scanFile(this, new String[]{path}, null, null); + adapter.updateItems(getPhotos()); + adapter.notifyDataSetChanged(); + } + @Override public void onItemClick(AdapterView parent, View view, int position, long id) { final Intent intent = new Intent(this, ViewPagerActivity.class); @@ -102,6 +120,7 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.cab_remove: + deleteSelectedItems(); mode.finish(); return true; default: diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java index 9e1dab00b..74c930845 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java @@ -55,6 +55,12 @@ public class PhotosAdapter extends BaseAdapter { return 0; } + public void updateItems(List newPhotos) { + photos.clear(); + photos.addAll(newPhotos); + notifyDataSetChanged(); + } + static class ViewHolder { ImageView photoThumbnail;