| | |
| | | package com.weikou.beibeivideo.ui.baidu; |
| | | |
| | | import android.os.Bundle; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.annotation.Nullable; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.app.FragmentManager; |
| | | import android.support.v4.app.FragmentStatePagerAdapter; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.Toast; |
| | | |
| | |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.BeibeiVideoApplication; |
| | | import com.weikou.beibeivideo.ui.MyRetainViewFragment; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.cache.DiskLruCacheManager; |
| | | import com.weikou.beibeivideo.util.downutil.StringUtils; |
| | | import com.yeshi.ec.library_baiducpu.R; |
| | |
| | | */ |
| | | public class BaiDuNewsFragment extends MyRetainViewFragment { |
| | | |
| | | private static final String TAG = BaiDuNewsFragment.class.getSimpleName(); |
| | | private ViewPager viewPager; |
| | | private ContentAdapter contentAdapter; |
| | | private List<BaiDuCPUType> itemList = new ArrayList<>(); |
| | |
| | | |
| | | private void initData(View contentView) { |
| | | mAQuery = new AQuery(contentView); |
| | | |
| | | } |
| | | |
| | | private void initCacheData() { |
| | | //获取缓存 |
| | | String value = DiskLruCacheManager.getInstance(BeibeiVideoApplication.application).getCache(getCacheKey()); |
| | | if (!StringUtils.isNullOrEmpty(value)) { |
| | |
| | | private synchronized void setData(String json) { |
| | | List<BaiDuCPUType> list = new Gson().fromJson(json, new TypeToken<List<BaiDuCPUType>>() { |
| | | }.getType()); |
| | | |
| | | |
| | | //数据一致就不必更新 |
| | | if (itemList != null) { |
| | | String data1 = new Gson().toJson(itemList); |
| | |
| | | |
| | | @Override |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | Log.i(TAG, "onCreateView"); |
| | | initView(contentView); |
| | | initData(contentView); |
| | | initCacheData(); |
| | | getTypeList(); |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | if (itemList == null || itemList.size() == 0) |
| | | initCacheData(); |
| | | } |
| | | |
| | | class ContentAdapter extends FragmentStatePagerAdapter { |
| | |
| | | |
| | | @Override |
| | | public Fragment getItem(int position) { |
| | | Fragment fragment = BaiDuCPUContentFragment.newInstance(mlist.get(position), BaiDuCPUContentFragment.VIEW_TYPE_NEWS); |
| | | Fragment fragment = BaiDuCPUContentFragment.newInstance(mlist.get(position), BaiDuCPUContentFragment.VIEW_TYPE_NEWS, AdUtil.getAdPid(getContext(), AdUtil.POSITION_SPLASH) != null); |
| | | return fragment; |
| | | } |
| | | |
| | |
| | | public CharSequence getPageTitle(int position) { |
| | | return mlist.get(position).getName(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onSaveInstanceState(@NonNull Bundle outState) { |
| | | Log.i(TAG, "onSaveInstanceState"); |
| | | super.onSaveInstanceState(outState); |
| | | } |
| | | } |