From 44358bbd31d3b0ad2f4504fd64bdd10bb7d3f254 Mon Sep 17 00:00:00 2001 From: zerrium Date: Fri, 19 Mar 2021 16:19:59 +0700 Subject: [PATCH] Finishing touch for KeywordsFilter --- .../instagrabber/activities/MainActivity.java | 10 --------- .../asyncs/FeedPostFetchService.java | 22 ++++++++----------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index ac97e169..7aaf4d43 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -84,7 +84,6 @@ import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.emoji.EmojiParser; import awais.instagrabber.viewmodels.AppStateViewModel; -import zerrium.FilterKeywordsUtility; import static awais.instagrabber.utils.NavigationExtensions.setupWithNavController; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -178,15 +177,6 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage }); initEmojiCompat(); // initDmService(); - initZerriumFilter(); //to filter out junk instagram post - } - - private void initZerriumFilter(){ - try{ - FilterKeywordsUtility.insert(getResources().getStringArray(R.array.filter_keyword)); - }catch(Exception e){ - Log.e(TAG, "initZerriumFilter: " + e); - } } private void initDmService() { diff --git a/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java b/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java index d7e1d1a4..54bd2509 100644 --- a/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java +++ b/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java @@ -5,14 +5,13 @@ import java.util.List; import awais.instagrabber.customviews.helpers.PostFetcher; import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.repositories.responses.Caption; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.PostsFetchResponse; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.webservices.FeedService; import awais.instagrabber.webservices.ServiceCallback; -import zerrium.FilterKeywordsUtility; +import awais.instagrabber.utils.KeywordsFilterUtils; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -43,18 +42,15 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService { nextCursor = result.getNextCursor(); hasNextPage = result.hasNextPage(); - //Skip adding (junk) post to Feed models - for(final Media m:result.getFeedModels()){ - final Caption c = m.getCaption(); - if(c == null){ - feedModels.add(m); //No caption - continue; - } - if(!FilterKeywordsUtility.filter(c.getText())){ //Check caption if it doesn't contain any specified keywords in filter_keywords.xml - feedModels.add(m); - } + //Check caption if it doesn't contain any specified keywords in filter_keywords.xml + List mediaResults = result.getFeedModels(); + if(!settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){ + feedModels.addAll(mediaResults); + }else{ + ArrayList items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); + feedModels.addAll(new KeywordsFilterUtils(items).filter(mediaResults)); } - //feedModels.addAll(result.getFeedModels()); + if (fetchListener != null) { // if (feedModels.size() < 15 && hasNextPage) { // feedService.fetch(csrfToken, nextCursor, this);