// 向服务器请求备料工单 private void getPrepareData(boolean isRefresh) { // 如果是用户下拉刷新操作,请求网络数据 if (isRefresh) { VolleyUtil.getVolleyUtil() .requestPrepareList( getActivity(), GloableParams.ADDRESS_PREPARELIST_APPLY, VolleyUtil.METHOD_POST, VolleyUtil.FRAGMENT_SHOP_PREPARELIST); return; } // 如果是页面加载操作 else { // 如果需要加载数据:是从主界面跳转过来,就向服务器请求数据;如果是采集页面返回跳转到此页面,不向服务器请求数据。 if (isLoadingData) { // 取缓存数据 DataSourceManager.getDataSourceManager().getLocalPrepareListCache(ct); Log.i("SCMake", "activity:p" + getActivity()); // 如果从缓存未取到数据,就从网络加载数据 Log.i("SCMake", "数据是否为空:" + prepareDataList.size()); loadingView.show(); if (prepareDataList.size() == 0) { Log.e("SCMAKE:GETDATA", " no prepareList cache"); VolleyUtil.getVolleyUtil() .requestPrepareList( getActivity(), GloableParams.ADDRESS_PREPARELIST_APPLY, VolleyUtil.METHOD_POST, VolleyUtil.FRAGMENT_SHOP_PREPARELIST); } else { Log.e("SCMAKE", "fromCache:" + prepareDataList.toString()); loadingView.dismiss(); } ; } } }
/*========================搜索界面:SearchPopWin====================================*/ @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.i("SCMake", "onCreateView"); FunctionActivity.setTitle(GloableParams.GRIDNAME_MATERIAL_PREPARE); View view = inflater.inflate(R.layout.fragment_scmakeprepare, container, false); ct = getActivity(); Log.i("SCMake", "activity:o" + ct); // 接口回调 DataSourceManager.getDataSourceManager().setNotifyData(this); VolleyUtil.setVolleyHandler(handler); // 获取数据 prepareDataList = DataSourceManager.getDataSourceManager().getPrepareList(); // 获取组件 ptrl = (PullToRefreshLayout) view.findViewById(R.id.refresh_view_makeprepare); prepareList = (ListView) view.findViewById(R.id.content_list_makeprepare); nullItemLayoutPrepare = (RelativeLayout) view.findViewById(R.id.rl_nulldata); btnShowSearch = (Button) getActivity().findViewById(R.id.btn_actionbar_right); btnBack = (Button) getActivity().findViewById(R.id.btn_actionbar_withback); parentView = getActivity().getWindow().findViewById(Window.ID_ANDROID_CONTENT); // 设置监听 btnShowSearch.setOnClickListener(this); ptrl.setOnRefreshListener( new PullToRefreshLayout.OnRefreshListener() { @Override public void onRefresh(PullToRefreshLayout pullToRefreshLayout) { getPrepareData(true); // 刷新完毕,通知下拉头消失 pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED); } @Override public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {} }); // 初始化界面、List initListView(); btnShowSearch.setVisibility(View.VISIBLE); showNullItemImg(prepareDataList, nullItemLayoutPrepare); // 加载数据 loadingView = new LoadingView(getActivity()); // 获取初始数据 getPrepareData(false); return view; }