private void getHomeData() { RequestParams params = RequestParam.getRequestParams(getActivity()); params.put("pageCount", 20); client.post( HttpConfig.getGetHomelist(userId), params, new AsyncHttpResponseCallBack(getActivity()) { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { super.onSuccess(i, headers, bytes); try { Log.e("hot", new String(bytes)); Type type = new TypeToken<HomeDataEntry>() {}.getType(); homeData = gson.fromJson(new String(bytes), type); storeUrl = homeData.getData().getHost(); SharedPreferenceUtil.getSharedEditor(getActivity()) .putString(SharedPreferenceUtil.HOST, storeUrl) .commit(); SharedPreferenceUtil.getSharedEditor(getActivity()) .putString(SharedPreferenceUtil.SEARCH_WORD, homeData.getData().getSearchWord()) .commit(); FileUtil.writeData(FileUtil.TEXT_BACKUP, new String(bytes)); hotWork = homeData.getData().getHotWorkTagList(); mList.clear(); mList.addAll(homeData.getData().getWorks().getWorks()); handler.sendEmptyMessage(1); } catch (Exception e) { } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {} }); }
private void initData() { userId = SharedPreferenceUtil.getAccountSharedPreference(getActivity()) .getString(SharedPreferenceUtil.USERID, ""); templateTag = ""; LID = 1; gson = new Gson(); client = new AsyncHttpClient(); url = HttpConfig.getGetWorks(userId); DPIUtil.getScreenMetrics(getActivity()); float windowWidth = DPIUtil.screen_width; float paddingWidth = DPIUtil.dip2px(getActivity(), 5); imgWidth = windowWidth / 2 - paddingWidth; mList = new ArrayList<>(); mViewList = new ArrayList<>(); backUpFile = new File(FileUtil.TEXT_BACKUP); if (backUpFile.exists()) { String json = TempEditUtil.getJsonFromFile(FileUtil.TEXT_BACKUP); if (json != null) { try { Type type = new TypeToken<HomeDataEntry>() {}.getType(); homeData = gson.fromJson(json, type); hotWork = homeData.getData().getHotWorkTagList(); mList.addAll(homeData.getData().getWorks().getWorks()); getViewpager(); } catch (Exception e) { } } } refreshLayout.setColorSchemeColors(getResources().getColor(R.color.theme_accent)); refreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { firstVisibleItem = 0; visibleItemCount = 0; totalItemCount = 0; previousTotal = 0; LID = 1; mList.clear(); getListData(); } }); firstVisiableItemPositions = new int[2]; }