1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 13:26:59 +00:00

Fixed Edit Keyword Filters dialog settings

This commit is contained in:
zerrium 2021-03-19 18:26:44 +07:00
parent 44358bbd31
commit 10f5d91a42
8 changed files with 37 additions and 26 deletions

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@ -37,15 +38,18 @@ public class KeywordsFilterAdapter extends RecyclerView.Adapter<KeywordsFilterDi
public void onBindViewHolder(@NonNull KeywordsFilterDialogViewHolder holder, int position) {
holder.getTextView().setText(items.get(position));
holder.getDeleteButton().setOnClickListener(view -> {
final String s = items.get(position);
SettingsHelper settingsHelper = new SettingsHelper(context);
items.remove(items.get(position));
items.remove(position);
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items));
notifyDataSetChanged();
final String message = context.getString(R.string.removed_keywords).replace("{0}", s);
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
});
}
@Override
public int getItemCount() {
return 0;
return items.size();
}
}

View File

@ -1,7 +1,7 @@
package awais.instagrabber.adapters.viewholder.dialogs;
import android.view.View;
import android.widget.ImageView;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -11,7 +11,7 @@ import awais.instagrabber.R;
public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder {
private final ImageView deleteButton;
private final Button deleteButton;
private final TextView item;
public KeywordsFilterDialogViewHolder(@NonNull View itemView) {
@ -20,7 +20,7 @@ public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder {
item = itemView.findViewById(R.id.keyword_text);
}
public ImageView getDeleteButton(){
public Button getDeleteButton(){
return deleteButton;
}

View File

@ -43,7 +43,7 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
hasNextPage = result.hasNextPage();
//Check caption if it doesn't contain any specified keywords in filter_keywords.xml
List<Media> mediaResults = result.getFeedModels();
final List<Media> mediaResults = result.getFeedModels();
if(!settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){
feedModels.addAll(mediaResults);
}else{

View File

@ -6,6 +6,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -16,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.HashSet;
import awais.instagrabber.R;
import awais.instagrabber.adapters.KeywordsFilterAdapter;
import awais.instagrabber.databinding.DialogKeywordsFilterBinding;
import awais.instagrabber.utils.Constants;
@ -23,24 +25,23 @@ import awais.instagrabber.utils.SettingsHelper;
public final class KeywordsFilterDialog extends DialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false);
final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false);
final Context context = getContext();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
final RecyclerView recyclerView = dialogKeywordsFilterBinding.recycler;
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
final RecyclerView recyclerView = dialogKeywordsFilterBinding.recyclerKeyword;
recyclerView.setLayoutManager(linearLayoutManager);
SettingsHelper settingsHelper = new SettingsHelper(context);
ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items);
final SettingsHelper settingsHelper = new SettingsHelper(context);
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
final KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items);
recyclerView.setAdapter(adapter);
final EditText editText = dialogKeywordsFilterBinding.editText;
dialogKeywordsFilterBinding.addIcon.setOnClickListener(view ->{
dialogKeywordsFilterBinding.btnAdd.setOnClickListener(view ->{
final String s = editText.getText().toString();
if(s.isEmpty()) return;
if(items.contains(s)) {
@ -49,13 +50,16 @@ public final class KeywordsFilterDialog extends DialogFragment {
}
items.add(s);
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items));
adapter.notifyDataSetChanged();
adapter.notifyItemInserted(items.size());
final String message = context.getString(R.string.added_keywords).replace("{0}", s);
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
editText.setText("");
});
dialogKeywordsFilterBinding.btnOK.setOnClickListener(view ->{
this.dismiss();
});
return super.onCreateView(inflater, container, savedInstanceState);
return dialogKeywordsFilterBinding.getRoot();
}
}

View File

@ -11,7 +11,7 @@ public final class KeywordsFilterUtils {
private final ArrayList<String> keywords;
public KeywordsFilterUtils(ArrayList<String> keywords){
public KeywordsFilterUtils(final ArrayList<String> keywords){
this.keywords = keywords;
}

View File

@ -17,21 +17,22 @@
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/edit_text"
android:layout_width="320dp"
android:layout_height="48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="60dp"
android:hint="@string/hint_keyword" />
<ImageView
android:id="@+id/add_icon"
<Button
android:id="@+id/btnAdd"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:background="@drawable/ic_add"
android:scaleType="center"
android:layout_marginStart="8dp" />
android:layout_marginStart="-50dp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:id="@+id/recyclerKeyword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@ -13,11 +13,11 @@
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
<Button
android:id="@+id/keyword_delete"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackground"
android:background="@drawable/ic_delete"
android:scaleType="center" />
</LinearLayout>

View File

@ -469,4 +469,6 @@
<string name="hint_keyword">Keyword</string>
<string name="toggle_keyword_filter">Enable keyword filter</string>
<string name="edit_keyword_filter">Edit keyword filters</string>
<string name="added_keywords">Added keyword: {0} to filter list</string>
<string name="removed_keywords">Removed keyword: {0} from filter list</string>
</resources>