mirror of
				https://github.com/KokaKiwi/BarInsta
				synced 2025-10-30 19:15:35 +00:00 
			
		
		
		
	replace DownloadCheckerAsyncTask, close #825
This commit is contained in:
		
							parent
							
								
									447ef0d660
								
							
						
					
					
						commit
						e726ba3ccf
					
				| @ -19,11 +19,11 @@ import java.util.List; | ||||
| 
 | ||||
| import awais.instagrabber.R; | ||||
| import awais.instagrabber.adapters.FeedAdapterV2; | ||||
| import awais.instagrabber.asyncs.DownloadedCheckerAsyncTask; | ||||
| import awais.instagrabber.databinding.ItemFeedGridBinding; | ||||
| import awais.instagrabber.models.PostsLayoutPreferences; | ||||
| import awais.instagrabber.repositories.responses.Media; | ||||
| import awais.instagrabber.repositories.responses.User; | ||||
| import awais.instagrabber.utils.DownloadUtils; | ||||
| import awais.instagrabber.utils.ResponseBodyUtils; | ||||
| import awais.instagrabber.utils.TextUtils; | ||||
| 
 | ||||
| @ -102,31 +102,28 @@ public class FeedGridItemViewHolder extends RecyclerView.ViewHolder { | ||||
|             binding.typeIcon.setVisibility(View.VISIBLE); | ||||
|             binding.typeIcon.setImageResource(typeIconRes); | ||||
|         } | ||||
|         final DownloadedCheckerAsyncTask task = new DownloadedCheckerAsyncTask(result -> { | ||||
|             final List<Boolean> checkList = result.get(media.getPk()); | ||||
|             if (checkList == null || 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<Media> 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: | ||||
|             } | ||||
|         }); | ||||
|         task.execute(media); | ||||
|         final List<Boolean> checkList = DownloadUtils.checkDownloaded(media); | ||||
|         if (checkList == null || 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<Media> 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: | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void setThumbImage(final String thumbnailUrl) { | ||||
|  | ||||
| @ -1,42 +0,0 @@ | ||||
| package awais.instagrabber.asyncs; | ||||
| 
 | ||||
| import android.os.AsyncTask; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import awais.instagrabber.repositories.responses.Media; | ||||
| import awais.instagrabber.utils.DownloadUtils; | ||||
| 
 | ||||
| public final class DownloadedCheckerAsyncTask extends AsyncTask<Media, Void, Map<String, List<Boolean>>> { | ||||
|     private static final String TAG = "DownloadedCheckerAsyncTask"; | ||||
| 
 | ||||
|     private final OnCheckResultListener listener; | ||||
| 
 | ||||
|     public DownloadedCheckerAsyncTask(final OnCheckResultListener listener) { | ||||
|         this.listener = listener; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected Map<String, List<Boolean>> doInBackground(final Media... feedModels) { | ||||
|         if (feedModels == null) { | ||||
|             return null; | ||||
|         } | ||||
|         final Map<String, List<Boolean>> map = new HashMap<>(); | ||||
|         for (final Media media : feedModels) { | ||||
|             map.put(media.getPk(), DownloadUtils.checkDownloaded(media)); | ||||
|         } | ||||
|         return map; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected void onPostExecute(final Map<String, List<Boolean>> result) { | ||||
|         if (listener == null) return; | ||||
|         listener.onResult(result); | ||||
|     } | ||||
| 
 | ||||
|     public interface OnCheckResultListener { | ||||
|         void onResult(final Map<String, List<Boolean>> result); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user