From 55d693fb97b9c74ea3fefe7a09ef3994aca46911 Mon Sep 17 00:00:00 2001 From: Lukas Koller Date: Wed, 21 Mar 2018 14:48:06 +0100 Subject: [PATCH] - deleting an image in the ItemActivity no longer takes the user back to AlbumActivity (#132) --- .../cameraroll/data/provider/Provider.java | 2 +- .../us/koller/cameraroll/ui/AlbumActivity.java | 8 +++++++- .../us/koller/cameraroll/ui/ItemActivity.java | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java b/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java index f9077d26..82fe6182 100644 --- a/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java +++ b/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java @@ -153,7 +153,7 @@ public static boolean isAlbumPinned(String albumPath, ArrayList pinnedPa return true; } else { for (int i = 0; i < pinnedPaths.size(); i++) { - if (albumPath.contains(pinnedPaths.get(i))) { + if (albumPath.equals(pinnedPaths.get(i))) { return true; } } diff --git a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java index aff47e89..cb90aca8 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java @@ -1161,6 +1161,7 @@ public void onAlbumLoaded(Album album) { } private void removeAlbumItem(String path) { + Log.d("AlbumActivity", "removeAlbumItem() called with: path = [" + path + "]"); int index = -1; for (int i = 0; i < album.getAlbumItems().size(); i++) { AlbumItem albumItem = album.getAlbumItems().get(i); @@ -1169,9 +1170,14 @@ private void removeAlbumItem(String path) { break; } } + Log.d("AlbumActivity", "removeAlbumItem: " + index); if (index > -1) { album.getAlbumItems().remove(index); - recyclerViewAdapter.notifyDataSetChanged(); + } + recyclerViewAdapter.notifyDataSetChanged(); + + if (album.getAlbumItems().size() == 0) { + finish(); } } } diff --git a/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java b/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java index 2f4f107d..19122b2b 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java @@ -572,8 +572,22 @@ public void onReceive(Context context, Intent intent) { .putExtra(ALBUM_ITEM_PATH, path); //notify AlbumActivity LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(i); - ItemActivity.this.setResult(RESULT_OK); - finish(); + /*ItemActivity.this.setResult(RESULT_OK); + finish();*/ + + album.getAlbumItems().remove(albumItem); + viewPager.getAdapter().notifyDataSetChanged(); + + if (album.getAlbumItems().size() == 0) { + ItemActivity.this.setResult(RESULT_OK); + finish(); + return; + } + + albumItem = album.getAlbumItems().get(viewPager.getCurrentItem()); + ItemAdapter adapter = (ItemAdapter) viewPager.getAdapter(); + ViewHolder viewHolder = adapter.findViewHolderByTag(albumItem.getPath()); + onShowViewHolder(viewHolder); break; case FileOperation.FAILED: //onBackPressed();