use of me.ccrama.redditslide.Adapters.CommentAdapterSearch in project Slide by ccrama.
the class CommentSearch method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideRedditSwipeAnywhere();
super.onCreate(savedInstance);
applyColorTheme();
setContentView(R.layout.activity_filtercomments);
final EditText search = (EditText) findViewById(R.id.search);
RecyclerView rv = (RecyclerView) findViewById(R.id.vertical_content);
final PreCachingLayoutManager mLayoutManager;
mLayoutManager = new PreCachingLayoutManager(this);
rv.setLayoutManager(mLayoutManager);
ArrayList<CommentNode> comments = new ArrayList<>();
List<CommentObject> commentsOld = DataShare.sharedComments;
if (commentsOld != null && !commentsOld.isEmpty())
for (CommentObject o : commentsOld) {
if (o instanceof CommentItem)
comments.add(o.comment);
}
else
finish();
final CommentAdapterSearch adapter = new CommentAdapterSearch(this, comments);
rv.setAdapter(adapter);
search.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
String result = search.getText().toString();
adapter.setResult(result);
adapter.getFilter().filter(result);
}
});
}
Aggregations