From 72e99aeff801de9e80dcfa890d5e9dc5f6c5766b Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sun, 21 Mar 2021 20:11:35 -0400 Subject: [PATCH] various improvements see the following comment on #814 --- .../asyncs/FeedPostFetchService.java | 8 +- .../customviews/PostsRecyclerView.java | 12 ++- .../dialogs/KeywordsFilterDialog.java | 22 ++++-- .../res/layout/dialog_keywords_filter.xml | 78 ++++++++++--------- app/src/main/res/layout/item_keyword.xml | 4 +- 5 files changed, 72 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java b/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java index 300e73f1..4fe91772 100644 --- a/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java +++ b/app/src/main/java/awais/instagrabber/asyncs/FeedPostFetchService.java @@ -11,7 +11,6 @@ import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.webservices.FeedService; import awais.instagrabber.webservices.ServiceCallback; -import awais.instagrabber.utils.KeywordsFilterUtils; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -43,12 +42,7 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService { hasNextPage = result.hasNextPage(); final List mediaResults = result.getFeedModels(); - 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); - } + feedModels.addAll(mediaResults); if (fetchListener != null) { // if (feedModels.size() < 15 && hasNextPage) { diff --git a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java index f7aac54e..cdab91c9 100644 --- a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java +++ b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java @@ -32,11 +32,15 @@ import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.repositories.responses.Media; +import awais.instagrabber.utils.Constants; +import awais.instagrabber.utils.KeywordsFilterUtils; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.Utils; import awais.instagrabber.viewmodels.MediaViewModel; import awais.instagrabber.workers.DownloadWorker; +import static awais.instagrabber.utils.Utils.settingsHelper; + public class PostsRecyclerView extends RecyclerView { private static final String TAG = "PostsRecyclerView"; @@ -70,7 +74,13 @@ public class PostsRecyclerView extends RecyclerView { } final List models = mediaViewModel.getList().getValue(); final List modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); - modelsCopy.addAll(result); + if (settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){ + final ArrayList items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); + modelsCopy.addAll(new KeywordsFilterUtils(items).filter(result)); + } + else { + modelsCopy.addAll(result); + } mediaViewModel.getList().postValue(modelsCopy); dispatchFetchStatus(); } diff --git a/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java b/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java index 5908f226..2a4d8a04 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java @@ -1,10 +1,12 @@ package awais.instagrabber.dialogs; +import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.widget.EditText; import android.widget.Toast; @@ -22,17 +24,27 @@ import awais.instagrabber.adapters.KeywordsFilterAdapter; import awais.instagrabber.databinding.DialogKeywordsFilterBinding; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.SettingsHelper; +import awais.instagrabber.utils.Utils; public final class KeywordsFilterDialog extends DialogFragment { + @Override + public void onStart() { + super.onStart(); + final Dialog dialog = getDialog(); + if (dialog == null) return; + final Window window = dialog.getWindow(); + if (window == null) return; + final int height = ViewGroup.LayoutParams.WRAP_CONTENT; + final int width = (int) (Utils.displayMetrics.widthPixels * 0.8); + window.setLayout(width, height); + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false); - init(dialogKeywordsFilterBinding, getContext()); - dialogKeywordsFilterBinding.btnOK.setOnClickListener(view -> this.dismiss()); - return dialogKeywordsFilterBinding.getRoot(); } @@ -55,10 +67,10 @@ public final class KeywordsFilterDialog extends DialogFragment { editText.setText(""); return; } - items.add(s); + items.add(s.toLowerCase()); settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); adapter.notifyItemInserted(items.size()); - final String message = context.getString(R.string.added_keywords).replace("{0}", s); + final String message = context.getString(R.string.added_keywords, s); Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); editText.setText(""); }); diff --git a/app/src/main/res/layout/dialog_keywords_filter.xml b/app/src/main/res/layout/dialog_keywords_filter.xml index e98d96d7..507d3b54 100644 --- a/app/src/main/res/layout/dialog_keywords_filter.xml +++ b/app/src/main/res/layout/dialog_keywords_filter.xml @@ -1,53 +1,57 @@ - + android:animateLayoutChanges="true" + android:paddingTop="16dp"> - + android:hint="@string/hint_keyword" + android:singleLine="true" + app:layout_constraintEnd_toStartOf="@id/btnAdd" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - - -