From 19a94f7e0a4b4bbcd0b928cab53dc1e110e7e7c4 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 16 Jul 2021 21:43:43 +0800 Subject: Automatically remove images that are not uploaded in PostGalleryActivity. --- .../infinityforreddit/activities/PostGalleryActivity.java | 8 ++++++++ .../adapters/RedditGallerySubmissionRecyclerViewAdapter.java | 5 +++++ 2 files changed, 13 insertions(+) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index d296688f..21d5c5d6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -266,6 +266,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); redditGalleryImageInfoList = savedInstanceState.getParcelableArrayList(REDDIT_GALLERY_IMAGE_INFO_STATE); + if (redditGalleryImageInfoList != null && !redditGalleryImageInfoList.isEmpty()) { + if (redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).payload == null) { + imageUri = Uri.parse(redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).imageUrlString); + uploadImage(); + } + } adapter.setRedditGalleryImageInfoList(redditGalleryImageInfoList); if (subredditName != null) { @@ -461,12 +467,14 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee } catch (ExecutionException | InterruptedException e) { e.printStackTrace(); handler.post(() -> { + adapter.removeFailedToUploadImage(); Snackbar.make(coordinatorLayout, R.string.get_image_bitmap_failed, Snackbar.LENGTH_LONG).show(); isUploading = false; }); } catch (XmlPullParserException | JSONException | IOException e) { e.printStackTrace(); handler.post(() -> { + adapter.removeFailedToUploadImage(); Snackbar.make(coordinatorLayout, R.string.error_processing_image, Snackbar.LENGTH_LONG).show(); isUploading = false; }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java index 005e65f4..80b4d1e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java @@ -136,6 +136,11 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada notifyItemChanged(redditGalleryImageInfoList.size() - 1); } + public void removeFailedToUploadImage() { + redditGalleryImageInfoList.remove(redditGalleryImageInfoList.size() - 1); + notifyItemRemoved(redditGalleryImageInfoList.size()); + } + class ImageViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.aspect_ratio_gif_image_view_item_reddit_gallery_submission_image) AspectRatioGifImageView imageView; -- cgit v1.2.3