mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
Refactored Adapter and ViewHolder binder
This commit is contained in:
parent
03413eedcd
commit
480fd59713
@ -4,18 +4,14 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.adapters.viewholder.dialogs.KeywordsFilterDialogViewHolder;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.SettingsHelper;
|
||||
|
||||
public class KeywordsFilterAdapter extends RecyclerView.Adapter<KeywordsFilterDialogViewHolder> {
|
||||
|
||||
@ -36,16 +32,7 @@ public class KeywordsFilterAdapter extends RecyclerView.Adapter<KeywordsFilterDi
|
||||
|
||||
@Override
|
||||
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(position);
|
||||
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items));
|
||||
notifyDataSetChanged();
|
||||
final String message = context.getString(R.string.removed_keywords, s);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
holder.bind(items, position, context, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,21 @@
|
||||
package awais.instagrabber.adapters.viewholder.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
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.utils.Constants;
|
||||
import awais.instagrabber.utils.SettingsHelper;
|
||||
|
||||
public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@ -20,6 +28,19 @@ public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder {
|
||||
item = itemView.findViewById(R.id.keyword_text);
|
||||
}
|
||||
|
||||
public void bind(ArrayList<String> items, int position, Context context, KeywordsFilterAdapter adapter){
|
||||
item.setText(items.get(position));
|
||||
deleteButton.setOnClickListener(view -> {
|
||||
final String s = items.get(position);
|
||||
SettingsHelper settingsHelper = new SettingsHelper(context);
|
||||
items.remove(position);
|
||||
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items));
|
||||
adapter.notifyDataSetChanged();
|
||||
final String message = context.getString(R.string.removed_keywords, s);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
|
||||
public Button getDeleteButton(){
|
||||
return deleteButton;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user