From 65624f0b42feca4b8943eb54efffddf3bb15605c Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 21 Jun 2021 23:42:14 -0400 Subject: [PATCH] patch downloaded check --- .../viewholder/FeedGridItemViewHolder.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedGridItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedGridItemViewHolder.java index af869af1..1a52eadf 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedGridItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedGridItemViewHolder.java @@ -24,6 +24,7 @@ import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; +import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.TextUtils; @@ -105,28 +106,33 @@ public class FeedGridItemViewHolder extends RecyclerView.ViewHolder { binding.typeIcon.setVisibility(View.VISIBLE); binding.typeIcon.setImageResource(typeIconRes); } - final List checkList = DownloadUtils.checkDownloaded(media); - if (checkList.isEmpty()) { - return; - } - switch (media.getMediaType()) { - case MEDIA_TYPE_IMAGE: - case MEDIA_TYPE_VIDEO: - binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE); - binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor(R.color.green_A400))); - break; - case MEDIA_TYPE_SLIDER: - binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE); - final List carouselMedia = media.getCarouselMedia(); - boolean allDownloaded = checkList.size() == (carouselMedia == null ? 0 : carouselMedia.size()); - if (allDownloaded) { - allDownloaded = checkList.stream().allMatch(downloaded -> downloaded); + binding.downloaded.setVisibility(View.GONE); + AppExecutors.INSTANCE.getTasksThread().execute(() -> { + final List checkList = DownloadUtils.checkDownloaded(media); + if (checkList.isEmpty()) { + return; + } + AppExecutors.INSTANCE.getMainThread().execute(() -> { + switch (media.getMediaType()) { + case MEDIA_TYPE_IMAGE: + case MEDIA_TYPE_VIDEO: + binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE); + binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor(R.color.green_A400))); + break; + case MEDIA_TYPE_SLIDER: + binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE); + final List carouselMedia = media.getCarouselMedia(); + boolean allDownloaded = checkList.size() == (carouselMedia == null ? 0 : carouselMedia.size()); + if (allDownloaded) { + allDownloaded = checkList.stream().allMatch(downloaded -> downloaded); + } + binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor( + allDownloaded ? R.color.green_A400 : R.color.yellow_400))); + break; + default: } - binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor( - allDownloaded ? R.color.green_A400 : R.color.yellow_400))); - break; - default: - } + }); + }); } private void setThumbImage(final String thumbnailUrl) {