Search in sources :

Example 1 with SearchsResultUser

use of org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser in project AisenWeiBo by wangdan.

the class SearchHeaderView method onClick.

@Override
public void onClick(View v) {
    final SearchsResultUser data = (SearchsResultUser) v.getTag();
    WeiBoUser user = new WeiBoUser();
    user.setId(data.getId());
    user.setIdstr(data.getId());
    if (data.isFollowing()) {
        BizFragment.createBizFragment(fragment).destoryFriendship(user, new BizFragment.OnDestoryFriendshipCallback() {

            @Override
            public void onFriendshipDestoryed(WeiBoUser targetUser) {
                data.setFollowing(false);
                basicRecycleViewAdapter.notifyDataSetChanged();
            }
        });
    } else {
        BizFragment.createBizFragment(fragment).createFriendship(user, new BizFragment.OnCreateFriendshipCallback() {

            @Override
            public void onFriendshipCreated(WeiBoUser targetUser) {
                data.setFollowing(true);
                basicRecycleViewAdapter.notifyDataSetChanged();
            }
        });
    }
}
Also used : SearchsResultUser(org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) BizFragment(org.aisen.weibo.sina.ui.fragment.base.BizFragment)

Example 2 with SearchsResultUser

use of org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser in project AisenWeiBo by wangdan.

the class SinaSDK method searchsResultUsers.

/**
 * 使用H5页面查询用户
 *
 * @param q
 * @param cookies
 * @return
 * @throws TaskException
 */
public ArrayList<SearchsResultUser> searchsResultUsers(String q, String cookies) throws TaskException {
    ArrayList<SearchsResultUser> resultUsers = new ArrayList<>();
    Setting action = newSetting("searchsResultUsers", "page/pageJson", "获取用户");
    action.getExtras().put(BASE_URL, newSettingExtra(BASE_URL, "http://m.weibo.cn/", ""));
    Params params = new Params();
    // params.addParameter("containerid", "100103");
    // params.addParameter("type", "3");
    // params.addParameter("page", "1");
    // params.addParameter("q", q);
    // 我也搞不懂这个脑残接口到底怎么玩的
    // http://m.weibo.cn/page/pageJson?containerid=100103type%3D3%26q%3Dwang&page=1
    params.addParameter("containerid", "100103type%3D3%26q%3D" + q + "&page=1");
    try {
        HttpConfig config = getHttpConfig();
        // config.cookie = cookies;
        // config.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        // config.addHeader("Referer", "http://m.weibo.cn/searchs");
        String response = doGet(config, action, params, String.class);
        JSONObject responseJSON = JSONObject.parseObject(response);
        int ok = responseJSON.getInteger("ok");
        if (ok == 1) {
            JSONArray cardsArray = responseJSON.getJSONArray("cards");
            if (cardsArray.size() > 0) {
                JSONObject cardGroupsObject = cardsArray.getJSONObject(1);
                JSONArray cardGroupArray = cardGroupsObject.getJSONArray("card_group");
                for (int i = 0; i < cardGroupArray.size(); i++) {
                    JSONObject cardGroup = cardGroupArray.getJSONObject(i);
                    SearchsResultUser user = new SearchsResultUser();
                    user.setDesc1(cardGroup.getString("desc1"));
                    user.setDesc2(cardGroup.getString("desc2"));
                    JSONObject userJSON = cardGroup.getJSONObject("user");
                    user.setId(userJSON.getString("id"));
                    user.setFollowing(userJSON.getBoolean("following"));
                    user.setFollow_me(userJSON.getBoolean("follow_me"));
                    user.setFansNum(userJSON.getString("fansNum"));
                    user.setScreen_name(userJSON.getString("screen_name"));
                    user.setDescription(userJSON.getString("description"));
                    user.setProfile_image_url(userJSON.getString("profile_image_url"));
                    user.setStatuses_count(userJSON.getInteger("statuses_count"));
                    user.setGender(userJSON.getString("gender"));
                    user.setRemark(userJSON.getString("remark"));
                    resultUsers.add(user);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof TaskException) {
            throw e;
        }
    }
    return resultUsers;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) TaskException(org.aisen.android.network.task.TaskException) SearchsResultUser(org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser) Setting(org.aisen.android.common.setting.Setting) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) Params(org.aisen.android.network.http.Params) HttpConfig(org.aisen.android.network.http.HttpConfig) ParseException(java.text.ParseException) TaskException(org.aisen.android.network.task.TaskException)

Aggregations

SearchsResultUser (org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Setting (org.aisen.android.common.setting.Setting)1 HttpConfig (org.aisen.android.network.http.HttpConfig)1 Params (org.aisen.android.network.http.Params)1 TaskException (org.aisen.android.network.task.TaskException)1 WeiBoUser (org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)1 BizFragment (org.aisen.weibo.sina.ui.fragment.base.BizFragment)1