Search in sources :

Example 1 with CommentAdapterSearch

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);
        }
    });
}
Also used : EditText(android.widget.EditText) ArrayList(java.util.ArrayList) CommentNode(net.dean.jraw.models.CommentNode) CommentAdapterSearch(me.ccrama.redditslide.Adapters.CommentAdapterSearch) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 EditText (android.widget.EditText)1 ArrayList (java.util.ArrayList)1 CommentAdapterSearch (me.ccrama.redditslide.Adapters.CommentAdapterSearch)1 CommentItem (me.ccrama.redditslide.Adapters.CommentItem)1 CommentObject (me.ccrama.redditslide.Adapters.CommentObject)1 PreCachingLayoutManager (me.ccrama.redditslide.Views.PreCachingLayoutManager)1 CommentNode (net.dean.jraw.models.CommentNode)1