| | |
| | | import android.os.Bundle; |
| | | import android.provider.Settings; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.view.PagerAdapter; |
| | | import android.support.v4.view.ViewPager; |
| | | 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.LinearLayout; |
| | | 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.ADSize; |
| | | import com.qq.e.ads.nativ.NativeExpressAD; |
| | | 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.R; |
| | | import com.weikou.beibeivideo.entity.HomeAd; |
| | | import com.weikou.beibeivideo.entity.HomeType; |
| | | import com.weikou.beibeivideo.entity.HomeTypeItem; |
| | | import com.weikou.beibeivideo.entity.HomeVideo; |
| | | import com.weikou.beibeivideo.entity.JumpDetail; |
| | | 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.HomeClass; |
| | | 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.yeshi.buwanshequ.R; |
| | | import com.ysh.wpc.appupdate.GoReview; |
| | | import com.ysh.wpc.appupdate.service.DownLoadFileService; |
| | | import com.weikou.beibeivideo.util.DimenUtils; |
| | | import com.weikou.beibeivideo.util.JumpActivityUtil; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.ui.DividerItemDecoration; |
| | | import com.yeshi.appupdate.GoReview; |
| | | import com.yeshi.appupdate.service.DownLoadFileService; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONArray; |
| | |
| | | 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 mHomeTypes; |
| | | |
| | | private List<HomeAd> mHomeAds; |
| | | |
| | | private DiskLruCache cache; |
| | | |
| | |
| | | |
| | | private ImageView iv_right_ad; |
| | | |
| | | private RatioLayout rl_recommend_top; |
| | | |
| | | private boolean isBottom = false; |
| | | |
| | | boolean isReview; |
| | | |
| | | public static Fragment newInstance(VideoType type, String position) { |
| | | if (Integer.parseInt(position) < 2) { |
| | | private Context context; |
| | | |
| | | public static Fragment newInstance(HomeClass type, String position) { |
| | | if ("recommend".equalsIgnoreCase(type.getDataType())) { |
| | | RecommendFragment fragment = new RecommendFragment(); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putSerializable("videotype", type); |
| | |
| | | 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) { |
| | | super.onCreate(savedInstanceState); |
| | | context = getActivity().getApplicationContext(); |
| | | try { |
| | | cache = DiskLruCache.open( |
| | | new File(StorageUtils.getCacheDirectory(getContext()) |
| | | .toString(), "http"), getVersionNum(getContext()), |
| | | new File(StorageUtils.getCacheDirectory(context) |
| | | .toString(), "http"), getVersionNum(context), |
| | | 1, 1024 * 1024); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onSaveInstanceState(Bundle outState) { |
| | | outState.putString("flash back", "show"); |
| | | super.onSaveInstanceState(outState); |
| | | |
| | | } |
| | | |
| | | public static int getVersionNum(Context context) { |
| | |
| | | return date; |
| | | } |
| | | |
| | | |
| | | //填充数据 |
| | | private void setAdContent() { |
| | | //没有广告,添加广告 |
| | | if (position != 0)//只有推荐才有广告 |
| | | return; |
| | | if (mRecommendNewAdapter.getAdCount() == 0) { |
| | | if (adList != null && adList.size() > 0) { |
| | | mRecommendNewAdapter.addAdToPosition(adList.get(0), 3); |
| | | } |
| | | mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | |
| | | private ViewPager vp_recommend; |
| | | private LinearLayout ll_ad_containner; |
| | | private RatioLayout rl_recommend_top; |
| | | private LinePageIndicator indicator_recommend; |
| | | |
| | | private void initHomeAd() { |
| | | View view = LayoutInflater.from(getContext()).inflate(R.layout.recommend_top, null); |
| | | vp_recommend = view.findViewById(R.id.vp_recommend); |
| | | ll_ad_containner = view.findViewById(R.id.ll_ad_containner); |
| | | rl_recommend_top = view.findViewById(R.id.rl_recommend_top); |
| | | if (position > 0) |
| | | rl_recommend_top.setRatio(0.56f); |
| | | indicator_recommend = view.findViewById(R.id.indicator_recommend); |
| | | mRecommendNewAdapter.setHeaderView(view); |
| | | autoPlayBanner(vp_recommend); |
| | | } |
| | | |
| | | @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); |
| | | mChangeHelper = new ConnectivityChangeHelper(tv_no_network.getContext(), |
| | | tv_notice = contentView.findViewById(R.id.include_notice); |
| | | mChangeHelper = new ConnectivityChangeHelper(context, |
| | | new OnConnectivityChangeListener() { |
| | | @Override |
| | | public void onNetworkUnAvailable() { |
| | |
| | | } |
| | | }); |
| | | |
| | | int width = (int) SystemCommon.getScreenWidth(tv_no_network.getContext()); |
| | | int width = (int) SystemCommon.getScreenWidth(context); |
| | | |
| | | 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(context)); |
| | | DividerItemDecoration decoration = new DividerItemDecoration(); |
| | | decoration.setSize(DimenUtils.dip2px(rv_recommend.getContext(), 0)); |
| | | 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(context, 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"); |
| | | } |
| | | }); |
| | | |
| | | if (mHomeTypes == null) |
| | | mHomeTypes = new ArrayList(); |
| | | mRecommendNewAdapter = new RecommendNewAdapter(getActivity(), mHomeTypes); |
| | | rv_recommend.setAdapter(mRecommendNewAdapter); |
| | | setAdContent(); |
| | | initHomeAd(); |
| | | //加载缓存数据 |
| | | // loadCacheData(); |
| | | 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(AdUtil.AD_TYPE.csj, context); |
| | | recommendAdManager.loadRecommendLargeAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(final List<ExpressAdContainer> adList) { |
| | | RecommendFragment.this.adList = new ArrayList<>(); |
| | | for (ExpressAdContainer ad : adList) { |
| | | ExpressAdManager.renderAd(getActivity(), ad, new ExpressAdManager.IAdRenderListener() { |
| | | @Override |
| | | public void onRenderSuccess(List<ExpressAdContainer> adList1) { |
| | | RecommendFragment.this.adList.add(adList1.get(0)); |
| | | if (RecommendFragment.this.adList.size() == adList.size()) { |
| | | if (mRecommendNewAdapter.getAdCount() == 0 && mHomeTypes.size() > 0) {//没有填充广告 |
| | | setAdContent(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onRenderFail(List<ExpressAdContainer> adList) { |
| | | |
| | | } |
| | | }, new ExpressAdManager.IAdEventListener() { |
| | | @Override |
| | | public void closeAd(ExpressAdContainer ad) { |
| | | mRecommendNewAdapter.removeAd(ad); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | private Runnable autoPlayBanner = null; |
| | | |
| | | private synchronized void autoPlayBanner(final ViewPager viewPager) { |
| | | |
| | | if (autoPlayBanner == null) { |
| | | autoPlayBanner = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | if (viewPager.getAdapter() != null && viewPager.getAdapter().getCount() > 0) { |
| | | if (viewPager.getCurrentItem() >= viewPager.getAdapter().getCount() - 1) { |
| | | viewPager.setCurrentItem(0, true); |
| | | } else { |
| | | viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, true); |
| | | } |
| | | } |
| | | autoPlayBanner(viewPager); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | }; |
| | | viewPager.postDelayed(autoPlayBanner, 3000); |
| | | } else { |
| | | viewPager.removeCallbacks(autoPlayBanner); |
| | | viewPager.postDelayed(autoPlayBanner, 3000); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置广告数据 |
| | | */ |
| | | private void setHomeAdsData() { |
| | | if (vp_recommend.getAdapter() == null) { |
| | | vp_recommend.setAdapter(new RecommendTopAdapter(mHomeAds, getActivity(), position == 0 ? false : true)); |
| | | int width = (int) SystemCommon.getScreenWidth(getContext()); |
| | | indicator_recommend.setScreenWidth(width); |
| | | indicator_recommend.setSelectedColor(vp_recommend.getContext().getResources() |
| | | .getColor(R.color.yellow)); |
| | | indicator_recommend.setUnselectedColor(0xbbADA9A7); |
| | | indicator_recommend.setViewPager(vp_recommend); |
| | | indicator_recommend.setViewPager(vp_recommend); |
| | | } else |
| | | vp_recommend.getAdapter().notifyDataSetChanged(); |
| | | } |
| | | |
| | | 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); |
| | | setHomeAdsData(); |
| | | } |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | |
| | | mHomeTypes.clear(); |
| | | if (homeTypes != null) { |
| | | mHomeTypes.addAll(homeTypes); |
| | | mRecommendAdapter.notifyDataSetChanged(); |
| | | // mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (snapshot != null) { |
| | |
| | | } |
| | | } |
| | | } |
| | | 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(context, 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(context).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(context, BrowserActivity.class); |
| | | intent.putExtra("url", webLink); |
| | | startActivity(intent); |
| | | } else { |
| | | try { |
| | | Intent intent = new Intent(indicator_recommend.getContext(), |
| | | Intent intent = new Intent(context, |
| | | DownLoadFileService.class); |
| | | getContext().stopService(intent); |
| | | context.stopService(intent); |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putString("downloadurl", |
| | | downloadLink); |
| | | Intent intent = new Intent(indicator_recommend.getContext(), |
| | | Intent intent = new Intent(context, |
| | | DownLoadFileService.class); |
| | | intent.putExtras(bundle); |
| | | getContext().startService(intent); |
| | | context.startService(intent); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | |
| | | @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; |
| | | |
| | | private void getNotice() { |
| | | SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = context.getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getNotice(tv_no_network.getContext(), uid, |
| | | BeibeiVideoAPI.getNotice(context, uid, |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | JSONObject obj = jsonObject.optJSONObject("Data"); |
| | | content = obj.optString("Content"); |
| | | JSONObject jumpDetailJson = obj.optJSONObject("jumpDetail"); |
| | | JumpDetail jumpDetail = null; |
| | | if (jumpDetailJson != null) { |
| | | jumpDetail = new Gson().fromJson(jumpDetailJson.toString(), JumpDetail.class); |
| | | } |
| | | JSONObject paramsJson = obj.optJSONObject("Params"); |
| | | com.alibaba.fastjson.JSONObject params = null; |
| | | if (paramsJson != null) |
| | | params = com.alibaba.fastjson.JSONObject.parseObject(paramsJson.toString()); |
| | | |
| | | |
| | | final JumpDetail fJumpDetail = jumpDetail; |
| | | final com.alibaba.fastjson.JSONObject fParams = params; |
| | | |
| | | // 0-不显示 |
| | | // 1-显示 |
| | | final String url = obj.optString("Url"); |
| | | if (position > 0)//只有第一页才显示通知 |
| | | content = null; |
| | | if (!StringUtils.isBlank(content)) { |
| | | tv_notice.setVisibility(View.VISIBLE); |
| | | tv_notice.setText(content); |
| | | if (!StringUtils.isBlank(url)) { |
| | | tv_notice |
| | | .setOnClickListener(new OnClickListener() { |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(new Intent( |
| | | v.getContext(), |
| | | BrowserActivity.class) |
| | | .putExtra("url", url)); |
| | | |
| | | JumpActivityUtil.jumpPage(getActivity(), fJumpDetail, fParams); |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | |
| | | private void getHomeAd() { |
| | | SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = context.getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getHomeAd(tv_no_network.getContext(), uid, type.getId(), |
| | | BeibeiVideoAPI.getHomeAd(context, uid, type.getId(), |
| | | new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | |
| | | .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); |
| | | } |
| | | |
| | | setHomeAdsData(); |
| | | |
| | | |
| | | 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( |
| | | |
| | | SharedPreferences preferences = context.getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getHomeType(tv_no_network.getContext(), uid, type.getId(), |
| | | BeibeiVideoAPI.getHomeType(context, 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(); |
| | | } |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | Gson gson = new GsonBuilder().setVersion(1.0).setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | List<HomeType> homeTypes = new ArrayList<HomeType>(); |
| | |
| | | } |
| | | } |
| | | type.setItemTypeList(itemList); |
| | | // if (type.getId().equalsIgnoreCase("1111")) { |
| | | // type.getHomeVideoList().clear(); |
| | | // type.getHomeVideoList().addAll(liveList); |
| | | // } |
| | | homeTypes.add(type); |
| | | if (!type.getName().equalsIgnoreCase("美女")) |
| | | homeTypes.add(type); |
| | | } |
| | | mHomeTypes.addAll(homeTypes); |
| | | |
| | | mRecommendAdapter.notifyDataSetChanged(); |
| | | //清除老数据 |
| | | mHomeTypes.clear(); |
| | | mRecommendNewAdapter.removeAllAd(); |
| | | mHomeTypes.addAll(homeTypes); |
| | | //填充数据 |
| | | setAdContent(); |
| | | if (position == 0) { |
| | | DiskLruCache.Editor editor = cache |
| | | .edit(getKey("getHomeType") + type.getId()); |
| | | editor.set(0, jsonObject.getJSONObject("Data") |
| | | .getJSONArray("data").toString()); |
| | | editor.commit(); |
| | | } |
| | | 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(); |
| | | if (autoPlayBanner != null) |
| | | vp_recommend.removeCallbacks(autoPlayBanner); |
| | | } |
| | | |
| | | 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<>(); |
| | | |
| | | private void getHotStars() { |
| | | SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = context.getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getRecommendStars(tv_no_network.getContext(), uid, |
| | | BeibeiVideoAPI.getRecommendStars(context, uid, |
| | | new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | |