// Path: src/main/java/de/e621/rebane/components/listadapter/PostListAdapter.java
// public class PostListAdapter extends XMLListAdapter {
//     private String quality;
//     private int pageoffset;
//     private String escapedQuery;
// 
//     public PostListAdapter(PostsActivity context, int textViewResourceId, List<XMLNode> rowDataList, String quality) {
//         super(context.getApplicationContext(), textViewResourceId, rowDataList);
//         this.quality = quality;
//         this.pageoffset = (context.page-1)*context.pagesize;
//         this.escapedQuery = context.query;
//     }
// 
//     public View getView(final int position, View convertView, ViewGroup parent) {
//         PostListViewHolder holder = new PostListViewHolder(quality, this);
// 
//         LayoutInflater inflator = LayoutInflater.from(parent.getContext());
//         convertView = inflator.inflate(R.layout.preview_layout, parent, false);
// 
//         holder.populate(position, convertView, list.get(position), pageoffset, escapedQuery);
// 
//         return convertView;
//     }
// }


import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.itwookie.XMLreader.XMLNode;
import java.net.URLDecoder;
import de.e621.rebane.a621.R;
import de.e621.rebane.components.listadapter.PostListAdapter;

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.posts, menu);
        this.menu = menu;

        // Get the SearchView and set the searchable configuration
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) (searchMenuItem = menu.findItem(R.id.action_search)).getActionView();
        if (searchView != null) {
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    MenuItem searchMenuItem = PostsActivity.this.searchMenuItem;
                    if (searchMenuItem != null) {
                        searchMenuItem.collapseActionView();
                    }
                    return false;
                }
                @Override
                public boolean onQueryTextChange(String newText) {
                    return true;
                }
            });
        }
        else Toast.makeText(getApplicationContext(), "Could not enable Search!", Toast.LENGTH_LONG).show();

        return true;
    }


// Path: src/main/java/de/e621/rebane/components/listadapter/PostListAdapter.java
// public class PostListAdapter extends XMLListAdapter {
//     private String quality;
//     private int pageoffset;
//     private String escapedQuery;
// 
//     public PostListAdapter(PostsActivity context, int textViewResourceId, List<XMLNode> rowDataList, String quality) {
//         super(context.getApplicationContext(), textViewResourceId, rowDataList);
//         this.quality = quality;
//         this.pageoffset = (context.page-1)*context.pagesize;
//         this.escapedQuery = context.query;
//     }
// 
//     public View getView(final int position, View convertView, ViewGroup parent) {
//         PostListViewHolder holder = new PostListViewHolder(quality, this);
// 
//         LayoutInflater inflator = LayoutInflater.from(parent.getContext());
//         convertView = inflator.inflate(R.layout.preview_layout, parent, false);
// 
//         holder.populate(position, convertView, list.get(position), pageoffset, escapedQuery);
// 
//         return convertView;
//     }
// }


// Path: src/main/java/de/e621/rebane/activities/PostsActivity.java
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.itwookie.XMLreader.XMLNode;
import java.net.URLDecoder;
import de.e621.rebane.a621.R;
import de.e621.rebane.components.listadapter.PostListAdapter;

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.posts, menu);
        this.menu = menu;

        // Get the SearchView and set the searchable configuration
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) (searchMenuItem = menu.findItem(R.id.action_search)).getActionView();
        if (searchView != null) {
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    MenuItem searchMenuItem = PostsActivity.this.searchMenuItem;
                    if (searchMenuItem != null) {
                        searchMenuItem.collapseActionView();
                    }
                    return false;
                }
                @Override
                public boolean onQueryTextChange(String newText) {
                    return true;
                }
            });
        }
        else Toast.makeText(getApplicationContext(), "Could not enable Search!", Toast.LENGTH_LONG).show();

        return true;
    }


    @Override
