private void getData(boolean forceRefresh) { V2EX.showTopicByUsername( getActivity(), forceRefresh, mMemberModel.username, new JsonHttpResponseHandler() { @Override public void onSuccess(JSONArray response) { DebugUtils.log(response); try { mModels = getModels(response); mListView.setAdapter(new PersonTopicAdapter(getActivity(), mModels)); mDataLoaded = true; } catch (JSONException e) { AppMsg.makeText(getActivity(), "Json decode error", AppMsg.STYLE_ALERT).show(); e.printStackTrace(); } mPullToRefreshLayout.setRefreshComplete(); super.onSuccess(response); } @Override public void onFailure( int statusCode, Header[] headers, String responseBody, Throwable e) { AppMsg.makeText(getActivity(), "Network error", AppMsg.STYLE_ALERT).show(); mPullToRefreshLayout.setRefreshComplete(); e.printStackTrace(); super.onFailure(statusCode, headers, responseBody, e); } }); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ActionBarPullToRefresh.from(getActivity()) .listener(this) .allChildrenArePullable() .setup(mPullToRefreshLayout); setupActionBar(); if (getArguments().containsKey("model")) { mMemberModel = getArguments().getParcelable("model"); showData(); } else if (getArguments().containsKey("username")) { String username = getArguments().getString("username").substring(1); mName.setText(username); mDescription.setText("Loading..."); V2EX.showUser( getActivity(), username, new JsonHttpResponseHandler() { @Override public void onSuccess(JSONObject response) { mMemberModel = new MemberModel(); try { mMemberModel.parse(response); showData(); } catch (JSONException e) { AppMsg.makeText(getActivity(), "Json decode error", AppMsg.STYLE_ALERT).show(); e.printStackTrace(); } super.onSuccess(response); } @Override public void onFailure( int statusCode, Header[] headers, String responseBody, Throwable e) { AppMsg.makeText(getActivity(), "Network error", AppMsg.STYLE_ALERT).show(); e.printStackTrace(); super.onFailure(statusCode, headers, responseBody, e); } }); } }