| | |
| | | import android.os.Bundle; |
| | | import android.provider.Settings; |
| | | import android.support.v4.app.Fragment; |
| | | 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.View; |
| | | import android.view.View.OnClickListener; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | |
| | | 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.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.recommend.RecommendContent; |
| | | 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.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.buwanshequ.R; |
| | | import com.ysh.wpc.appupdate.GoReview; |
| | | import com.ysh.wpc.appupdate.service.DownLoadFileService; |
| | | import com.yeshi.appupdate.GoReview; |
| | | import com.yeshi.appupdate.service.DownLoadFileService; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONArray; |
| | |
| | | |
| | | private RecommendNewAdapter mRecommendNewAdapter; |
| | | |
| | | private List<HomeType> mHomeTypes; |
| | | private List mHomeTypes; |
| | | |
| | | private List<HomeAd> mHomeAds; |
| | | |
| | |
| | | |
| | | boolean isReview; |
| | | |
| | | private List<RecommendContent> contentList; |
| | | private Context context; |
| | | |
| | | public static Fragment newInstance(VideoType type, String position) { |
| | | if (Integer.parseInt(position) < 2) { |
| | | 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); |
| | |
| | | @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 |
| | |
| | | |
| | | |
| | | //填充数据 |
| | | 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)); |
| | | private void setAdContent() { |
| | | //没有广告,添加广告 |
| | | if (position != 0)//只有推荐才有广告 |
| | | return; |
| | | if (mRecommendNewAdapter.getAdCount() == 0) { |
| | | if (adList != null && adList.size() > 0) { |
| | | mRecommendNewAdapter.addAdToPosition(adList.get(0), 3); |
| | | } |
| | | else { |
| | | contentList.add(RecommendContent.createHomeType(null)); |
| | | mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | //填充广告 |
| | | 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)); |
| | | } |
| | | 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 |
| | |
| | | tv_no_network.setOnClickListener(this); |
| | | // 公告 |
| | | tv_notice = contentView.findViewById(R.id.include_notice); |
| | | mChangeHelper = new ConnectivityChangeHelper(tv_no_network.getContext(), |
| | | 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 = contentView.findViewById(R.id.rl_recommend); |
| | | rv_recommend = contentView |
| | | .findViewById(R.id.rv_recommend); |
| | | |
| | | rv_recommend.setLayoutManager(new LinearLayoutManager(rv_recommend.getContext())); |
| | | rv_recommend.setLayoutManager(new LinearLayoutManager(context)); |
| | | DividerItemDecoration decoration = new DividerItemDecoration(); |
| | | decoration.setSize(DimenUtils.dip2px(rv_recommend.getContext(), 6)); |
| | | decoration.setSize(DimenUtils.dip2px(rv_recommend.getContext(), 0)); |
| | | rv_recommend.addItemDecoration(decoration); |
| | | |
| | | rl_recommend.setClickable(false); |
| | |
| | | position = (Integer) getArguments().get("position"); |
| | | |
| | | |
| | | isReview = GoReview.getGoReview(getContext(), BeibeiConstant.GO_REVIEW_KEY); |
| | | isReview = GoReview.getGoReview(context, BeibeiConstant.GO_REVIEW_KEY); |
| | | |
| | | |
| | | mHomeTypes = new ArrayList<HomeType>(); |
| | |
| | | Log.i("mResult", "onCreate---setOnRefreshListener---loadAD1"); |
| | | } |
| | | }); |
| | | contentList = new ArrayList<>(); |
| | | //加载缓存数据 |
| | | loadCacheData(); |
| | | |
| | | setContent(); |
| | | |
| | | |
| | | mRecommendNewAdapter = new RecommendNewAdapter(getActivity(), contentList); |
| | | if (mHomeTypes == null) |
| | | mHomeTypes = new ArrayList(); |
| | | mRecommendNewAdapter = new RecommendNewAdapter(getActivity(), mHomeTypes); |
| | | rv_recommend.setAdapter(mRecommendNewAdapter); |
| | | setAdContent(); |
| | | initHomeAd(); |
| | | //加载缓存数据 |
| | | // loadCacheData(); |
| | | rv_recommend.postDelayed(new Runnable() { |
| | | |
| | | @Override |
| | |
| | | |
| | | private void loadAd() { |
| | | try { |
| | | ExpressAdManager recommendAdManager = new ExpressAdManager(ExpressAdManager.SOURCE_GDT, getContext()); |
| | | ExpressAdManager recommendAdManager = new ExpressAdManager(AdUtil.AD_TYPE.csj, context); |
| | | 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++)); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //有填充广告 |
| | | if (hasAd) { |
| | | mRecommendNewAdapter.notifyDataSetChanged(); |
| | | @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 (adList != null && adList.size() > 0) { |
| | | mHomeAds.clear(); |
| | | mHomeAds.addAll(adList); |
| | | // mRecommendNewAdapter.notifyDataSetChanged(); |
| | | setHomeAdsData(); |
| | | } |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | |
| | | // mRecommendNewAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (snapshot != null) { |
| | |
| | | |
| | | |
| | | private void getAdRecommendRight() { |
| | | BeibeiVideoAPI.getAdRecommendRight(rv_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(rv_recommend.getContext()).load(img).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(rv_recommend.getContext(), BrowserActivity.class); |
| | | Intent intent = new Intent(context, BrowserActivity.class); |
| | | intent.putExtra("url", webLink); |
| | | startActivity(intent); |
| | | } else { |
| | | try { |
| | | Intent intent = new Intent(rv_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(rv_recommend.getContext(), |
| | | Intent intent = new Intent(context, |
| | | DownLoadFileService.class); |
| | | intent.putExtras(bundle); |
| | | getContext().startService(intent); |
| | | context.startService(intent); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | |
| | | 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, |
| | |
| | | mHomeAds.clear(); |
| | | mHomeAds.addAll(homeAds); |
| | | } |
| | | |
| | | setHomeAdsData(); |
| | | |
| | | |
| | | if (position == 0) { |
| | |
| | | |
| | | 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(getContext(), uid, type.getId(), |
| | | BeibeiVideoAPI.getHomeType(context, uid, type.getId(), |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | 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); |
| | | homeTypes.add(type); |
| | | if (!type.getName().equalsIgnoreCase("美女")) |
| | | homeTypes.add(type); |
| | | } |
| | | |
| | | //清除老数据 |
| | | mHomeTypes.clear(); |
| | | mRecommendNewAdapter.removeAllAd(); |
| | | mHomeTypes.addAll(homeTypes); |
| | | //填充数据 |
| | | setContent(); |
| | | 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 onDestroy() { |
| | | super.onDestroy(); |
| | | if (autoPlayBanner != null) |
| | | vp_recommend.removeCallbacks(autoPlayBanner); |
| | | } |
| | | |
| | | private List<HomeVideo> adList1 = new ArrayList<>(); |
| | |
| | | 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, |