Search in sources :

Example 1 with AtUserBean

use of org.qii.weiciyuan.bean.AtUserBean in project weiciyuan by qii.

the class AtUsersDBTask method get.

public static List<AtUserBean> get(SQLiteDatabase db, String accountId) {
    List<AtUserBean> msgList = new ArrayList<AtUserBean>();
    String sql = "select * from " + AtUsersTable.TABLE_NAME + " where " + AtUsersTable.ACCOUNTID + "  = " + accountId + " order by " + AtUsersTable.ID + " desc";
    Cursor c = db.rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(AtUsersTable.JSONDATA));
        try {
            AtUserBean value = gson.fromJson(json, AtUserBean.class);
            msgList.add(value);
        } catch (JsonSyntaxException e) {
            AppLogger.e(e.getMessage());
        }
    }
    c.close();
    return msgList;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ArrayList(java.util.ArrayList) AtUserBean(org.qii.weiciyuan.bean.AtUserBean) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 2 with AtUserBean

use of org.qii.weiciyuan.bean.AtUserBean in project weiciyuan by qii.

the class AtUserFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.actionbar_menu_atuserfragment, menu);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(GlobalContext.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}
Also used : SearchView(android.widget.SearchView) SearchManager(android.app.SearchManager) AtUserBean(org.qii.weiciyuan.bean.AtUserBean)

Example 3 with AtUserBean

use of org.qii.weiciyuan.bean.AtUserBean in project weiciyuan by qii.

the class AtUserFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    token = getArguments().getString("token");
    adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, result);
    setListAdapter(adapter);
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent();
            intent.putExtra("name", "@" + atList.get(position).getNickname() + " ");
            getActivity().setResult(Activity.RESULT_OK, intent);
            AtUsersDBTask.add(atList.get(position), GlobalContext.getInstance().getCurrentAccountId());
            getActivity().finish();
        }
    });
    atList = AtUsersDBTask.get(GlobalContext.getInstance().getCurrentAccountId());
    for (AtUserBean b : atList) {
        result.add(b.getNickname());
    }
    adapter.notifyDataSetChanged();
}
Also used : AtUserBean(org.qii.weiciyuan.bean.AtUserBean) AdapterView(android.widget.AdapterView) Intent(android.content.Intent) SearchView(android.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 4 with AtUserBean

use of org.qii.weiciyuan.bean.AtUserBean in project weiciyuan by qii.

the class AtUserDao method getUserInfo.

public List<AtUserBean> getUserInfo() throws WeiboException {
    String url = URLHelper.AT_USER;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("q", q);
    map.put("count", count);
    map.put("type", type);
    map.put("range", range);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    Gson gson = new Gson();
    List<AtUserBean> value = null;
    try {
        value = gson.fromJson(jsonData, new TypeToken<List<AtUserBean>>() {
        }.getType());
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return value;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) AtUserBean(org.qii.weiciyuan.bean.AtUserBean) List(java.util.List)

Aggregations

AtUserBean (org.qii.weiciyuan.bean.AtUserBean)4 SearchView (android.widget.SearchView)2 Gson (com.google.gson.Gson)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 SearchManager (android.app.SearchManager)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1