// Path: app/src/main/java/com/github/mzule/androidweekly/dao/SearchHistoryKeeper.java
// public class SearchHistoryKeeper {
// 
//     private static final int MAX_SIZE = 5;
// 
//     public static void save(String q) {
//         List<String> exist = read();
//         if (exist.contains(q)) {
//             exist.remove(q);
//         }
//         exist.add(0, q);
//         if (exist.size() > MAX_SIZE) {
//             exist = exist.subList(0, MAX_SIZE);
//         }
//         getSharedPreferences().edit().putString("q", JsonUtil.toJson(exist)).apply();
//     }
// 
//     public static List<String> read() {
//         String json = getSharedPreferences().getString("q", null);
//         if (TextUtils.isEmpty(json)) {
//             return new ArrayList<>();
//         } else {
//             return JsonUtil.fromJson(json, new TypeToken<List<String>>() {
//             }.getType());
//         }
//     }
// 
//     private static SharedPreferences getSharedPreferences() {
//         return App.getInstance().getSharedPreferences("SearchHistory", Context.MODE_PRIVATE);
//     }
// }
// 
// Path: app/src/main/java/com/github/mzule/androidweekly/ui/adapter/SearchHistoryAdapter.java
// public class SearchHistoryAdapter extends SingleTypeAdapter<String> {
//     public SearchHistoryAdapter(Context context) {
//         super(context);
//     }
// 
//     @Override
//     protected Class<? extends ViewType> singleViewType() {
//         return SearchHistoryViewType.class;
//     }
// }


import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.github.mzule.androidweekly.R;
import com.github.mzule.androidweekly.dao.SearchHistoryKeeper;
import com.github.mzule.androidweekly.ui.adapter.SearchHistoryAdapter;
import com.github.mzule.layoutannotation.Layout;
import butterknife.Bind;
import butterknife.OnItemClick;
package com.github.mzule.androidweekly.ui.activity;




/**
 * Created by CaoDongping on 4/5/16.
 */
@Layout(R.layout.activity_search)
public class SearchActivity extends BaseActivity {
    @Bind(R.id.queryInput)
    EditText queryInput;
    @Bind(R.id.listView)
    ListView listView;
    private SearchHistoryAdapter adapter;

    public static Intent makeIntent(Context context) {
        return new Intent(context, SearchActivity.class);
    }

    @OnItemClick(R.id.listView)
    void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String q = (String) parent.getAdapter().getItem(position);
// Path: app/src/main/java/com/github/mzule/androidweekly/dao/SearchHistoryKeeper.java
// public class SearchHistoryKeeper {
// 
//     private static final int MAX_SIZE = 5;
// 
//     public static void save(String q) {
//         List<String> exist = read();
//         if (exist.contains(q)) {
//             exist.remove(q);
//         }
//         exist.add(0, q);
//         if (exist.size() > MAX_SIZE) {
//             exist = exist.subList(0, MAX_SIZE);
//         }
//         getSharedPreferences().edit().putString("q", JsonUtil.toJson(exist)).apply();
//     }
// 
//     public static List<String> read() {
//         String json = getSharedPreferences().getString("q", null);
//         if (TextUtils.isEmpty(json)) {
//             return new ArrayList<>();
//         } else {
//             return JsonUtil.fromJson(json, new TypeToken<List<String>>() {
//             }.getType());
//         }
//     }
// 
//     private static SharedPreferences getSharedPreferences() {
//         return App.getInstance().getSharedPreferences("SearchHistory", Context.MODE_PRIVATE);
//     }
// }
// 
// Path: app/src/main/java/com/github/mzule/androidweekly/ui/adapter/SearchHistoryAdapter.java
// public class SearchHistoryAdapter extends SingleTypeAdapter<String> {
//     public SearchHistoryAdapter(Context context) {
//         super(context);
//     }
// 
//     @Override
//     protected Class<? extends ViewType> singleViewType() {
//         return SearchHistoryViewType.class;
//     }
// }


// Path: app/src/main/java/com/github/mzule/androidweekly/ui/activity/SearchActivity.java
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.github.mzule.androidweekly.R;
import com.github.mzule.androidweekly.dao.SearchHistoryKeeper;
import com.github.mzule.androidweekly.ui.adapter.SearchHistoryAdapter;
import com.github.mzule.layoutannotation.Layout;
import butterknife.Bind;
import butterknife.OnItemClick;

package com.github.mzule.androidweekly.ui.activity;




/**
 * Created by CaoDongping on 4/5/16.
 */
@Layout(R.layout.activity_search)
public class SearchActivity extends BaseActivity {
    @Bind(R.id.queryInput)
    EditText queryInput;
    @Bind(R.id.listView)
    ListView listView;
    private SearchHistoryAdapter adapter;

    public static Intent makeIntent(Context context) {
        return new Intent(context, SearchActivity.class);
    }

    @OnItemClick(R.id.listView)
    void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String q = (String) parent.getAdapter().getItem(position);
        SearchHistoryKeeper.save(q);