admin
2022-01-28 760aee20870a34e6130a1c12237c5b747e2b00bd
MGVideo/src/com/mugua/mgvideo/ui/main/RecommendNewFragment.java
@@ -42,12 +42,13 @@
import com.mugua.mgvideo.entity.recommend.HomeClass;
import com.mugua.mgvideo.test.MyViewPager;
import com.mugua.mgvideo.ui.category.bean.HotStar;
import com.mugua.mgvideo.ui.common.CommonFragmentActivity;
import com.mugua.mgvideo.ui.recommend.RecommendNewAdapter;
import com.mugua.mgvideo.ui.recommend.RecommendTopAdapter;
import com.mugua.mgvideo.ui.recommend.SearchActivity;
import com.mugua.mgvideo.util.DimenUtils;
import com.yeshi.base.utils.JsonUtil;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.umeng.analytics.MobclickAgent;
import com.viewpagerindicator.LinePageIndicator;
import com.yeshi.base.entity.JumpDetail;
import com.yeshi.base.entity.ad.AdPositionEnum;
@@ -63,7 +64,6 @@
import com.yeshi.base.utils.ad.GDTConstant;
import com.yeshi.base.utils.http.BasicTextHttpResponseHandler;
import com.yeshi.base.utils.ui.DividerItemDecoration;
import com.yeshi.video.ui.VideoDetailActivity;
import org.apache.http.Header;
import org.json.JSONArray;
@@ -121,10 +121,17 @@
    private TextView tv_go_search;
    private TextView tv_shop;
    private TextView tv_category;
    private SwipeRefreshLayout.OnRefreshListener mRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            //加载广告
            if (mRecommendNewAdapter != null) {
                mRecommendNewAdapter.refresh();
            }
            loadAd();
            getHomeAd();
            Log.i("mResult", "onCreate---setOnRefreshListener---loadAD1");
@@ -191,7 +198,7 @@
            return;
        if (mRecommendNewAdapter.getAdCount() == 0) {
            if (adList != null && adList.size() > 0) {
                mRecommendNewAdapter.addAdToPosition(adList.get(0), 2);
                mRecommendNewAdapter.addAdToPosition(adList.get(0), 0);
            }
            mRecommendNewAdapter.notifyDataSetChanged();
        }
@@ -286,9 +293,9 @@
                .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);
//        DividerItemDecoration decoration = new DividerItemDecoration();
//        decoration.setSize(DimenUtils.dip2px(rv_recommend.getContext(), 0));
//        rv_recommend.addItemDecoration(decoration);
        loading = LayoutInflater.from(getContext()).inflate(R.layout.item_loading, null);
        loading.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
@@ -383,6 +390,12 @@
        iv_right_ad_close = contentView.findViewById(R.id.iv_right_ad_close);
        ll_right_ad = contentView.findViewById(R.id.ll_right_ad);
        tv_shop = contentView.findViewById(R.id.tv_shop);
        tv_category = contentView.findViewById(R.id.tv_category);
        tv_shop.setOnClickListener(this);
        tv_category.setOnClickListener(this);
        type = (HomeClass) getArguments().getSerializable("videotype");
        position = (Integer) getArguments().get("position");
@@ -450,7 +463,7 @@
            if (recommendAdManager.getSourceType() == AdUtil.AD_TYPE.csj) {
                pid = CSJConstant.RECOMMEND_BIG_IMG_AD;
                height = (int) (width * 0.78);
            } else if (recommendAdManager.getSourceType() == AdUtil.AD_TYPE.gdt2) {
            } else if (recommendAdManager.getSourceType() == AdUtil.AD_TYPE.gdt) {
                pid = GDTConstant.PID_HOME_RECOMMEND_BIG_IMG;
            }
