/** * 检索请求 * * @param keyword */ private void requestFilmInfo(String keyword) { showPd(getString(R.string.tips_resquesting)); CustomRequest.CustomParam param = new CustomRequest.CustomParam(); param.put("key", Constant.API_KEY_SEARCH_FILM_INFO); param.put("q", StringUtil.toURLEncoded(keyword)); CustomRequest.getInstance(this) .getString( requestQueue, TAG, Constant.URL_SEARCH_FILM_INFO, null, param, new CustomRequest.SimpleListener() { @Override public void onSuccess(String response) { try { JSONObject object = new JSONObject(response); if ("0".equals(object.getString("error_code"))) { SearchFilmResultBean bean = JsonUtil.jsonToBean( object.getJSONObject("result").toString(), SearchFilmResultBean.class); Intent intent = new Intent(FilmInfoActivity.this, FilmInfoActivity.class); Bundle data = new Bundle(); data.putSerializable("FILM_BEAN", bean); intent.putExtras(data); goTo(intent); } else { Snack.showShort(mActorsLayout, "未检索到相关影片"); } } catch (JSONException e) { e.printStackTrace(); } dismissPd(); } @Override public void onFailed(String errorMsg) { Snack.showShort(mActorsLayout, getString(R.string.tip_error_check_connection)); dismissPd(); } }); }
private void request(int month, int day) { showPd(); CustomRequest.CustomParam param = new CustomRequest.CustomParam(); param.put("key", API_KEY).put("v", "1.0").put("month", month + "").put("day", day + ""); CustomRequest.getInstance(this) .getString( requestQueue, TAG, Constant.URL_HISTORY_TODAY, null, param, new CustomRequest.SimpleListener() { @Override public void onSuccess(String response) { try { JSONObject object = new JSONObject(response); if (0 == (object.getInt("error_code"))) { JSONArray list = object.getJSONArray("result"); final List<HistoryTodayBean> temp = JsonUtil.jsonToList(list.toString(), HistoryTodayBean.class); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { final List<HistoryTodayBean> historyTodayBeanList = dbUtils.findAll(HistoryTodayBean.class); if (null != historyTodayBeanList) { dbUtils.deleteAll(HistoryTodayBean.class); } dbUtils.saveAll(temp); } catch (DbException e) { e.printStackTrace(); } return null; } }.execute(); mDataList.clear(); mDataList.addAll(temp); mListAdapter.notifyDataSetChanged(); loadImage(mTopAreaIv, temp.get(0).getPic()); mTopDesTv.setText(StringUtil.addBeginSpace(temp.get(0).getDes(), 4)); mRecyclerView.smoothScrollToPosition(0); hideFb(); } else { Snack.showShort(mRecyclerView, "访问服务器失败"); } dismissPd(); } catch (Exception e) { e.printStackTrace(); } } @Override public void onFailed(String errorMsg) { Snack.showShort(mRecyclerView, getString(R.string.tip_error_check_connection)); if (0 == mDataList.size()) { try { List<HistoryTodayBean> newsCache = dbUtils.findAll(HistoryTodayBean.class); if (null != newsCache) { mDataList.addAll(newsCache); mListAdapter.notifyDataSetChanged(); loadImage(mTopAreaIv, mListAdapter.getBeanList().get(0).getPic()); mTopDesTv.setText( StringUtil.addBeginSpace(mListAdapter.getBeanList().get(0).getDes(), 4)); } } catch (DbException e) { e.printStackTrace(); } } dismissPd(); } }); }