parent
915e893cc1
commit
72e99aeff8
@ -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<Media> mediaResults = result.getFeedModels();
|
||||
if(settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){
|
||||
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
|
||||
feedModels.addAll(new KeywordsFilterUtils(items).filter(mediaResults));
|
||||
}else{
|
||||
feedModels.addAll(mediaResults);
|
||||
}
|
||||
|
||||
if (fetchListener != null) {
|
||||
// if (feedModels.size() < 15 && hasNextPage) {
|
||||
|
@ -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<Media> models = mediaViewModel.getList().getValue();
|
||||
final List<Media> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models);
|
||||
if (settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){
|
||||
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
|
||||
modelsCopy.addAll(new KeywordsFilterUtils(items).filter(result));
|
||||
}
|
||||
else {
|
||||
modelsCopy.addAll(result);
|
||||
}
|
||||
mediaViewModel.getList().postValue(modelsCopy);
|
||||
dispatchFetchStatus();
|
||||
}
|
||||
|
@ -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("");
|
||||
});
|
||||
|
@ -1,44 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp">
|
||||
android:animateLayoutChanges="true"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:hint="@string/hint_keyword" />
|
||||
android:hint="@string/hint_keyword"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintEnd_toStartOf="@id/btnAdd"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnAdd"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:background="@drawable/ic_add"
|
||||
android:scaleType="center"
|
||||
android:layout_marginStart="-50dp" />
|
||||
</LinearLayout>
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/edit_text"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/edit_text" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerKeyword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnAdd"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:layout_editor_absoluteX="16dp"
|
||||
tools:listitem="@layout/item_keyword" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnOK"
|
||||
@ -46,8 +49,9 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:text="@string/ok" />
|
||||
</FrameLayout>
|
||||
android:text="@string/ok"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/recyclerKeyword" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
@ -15,8 +15,8 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/keyword_delete"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:background="@drawable/ic_delete"
|
||||
android:scaleType="center" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user