@@ -563,9 +576,8 @@
            try {
                snapshot = cache.get(getKey("getHomeType") + type.getId());
                if (snapshot != null) {
                    Gson gson = new GsonBuilder().setFieldNamingPolicy(
                            FieldNamingPolicy.UPPER_CAMEL_CASE).create();
                    List<HomeType> homeTypes = gson.fromJson(
                    List<HomeType> homeTypes = JsonUtil.videoGson.fromJson(
                            snapshot.getString(0),
                            new TypeToken<List<HomeType>>() {
                            }.getType());
@@ -659,21 +671,32 @@
        needRefresh = true;
    }
    private void setNavShow() {
        if (YouthUtil.isOpenYouthMode(getActivity())) {
            tv_category.setVisibility(View.GONE);
            tv_shop.setVisibility(View.GONE);
        } else {
            if (AdUtil.isCanInitCSJ() && AdUtil.getAdType(getContext(), AdPositionEnum.splashHotStart) != null) {
                tv_category.setVisibility(View.VISIBLE);
                tv_shop.setVisibility(View.VISIBLE);
            } else {
                tv_category.setVisibility(View.GONE);
                tv_shop.setVisibility(View.GONE);
            }
        }
    }
    @Override
    public void onResume() {
        super.onResume();
        indicator_recommend.setViewPager(vp_recommend);
        mChangeHelper.registerReceiver();
        if (YouthUtil.isOpenYouthMode(getContext())) {
            tv_go_search.setVisibility(View.GONE);
        } else {
            tv_go_search.setVisibility(View.VISIBLE);
        }
        if (needRefresh) {
            needRefresh = false;
            rl_recommend.setRefreshing(true);
            mRefreshListener.onRefresh();
        }
        setNavShow();
    }
    @Override
@@ -753,6 +776,7 @@
                                    .setPrettyPrinting()
                                    .setFieldNamingPolicy(
                                            FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .excludeFieldsWithoutExposeAnnotation()
                                    .create();
                            JSONObject data = jsonObject
                                    .getJSONObject("Data");
@@ -808,9 +832,6 @@
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            Gson gson = new GsonBuilder().setVersion(1.0).setFieldNamingPolicy(
                                    FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .create();
                            List<HomeType> homeTypes = new ArrayList<HomeType>();
                            JSONArray array = jsonObject.getJSONObject("Data")
                                    .getJSONArray("data");
@@ -834,7 +855,7 @@
                                if (obj.optJSONObject("Ad") != null)
                                    type.setAd(gson.fromJson(obj.optJSONObject("Ad").toString(), HomeType.HomeTypeAd.class));
                                    type.setAd(JsonUtil.videoGson.fromJson(obj.optJSONObject("Ad").toString(), HomeType.HomeTypeAd.class));
                                JSONArray homeArray = obj
                                        .optJSONArray("HomeVideoList");
@@ -842,7 +863,7 @@
                                if (homeArray != null && homeArray.length() > 0) {
                                    for (int j = 0; j < homeArray.length(); j++) {
                                        homeList.add(gson.fromJson(homeArray
                                        homeList.add(JsonUtil.videoGson.fromJson(homeArray
                                                        .optJSONObject(j).toString(),
                                                HomeVideo.class));
                                    }
@@ -856,7 +877,7 @@
                                if (itemArray != null && itemArray.length() > 0) {
                                    for (int k = 0; k < itemArray.length(); k++) {
                                        if (itemArray.optJSONObject(k) != null) {
                                            itemList.add(gson.fromJson(
                                            itemList.add(JsonUtil.videoGson.fromJson(
                                                    itemArray.optJSONObject(k)
                                                            .toString(),
                                                    HomeTypeItem.class));
@@ -923,6 +944,24 @@
                startActivity(intent);
            }
            break;
            case R.id.tv_shop: {
                Intent intent = new Intent(getContext(), CommonFragmentActivity.class);
                intent.putExtra("title", "集市");
                intent.putExtra("fragment", ShopFragment.class.getName());
                startActivity(intent);
            }
            break;
            case R.id.tv_category: {
                Intent intent = new Intent(getContext(), CommonFragmentActivity.class);
                intent.putExtra("title", "分类");
                intent.putExtra("fragment", CategoryFragment.class.getName());
                startActivity(intent);
            }
            break;
            default:
                break;
        }
@@ -932,6 +971,9 @@
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        if (mRecommendNewAdapter != null) {
            mRecommendNewAdapter.onDestory();
        }
    }
    private List<HomeVideo> adList1 = new ArrayList<>();