From 21950a4277e0d2d19374e8f8d832500398c68a4b Mon Sep 17 00:00:00 2001 From: zerrium Date: Fri, 19 Mar 2021 18:47:50 +0700 Subject: [PATCH] Fixed warnings --- .../adapters/KeywordsFilterAdapter.java | 2 +- .../instagrabber/asyncs/FeedPostFetchService.java | 9 ++++----- .../dialogs/KeywordsFilterDialog.java | 15 ++++++++------- .../instagrabber/utils/KeywordsFilterUtils.java | 3 +++ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/KeywordsFilterAdapter.java b/app/src/main/java/awais/instagrabber/adapters/KeywordsFilterAdapter.java index 99867f6c..f15f0b01 100644 --- a/app/src/main/java/awais/instagrabber/adapters/KeywordsFilterAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/KeywordsFilterAdapter.java @@ -30,7 +30,7 @@ public class KeywordsFilterAdapter extends RecyclerView.Adapter mediaResults = result.getFeedModels(); - if(!settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){ - feedModels.addAll(mediaResults); - }else{ - ArrayList items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); + if(settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){ + final ArrayList items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); feedModels.addAll(new KeywordsFilterUtils(items).filter(mediaResults)); + }else{ + feedModels.addAll(mediaResults); } if (fetchListener != null) { diff --git a/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java b/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java index 473f6f5e..5908f226 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java @@ -29,7 +29,14 @@ public final class KeywordsFilterDialog extends DialogFragment { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false); - final Context context = getContext(); + init(dialogKeywordsFilterBinding, getContext()); + + dialogKeywordsFilterBinding.btnOK.setOnClickListener(view -> this.dismiss()); + + return dialogKeywordsFilterBinding.getRoot(); + } + + private void init(DialogKeywordsFilterBinding dialogKeywordsFilterBinding, Context context){ final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); final RecyclerView recyclerView = dialogKeywordsFilterBinding.recyclerKeyword; recyclerView.setLayoutManager(linearLayoutManager); @@ -55,11 +62,5 @@ public final class KeywordsFilterDialog extends DialogFragment { Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); editText.setText(""); }); - - dialogKeywordsFilterBinding.btnOK.setOnClickListener(view ->{ - this.dismiss(); - }); - - return dialogKeywordsFilterBinding.getRoot(); } } diff --git a/app/src/main/java/awais/instagrabber/utils/KeywordsFilterUtils.java b/app/src/main/java/awais/instagrabber/utils/KeywordsFilterUtils.java index a61ac66e..d7c07498 100644 --- a/app/src/main/java/awais/instagrabber/utils/KeywordsFilterUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/KeywordsFilterUtils.java @@ -17,6 +17,7 @@ public final class KeywordsFilterUtils { public boolean filter(final String caption){ if(caption == null) return false; + if(keywords.isEmpty()) return false; final String temp = caption.toLowerCase(Locale.getDefault()); for(final String s:keywords){ if(temp.contains(s)) return true; @@ -28,6 +29,7 @@ public final class KeywordsFilterUtils { if(media == null) return false; final Caption c = media.getCaption(); if(c == null) return false; + if(keywords.isEmpty()) return false; final String temp = c.getText().toLowerCase(LocaleUtils.getCurrentLocale()); for(final String s:keywords){ if(temp.contains(s)) return true; @@ -36,6 +38,7 @@ public final class KeywordsFilterUtils { } public List filter(final List media){ + if(keywords.isEmpty()) return media; if(media == null) return new ArrayList<>(); final List result= new ArrayList<>();