| | |
| | | import android.os.Bundle; |
| | | import android.provider.Settings; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.view.PagerAdapter; |
| | | import android.support.v4.widget.SwipeRefreshLayout; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.MotionEvent; |
| | | import android.view.View; |
| | | import android.view.View.OnClickListener; |
| | | import android.view.WindowManager; |
| | | import android.widget.AbsListView; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.ImageView; |
| | | import android.widget.ListView; |
| | | import android.widget.TextView; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | |
| | | import com.lcjian.library.RetainViewFragment; |
| | | import com.lcjian.library.content.ConnectivityChangeHelper; |
| | | import com.lcjian.library.content.ConnectivityChangeHelper.OnConnectivityChangeListener; |
| | | import com.lcjian.library.util.SingleToast; |
| | | import com.lcjian.library.util.SystemCommon; |
| | | import com.lcjian.library.util.cache.DiskLruCache; |
| | | import com.lcjian.library.util.common.StorageUtils; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.lcjian.library.widget.RatioLayout; |
| | | import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; |
| | | import com.qq.e.ads.cfg.DownAPPConfirmPolicy; |
| | | import com.qq.e.ads.cfg.VideoOption; |
| | |
| | | import com.qq.e.ads.nativ.NativeExpressADView; |
| | | import com.qq.e.comm.util.AdError; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.viewpagerindicator.LinePageIndicator; |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.entity.HomeAd; |
| | |
| | | import com.weikou.beibeivideo.entity.HomeVideo; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.VideoType; |
| | | import com.weikou.beibeivideo.test.MyViewPager; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.recommend.RecommendContent; |
| | | import com.weikou.beibeivideo.ui.category.bean.HotStar; |
| | | import com.weikou.beibeivideo.ui.mine.BrowserActivity; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.wpc.superad.banner.Superbanner; |
| | | import com.weikou.beibeivideo.util.DimenUtils; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.ui.DividerItemDecoration; |
| | | import com.yeshi.buwanshequ.R; |
| | | import com.ysh.wpc.appupdate.GoReview; |
| | | import com.ysh.wpc.appupdate.service.DownLoadFileService; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import de.greenrobot.event.EventBus; |
| | | |
| | | public class RecommendFragment extends RetainViewFragment implements |
| | | OnClickListener { |
| | | |
| | | // private TextView tv_go_search; |
| | | |
| | | private View recommend_top; |
| | | |
| | | private MyViewPager vp_recommend; |
| | | |
| | | // private VerticalViewPager vp_ad; |
| | | |
| | | private LinePageIndicator indicator_recommend; |
| | | |
| | | private SwipeRefreshLayout rl_recommend; |
| | | |
| | | private ListView lv_recommend; |
| | | private RecyclerView rv_recommend; |
| | | |
| | | private RecommendAdapter mRecommendAdapter; |
| | | private RecommendNewAdapter mRecommendNewAdapter; |
| | | |
| | | private List<HomeType> mHomeTypes; |
| | | |
| | | private List<HomeAd> mHomeAds; |
| | | |
| | | private DiskLruCache cache; |
| | | |
| | |
| | | |
| | | private ImageView iv_right_ad; |
| | | |
| | | private RatioLayout rl_recommend_top; |
| | | |
| | | private boolean isBottom = false; |
| | | |
| | | boolean isReview; |
| | | |
| | | private List<RecommendContent> contentList; |
| | | |
| | | public static Fragment newInstance(VideoType type, String position) { |
| | | if (Integer.parseInt(position) < 2) { |
| | |
| | | fragment.setArguments(bundle); |
| | | return fragment; |
| | | } |
| | | |
| | | } |
| | | |
| | | private Runnable mAutoScroller = new Runnable() { |
| | | |
| | | @Override |
| | | public void run() { |
| | | PagerAdapter adapter = vp_recommend.getAdapter(); |
| | | if (adapter != null && adapter.getCount() != 0) { |
| | | vp_recommend.setCurrentItem((vp_recommend.getCurrentItem() + 1) |
| | | % adapter.getCount(), true); |
| | | } |
| | | vp_recommend.postDelayed(this, 5000); |
| | | } |
| | | }; |
| | | |
| | | @Override |
| | | public void onCreate(Bundle savedInstanceState) { |
| | |
| | | public void onSaveInstanceState(Bundle outState) { |
| | | outState.putString("flash back", "show"); |
| | | super.onSaveInstanceState(outState); |
| | | |
| | | } |
| | | |
| | | public static int getVersionNum(Context context) { |
| | |
| | | return date; |
| | | } |
| | | |
| | | |
| | | //填充数据 |
| | | private void setContent() { |
| | | contentList.clear(); |
| | | contentList.add(new RecommendContent(RecommendContent.TYPE_BANNER, mHomeAds)); |
| | | if (mHomeTypes != null && mHomeTypes.size() > 0) |
| | | for (HomeType ht : mHomeTypes) { |
| | | contentList.add(new RecommendContent(RecommendContent.TYPE_HOMETYPE, ht)); |
| | | } |
| | | else { |
| | | contentList.add(RecommendContent.createHomeType(null)); |
| | | } |
| | | //填充广告 |
| | | if (adList != null && adList.size() > 0) |
| | | contentList.add(2, RecommendContent.createAd(adList.get(0))); |
| | | else |
| | | contentList.add(2, RecommendContent.createAd(null)); |
| | | |
| | | if (adList != null && adList.size() > 1) { |
| | | contentList.add(RecommendContent.createAd(adList.get(1))); |
| | | } else { |
| | | contentList.add(RecommendContent.createAd(null)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | tv_no_network = (TextView) contentView.findViewById(R.id.tv_no_network); |
| | | tv_no_network = contentView.findViewById(R.id.tv_no_network); |
| | | tv_no_network.setOnClickListener(this); |
| | | // 公告 |
| | | tv_notice = (TextView) contentView.findViewById(R.id.include_notice); |
| | | tv_notice = contentView.findViewById(R.id.include_notice); |
| | | mChangeHelper = new ConnectivityChangeHelper(tv_no_network.getContext(), |
| | | new OnConnectivityChangeListener() { |
| | | @Override |
| | |
| | | |
| | | int width = (int) SystemCommon.getScreenWidth(tv_no_network.getContext()); |
| | | |
| | | rl_recommend = (SwipeRefreshLayout) contentView.findViewById(R.id.rl_recommend); |
| | | lv_recommend = (ListView) contentView |
| | | .findViewById(R.id.lv_recommend); |
| | | rl_recommend = contentView.findViewById(R.id.rl_recommend); |
| | | rv_recommend = contentView |
| | | .findViewById(R.id.rv_recommend); |
| | | |
| | | rv_recommend.setLayoutManager(new LinearLayoutManager(rv_recommend.getContext())); |
| | | DividerItemDecoration decoration = new DividerItemDecoration(); |
| | | decoration.setSize(DimenUtils.dip2px(rv_recommend.getContext(), 6)); |
| | | rv_recommend.addItemDecoration(decoration); |
| | | |
| | | rl_recommend.setClickable(false); |
| | | |
| | | iv_right_ad = (ImageView) contentView.findViewById(R.id.iv_right_ad); |
| | | recommend_top = LayoutInflater.from(tv_no_network.getContext()).inflate( |
| | | R.layout.recommend_top, null); |
| | | rl_recommend_top = (RatioLayout) recommend_top.findViewById(R.id.rl_recommend_top); |
| | | |
| | | FrameLayout fl_ad = (FrameLayout) recommend_top.findViewById(R.id.fl_ad); |
| | | // banner广告 |
| | | WindowManager wm = (WindowManager) tv_no_network.getContext().getSystemService( |
| | | Context.WINDOW_SERVICE); |
| | | Superbanner.initBanner(getActivity(), "100011", fl_ad, (int) (wm |
| | | .getDefaultDisplay().getWidth() * (98 / 600f))); |
| | | |
| | | vp_recommend = (MyViewPager) recommend_top |
| | | .findViewById(R.id.vp_recommend); |
| | | iv_right_ad = contentView.findViewById(R.id.iv_right_ad); |
| | | |
| | | type = (VideoType) getArguments().getSerializable("videotype"); |
| | | position = (Integer) getArguments().get("position"); |
| | | |
| | | vp_recommend.setOnTouchListener(new View.OnTouchListener() { |
| | | @Override |
| | | public boolean onTouch(View v, MotionEvent event) { |
| | | switch (event.getAction()) { |
| | | case MotionEvent.ACTION_MOVE: |
| | | rl_recommend.setEnabled(false); |
| | | break; |
| | | case MotionEvent.ACTION_UP: |
| | | case MotionEvent.ACTION_CANCEL: |
| | | rl_recommend.setEnabled(true); |
| | | break; |
| | | } |
| | | return false; |
| | | } |
| | | }); |
| | | indicator_recommend = (LinePageIndicator) recommend_top |
| | | .findViewById(R.id.indicator_recommend); |
| | | isReview = GoReview.getGoReview(indicator_recommend.getContext(), BeibeiConstant.GO_REVIEW_KEY); |
| | | if (position == 0) { |
| | | vp_recommend.setAdapter(new RecommendTopAdapter(null, getActivity(), isReview)); |
| | | } else { |
| | | vp_recommend.setAdapter(new RecommendTopAdapter(null, getActivity(), false)); |
| | | } |
| | | indicator_recommend.setScreenWidth(width); |
| | | indicator_recommend.setSelectedColor(vp_recommend.getContext().getResources() |
| | | .getColor(R.color.yellow)); |
| | | indicator_recommend.setUnselectedColor(0xbbADA9A7); |
| | | |
| | | isReview = GoReview.getGoReview(getContext(), BeibeiConstant.GO_REVIEW_KEY); |
| | | |
| | | |
| | | mHomeTypes = new ArrayList<HomeType>(); |
| | | mRecommendAdapter = new RecommendAdapter(mHomeTypes, getActivity()); |
| | | lv_recommend.addHeaderView(recommend_top); |
| | | lv_recommend.setAdapter(mRecommendAdapter); |
| | | mHomeAds = new ArrayList<>(); |
| | | |
| | | rl_recommend.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | if (position == 0) { |
| | | getHotStars(); |
| | | } |
| | | EventBus.getDefault().post(type); |
| | | rl_recommend.setRefreshing(false); |
| | | // vp_recommend.setCurrentItem(0, true); |
| | | //加载广告 |
| | | loadAd(); |
| | | getHomeAd(); |
| | | getHomeType(); |
| | | Log.i("mResult", "onCreate---setOnRefreshListener---loadAD1"); |
| | | } |
| | | }); |
| | | contentList = new ArrayList<>(); |
| | | //加载缓存数据 |
| | | loadCacheData(); |
| | | |
| | | setContent(); |
| | | |
| | | |
| | | mRecommendNewAdapter = new RecommendNewAdapter(getActivity(), contentList); |
| | | rv_recommend.setAdapter(mRecommendNewAdapter); |
| | | rv_recommend.postDelayed(new Runnable() { |
| | | |
| | | @Override |
| | | public void run() { |
| | | if (getActivity() != null) { |
| | | rl_recommend.setRefreshing(true); |
| | | getHomeAd(); |
| | | Log.i("mResult", "onCreate---postDelayed---loadAD1"); |
| | | if (position == 0) |
| | | getHotStars(); |
| | | } |
| | | } |
| | | }, 500); |
| | | |
| | | //加载广告 |
| | | loadAd(); |
| | | |
| | | getNotice(); |
| | | if (position == 0) { |
| | | getAdRecommendRight(); |
| | | } |
| | | } |
| | | |
| | | private List<ExpressAdContainer> adList; |
| | | |
| | | private void loadAd() { |
| | | try { |
| | | ExpressAdManager recommendAdManager = new ExpressAdManager(ExpressAdManager.SOURCE_GDT, getContext()); |
| | | recommendAdManager.loadRecommendLargeAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | //填充广告位 |
| | | RecommendFragment.this.adList = adList; |
| | | boolean hasAd = false; |
| | | int p = 0; |
| | | for (RecommendContent content : contentList) { |
| | | if (content.getType() == RecommendContent.TYPE_AD && content.getAd() == null) { |
| | | hasAd = true; |
| | | break; |
| | | } |
| | | p++; |
| | | } |
| | | |
| | | int adP = 0; |
| | | for (int i = 0; i < contentList.size(); i++) { |
| | | //填充广告数据 |
| | | if (contentList.get(i).getType() == RecommendContent.TYPE_AD && contentList.get(i).getAd() == null) { |
| | | //填充广告数据 |
| | | if (adP < RecommendFragment.this.adList.size()) { |
| | | hasAd = true; |
| | | contentList.get(i).setAd(RecommendFragment.this.adList.get(adP++)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //有填充广告 |
| | | if (hasAd) { |
| | | mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | }); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | private void loadCacheData() { |
| | | if (cache != null && position == 0) { |
| | | { |
| | | DiskLruCache.Snapshot snapshot = null; |
| | |
| | | |
| | | } |
| | | if (adList != null && adList.size() > 0) { |
| | | vp_recommend |
| | | .setAdapter(new RecommendTopAdapter( |
| | | adList, getActivity(), isReview)); |
| | | mHomeAds.clear(); |
| | | mHomeAds.addAll(adList); |
| | | // mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | |
| | | mHomeTypes.clear(); |
| | | if (homeTypes != null) { |
| | | mHomeTypes.addAll(homeTypes); |
| | | mRecommendAdapter.notifyDataSetChanged(); |
| | | // mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | |
| | | } |
| | | } |
| | | } |
| | | lv_recommend.postDelayed(new Runnable() { |
| | | |
| | | @Override |
| | | public void run() { |
| | | if (getActivity() != null) { |
| | | vp_recommend.setCurrentItem(0, true); |
| | | rl_recommend.setRefreshing(true); |
| | | getHomeAd(); |
| | | getHomeType(); |
| | | Log.i("mResult", "onCreate---postDelayed---loadAD1"); |
| | | if (position == 0) |
| | | getHotStars(); |
| | | } |
| | | } |
| | | }, 500); |
| | | getNotice(); |
| | | |
| | | lv_recommend.setOnScrollListener(new AbsListView.OnScrollListener() { |
| | | @Override |
| | | public void onScrollStateChanged(AbsListView view, int scrollState) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { |
| | | if (mHomeTypes.size() > 0 && (firstVisibleItem + visibleItemCount) < totalItemCount) { |
| | | isBottom = false; |
| | | } |
| | | if (mHomeTypes.size() > 0 && !isBottom && (firstVisibleItem + visibleItemCount) >= totalItemCount) { |
| | | SingleToast.showToast(indicator_recommend.getContext(), "没有更多了"); |
| | | isBottom = true; |
| | | } |
| | | } |
| | | }); |
| | | |
| | | if (position == 0) { |
| | | getAdRecommendRight(); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void getAdRecommendRight() { |
| | | BeibeiVideoAPI.getAdRecommendRight(indicator_recommend.getContext(), new BasicTextHttpResponseHandler() { |
| | | BeibeiVideoAPI.getAdRecommendRight(rv_recommend.getContext(), new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | |
| | | final String linkType = jsonObject.optJSONObject("Data").optString("linkType"); |
| | | final String webLink = jsonObject.optJSONObject("Data").optString("webLink"); |
| | | final String downloadLink = jsonObject.optJSONObject("Data").optString("downloadLink"); |
| | | Glide.with(indicator_recommend.getContext()).load("https://r1.ykimg.com/050E00005CE60A62859B5EC26201389E?x-oss-process=image/resize,w_290/interlace,1/quality,Q_80/sharpen,100").into(iv_right_ad); |
| | | Glide.with(rv_recommend.getContext()).load(img).into(iv_right_ad); |
| | | if (mstatus.equalsIgnoreCase("0")) { |
| | | iv_right_ad.setVisibility(View.GONE); |
| | | } else { |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (linkType.equalsIgnoreCase("0")) { |
| | | Intent intent = new Intent(indicator_recommend.getContext(), BrowserActivity.class); |
| | | Intent intent = new Intent(rv_recommend.getContext(), BrowserActivity.class); |
| | | intent.putExtra("url", webLink); |
| | | startActivity(intent); |
| | | } else { |
| | | try { |
| | | Intent intent = new Intent(indicator_recommend.getContext(), |
| | | Intent intent = new Intent(rv_recommend.getContext(), |
| | | DownLoadFileService.class); |
| | | getContext().stopService(intent); |
| | | } catch (Exception e) { |
| | |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putString("downloadurl", |
| | | downloadLink); |
| | | Intent intent = new Intent(indicator_recommend.getContext(), |
| | | Intent intent = new Intent(rv_recommend.getContext(), |
| | | DownLoadFileService.class); |
| | | intent.putExtras(bundle); |
| | | getContext().startService(intent); |
| | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | indicator_recommend.setViewPager(vp_recommend); |
| | | vp_recommend.postDelayed(mAutoScroller, 2000); |
| | | mChangeHelper.registerReceiver(); |
| | | MobclickAgent.onPageStart("主页面—推荐"); |
| | | // EventBus.getDefault().register(this); |
| | | } |
| | | |
| | | @Override |
| | | public void onPause() { |
| | | super.onPause(); |
| | | vp_recommend.removeCallbacks(mAutoScroller); |
| | | // vp_ad.removeCallbacks(mAdAutoScroller); |
| | | mChangeHelper.unregisterReceiver(); |
| | | MobclickAgent.onPageEnd("主页面—推荐"); |
| | | // EventBus.getDefault().unregister(this); |
| | | } |
| | | |
| | | private String content; |
| | |
| | | .getJSONObject("Data").getJSONArray("data") |
| | | .toString(), new TypeToken<List<HomeAd>>() { |
| | | }.getType()); |
| | | if (position == 1) { |
| | | rl_recommend_top.setRatio(0.56f); |
| | | vp_recommend.setAdapter(new RecommendTopAdapter( |
| | | homeAds, getActivity(), false)); |
| | | } else { |
| | | vp_recommend.setAdapter(new RecommendTopAdapter( |
| | | homeAds, getActivity(), isReview)); |
| | | |
| | | if (homeAds != null) { |
| | | mHomeAds.clear(); |
| | | mHomeAds.addAll(homeAds); |
| | | } |
| | | |
| | | |
| | | if (position == 0) { |
| | | DiskLruCache.Editor editor = cache |
| | |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | rl_recommend.setRefreshing(false); |
| | | getHomeType(); |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | |
| | | private void getHomeType() { |
| | | |
| | | SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getHomeType(tv_no_network.getContext(), uid, type.getId(), |
| | | BeibeiVideoAPI.getHomeType(getContext(), uid, type.getId(), |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | rl_recommend.setRefreshing(false); |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | if (mHomeTypes != null || mHomeTypes.size() > 0) { |
| | | mHomeTypes.clear(); |
| | |
| | | } |
| | | } |
| | | type.setItemTypeList(itemList); |
| | | // if (type.getId().equalsIgnoreCase("1111")) { |
| | | // type.getHomeVideoList().clear(); |
| | | // type.getHomeVideoList().addAll(liveList); |
| | | // } |
| | | homeTypes.add(type); |
| | | } |
| | | mHomeTypes.addAll(homeTypes); |
| | | |
| | | mRecommendAdapter.notifyDataSetChanged(); |
| | | //填充数据 |
| | | setContent(); |
| | | mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | rl_recommend.setRefreshing(false); |
| | | try { |
| | | loadAD1(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, |
| | | byte[] responseBytes, Throwable throwable) { |
| | | // TODO Auto-generated method stub |
| | | super.onFailure(statusCode, headers, responseBytes, |
| | | throwable); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取直播列表信息 |
| | | * |
| | | * @param homeType |
| | | */ |
| | | private List<HomeVideo> liveList; |
| | | |
| | | private void getLiveInfo() { |
| | | SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getLiveList(tv_no_network.getContext(), uid, "meinv_mm", |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | JSONArray homeArray = jsonObject.optJSONObject( |
| | | "Data").optJSONArray("data"); |
| | | liveList = new ArrayList<>(); |
| | | for (int j = 0; j < homeArray.length(); j++) { |
| | | liveList.add(gson.fromJson(homeArray |
| | | .optJSONObject(j).toString(), |
| | | HomeVideo.class)); |
| | | } |
| | | for (int i = 0; i < mHomeTypes.size(); i++) { |
| | | if (mHomeTypes.get(i).getId().equalsIgnoreCase("1111")) { |
| | | mHomeTypes.get(i).getHomeVideoList().clear(); |
| | | mHomeTypes.get(i).getHomeVideoList().addAll(liveList); |
| | | } |
| | | } |
| | | if (position <= 1) { |
| | | DiskLruCache.Editor editor = cache |
| | | .edit(getKey("getHomeType") + type.getId()); |
| | | editor.set(0, gson.toJson(mHomeTypes)); |
| | | editor.commit(); |
| | | |
| | | //插入明星列表 |
| | | if (hotStars != null && hotStars.size() > 0) { |
| | | HomeType homeType = new HomeType(); |
| | | homeType.setName("明星合辑"); |
| | | homeType.setColumns(4); |
| | | homeType.setHotStars(hotStars); |
| | | homeType.setActivity(""); |
| | | homeType.setBeizhu(""); |
| | | homeType.setParams(""); |
| | | homeType.setHasMore("true"); |
| | | homeType.setId("9998"); |
| | | mHomeTypes.add(homeType); |
| | | } |
| | | if (BeibeiConstant.AD_SETTING_RECOMMEND_FIRST) |
| | | if (adInfo != null && mHomeTypes != null && mHomeTypes.size() > 0) { |
| | | mHomeTypes.get(0).getHomeVideoList().get(0).setVideo(adInfo); |
| | | Log.i("mResult", "替换广告数据"); |
| | | } |
| | | } |
| | | //插入大屏广告 |
| | | if (adList != null && adList.size() > 0) { |
| | | HomeType homeType = new HomeType(); |
| | | homeType.setName("推广"); |
| | | homeType.setColumns(1); |
| | | homeType.setHomeVideoList(adList); |
| | | homeType.setActivity(""); |
| | | homeType.setBeizhu(""); |
| | | homeType.setParams(""); |
| | | homeType.setHasMore("false"); |
| | | homeType.setId("9999"); |
| | | mHomeTypes.add(1, homeType); |
| | | } |
| | | if (adList1 != null && adList1.size() > 0) { |
| | | HomeType homeType = new HomeType(); |
| | | homeType.setName("推广"); |
| | | homeType.setColumns(1); |
| | | homeType.setHomeVideoList(adList1); |
| | | homeType.setActivity(""); |
| | | homeType.setBeizhu(""); |
| | | homeType.setParams(""); |
| | | homeType.setHasMore("false"); |
| | | homeType.setId("8888"); |
| | | mHomeTypes.add(homeType); |
| | | } |
| | | mRecommendAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | rl_recommend.setRefreshing(false); |
| | | // getHomeType(); |
| | | Log.i("mResult", "getLiveInfo---onFinish---getHomeType"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onDestroy() { |
| | | super.onDestroy(); |
| | | } |
| | | |
| | | private List<HomeVideo> adList = new ArrayList<>(); |
| | | private List<HomeVideo> adList1 = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 中屏 |
| | | */ |
| | | // 1.加载广告,先设置加载上下文环境和条件 |
| | | private void loadAD1() { |
| | | NativeExpressAD nativeExpressAD = new NativeExpressAD(indicator_recommend.getContext(), new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), |
| | | BeibeiConstant.GDT_ID, BeibeiConstant.GDT_RECOMMAND_NATIVE, new NativeExpressAD.NativeExpressADListener() { |
| | | @Override |
| | | public void onADLoaded(final List<NativeExpressADView> list) { |
| | | tv_notice.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (list != null && list.size() > 0) { |
| | | HomeVideo homeVideo = new HomeVideo(); |
| | | VideoInfo info = new VideoInfo(); |
| | | info.setAdView(list.get(0)); |
| | | homeVideo.setVideo(info); |
| | | adList.add(homeVideo); |
| | | } |
| | | try { |
| | | loadAD3(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderFail(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderSuccess(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADExposure(NativeExpressADView nativeExpressADView) { |
| | | } |
| | | |
| | | @Override |
| | | public void onADClicked(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADClosed(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADLeftApplication(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADOpenOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADCloseOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) { |
| | | tv_notice.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | loadAD3(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); // 传入Activity |
| | | // 注意:如果您在联盟平台上新建原生模板广告位时,选择了支持视频,那么可以进行个性化设置(可选) |
| | | nativeExpressAD.setVideoOption(new VideoOption.Builder() |
| | | .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频 |
| | | .setAutoPlayMuted(true) // 自动播放时为静音 |
| | | .build()); // |
| | | nativeExpressAD.setDownAPPConfirmPolicy(DownAPPConfirmPolicy.Default); |
| | | nativeExpressAD.loadAD(2); |
| | | } |
| | | |
| | | /** |
| | | * 首页底屏 |
| | | */ |
| | | // 1.加载广告,先设置加载上下文环境和条件 |
| | | private void loadAD2() throws Exception { |
| | | String positionAdID; |
| | | if (position == 0) { |
| | | positionAdID = BeibeiConstant.GDT_RECOMMAND_MIN_NATIVE; |
| | | } else { |
| | | positionAdID = BeibeiConstant.GDT_RECOMMEND_CATEGORY_MIN_NATIVE; |
| | | } |
| | | NativeExpressAD nativeExpressAD = new NativeExpressAD(indicator_recommend.getContext(), new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), |
| | | BeibeiConstant.GDT_ID, positionAdID, new NativeExpressAD.NativeExpressADListener() { |
| | | @Override |
| | | public void onADLoaded(List<NativeExpressADView> list) { |
| | | if (list != null && list.size() > 0) { |
| | | HomeVideo homeVideo = new HomeVideo(); |
| | | VideoInfo info = new VideoInfo(); |
| | | info.setAdView(list.get(0)); |
| | | homeVideo.setVideo(info); |
| | | adList1.add(homeVideo); |
| | | } |
| | | tv_no_network.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | getLiveInfo(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderFail(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderSuccess(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADExposure(NativeExpressADView nativeExpressADView) { |
| | | } |
| | | |
| | | @Override |
| | | public void onADClicked(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADClosed(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADLeftApplication(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADOpenOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADCloseOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) { |
| | | tv_no_network.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | getLiveInfo(); |
| | | } |
| | | }); |
| | | } |
| | | }); // 传入Activity |
| | | // 注意:如果您在联盟平台上新建原生模板广告位时,选择了支持视频,那么可以进行个性化设置(可选) |
| | | nativeExpressAD.setVideoOption(new VideoOption.Builder() |
| | | .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频 |
| | | .setAutoPlayMuted(true) // 自动播放时为静音 |
| | | .build()); // |
| | | nativeExpressAD.loadAD(2); |
| | | } |
| | | |
| | | /** |
| | | * 分类首屏 |
| | | */ |
| | | VideoInfo adInfo; |
| | | |
| | | // 1.加载广告,先设置加载上下文环境和条件 |
| | | private void loadAD3() throws Exception { |
| | | String positionAdID; |
| | | if (position == 0) { |
| | | positionAdID = BeibeiConstant.GDT_RECOMMAND_MIN_NATIVE; |
| | | } else { |
| | | positionAdID = BeibeiConstant.GDT_RECOMMEND_CATEGORY_MIN_NATIVE; |
| | | } |
| | | NativeExpressAD nativeExpressAD = new NativeExpressAD(indicator_recommend.getContext(), new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), |
| | | BeibeiConstant.GDT_ID, positionAdID, new NativeExpressAD.NativeExpressADListener() { |
| | | @Override |
| | | public void onADLoaded(final List<NativeExpressADView> list) { |
| | | tv_notice.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (null != list && list.size() > 0) { |
| | | adInfo = new VideoInfo(); |
| | | adInfo.setAdView(list.get(0)); |
| | | } |
| | | try { |
| | | loadAD2(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderFail(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderSuccess(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADExposure(NativeExpressADView nativeExpressADView) { |
| | | } |
| | | |
| | | @Override |
| | | public void onADClicked(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADClosed(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADLeftApplication(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADOpenOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADCloseOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) { |
| | | tv_notice.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | loadAD2(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); // 传入Activity |
| | | // 注意:如果您在联盟平台上新建原生模板广告位时,选择了支持视频,那么可以进行个性化设置(可选) |
| | | nativeExpressAD.setVideoOption(new VideoOption.Builder() |
| | | .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频 |
| | | .setAutoPlayMuted(true) // 自动播放时为静音 |
| | | .build()); // |
| | | nativeExpressAD.loadAD(2); |
| | | } |
| | | |
| | | List<HotStar> hotStars = new ArrayList<>(); |
| | | |
| | |
| | | new TypeToken<List<HotStar>>() { |
| | | }.getType()); |
| | | hotStars.addAll(hotStarList); |
| | | |
| | | //插入明星列表 |
| | | if (hotStars != null && hotStars.size() > 0) { |
| | | HomeType homeType = new HomeType(); |
| | | homeType.setName("明星合辑"); |
| | | homeType.setColumns(4); |
| | | homeType.setHotStars(hotStars); |
| | | homeType.setActivity(""); |
| | | homeType.setBeizhu(""); |
| | | homeType.setParams(""); |
| | | homeType.setHasMore("true"); |
| | | homeType.setId("9998"); |
| | | mHomeTypes.add(homeType); |
| | | mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | } |
| | | |