1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

various improvements

see the following comment on #814
This commit is contained in:
Austin Huang 2021-03-21 20:11:35 -04:00
parent 915e893cc1
commit 72e99aeff8
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
5 changed files with 72 additions and 52 deletions

View File

@ -11,7 +11,6 @@ import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.webservices.FeedService; import awais.instagrabber.webservices.FeedService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.utils.KeywordsFilterUtils;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
@ -43,12 +42,7 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
hasNextPage = result.hasNextPage(); hasNextPage = result.hasNextPage();
final List<Media> mediaResults = result.getFeedModels(); 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); feedModels.addAll(mediaResults);
}
if (fetchListener != null) { if (fetchListener != null) {
// if (feedModels.size() < 15 && hasNextPage) { // if (feedModels.size() < 15 && hasNextPage) {

View File

@ -32,11 +32,15 @@ import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.repositories.responses.Media; 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.ResponseBodyUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.MediaViewModel; import awais.instagrabber.viewmodels.MediaViewModel;
import awais.instagrabber.workers.DownloadWorker; import awais.instagrabber.workers.DownloadWorker;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class PostsRecyclerView extends RecyclerView { public class PostsRecyclerView extends RecyclerView {
private static final String TAG = "PostsRecyclerView"; 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> models = mediaViewModel.getList().getValue();
final List<Media> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); 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); modelsCopy.addAll(result);
}
mediaViewModel.getList().postValue(modelsCopy); mediaViewModel.getList().postValue(modelsCopy);
dispatchFetchStatus(); dispatchFetchStatus();
} }

View File

@ -1,10 +1,12 @@
package awais.instagrabber.dialogs; package awais.instagrabber.dialogs;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
@ -22,17 +24,27 @@ import awais.instagrabber.adapters.KeywordsFilterAdapter;
import awais.instagrabber.databinding.DialogKeywordsFilterBinding; import awais.instagrabber.databinding.DialogKeywordsFilterBinding;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.SettingsHelper; import awais.instagrabber.utils.SettingsHelper;
import awais.instagrabber.utils.Utils;
public final class KeywordsFilterDialog extends DialogFragment { 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 @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false); final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false);
init(dialogKeywordsFilterBinding, getContext()); init(dialogKeywordsFilterBinding, getContext());
dialogKeywordsFilterBinding.btnOK.setOnClickListener(view -> this.dismiss()); dialogKeywordsFilterBinding.btnOK.setOnClickListener(view -> this.dismiss());
return dialogKeywordsFilterBinding.getRoot(); return dialogKeywordsFilterBinding.getRoot();
} }
@ -55,10 +67,10 @@ public final class KeywordsFilterDialog extends DialogFragment {
editText.setText(""); editText.setText("");
return; return;
} }
items.add(s); items.add(s.toLowerCase());
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items));
adapter.notifyItemInserted(items.size()); 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(); Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
editText.setText(""); editText.setText("");
}); });

View File

@ -1,44 +1,47 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:padding="16dp"> 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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:animateLayoutChanges="true"
android:layout_marginTop="8dp" android:paddingTop="16dp">
android:layout_marginBottom="8dp">
<androidx.appcompat.widget.AppCompatEditText <androidx.appcompat.widget.AppCompatEditText
android:id="@+id/edit_text" android:id="@+id/edit_text"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" 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 <Button
android:id="@+id/btnAdd" android:id="@+id/btnAdd"
android:layout_width="48dp" android:layout_width="30dp"
android:layout_height="48dp" android:layout_height="30dp"
android:background="@drawable/ic_add" android:background="@drawable/ic_add"
android:scaleType="center" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="-50dp" /> app:layout_constraintStart_toEndOf="@id/edit_text"
</LinearLayout> app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/edit_text" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerKeyword" android:id="@+id/recyclerKeyword"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/btnAdd"
<FrameLayout app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content"> tools:layout_editor_absoluteX="16dp"
tools:listitem="@layout/item_keyword" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnOK" android:id="@+id/btnOK"
@ -46,8 +49,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:text="@string/ok" /> android:text="@string/ok"
</FrameLayout> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/recyclerKeyword" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

View File

@ -15,8 +15,8 @@
<Button <Button
android:id="@+id/keyword_delete" android:id="@+id/keyword_delete"
android:layout_width="48dp" android:layout_width="30dp"
android:layout_height="48dp" android:layout_height="30dp"
android:background="@drawable/ic_delete" android:background="@drawable/ic_delete"
android:scaleType="center" /> android:scaleType="center" />