From abce02c7a61820f5d580f87364d542e817be429c Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 06 七月 2021 15:22:11 +0800 Subject: [PATCH] 1.1.1完善 --- app/src/main/java/com/tejia/lijin/app/ui/recommend/RecommendFragment.java | 186 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 159 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/tejia/lijin/app/ui/recommend/RecommendFragment.java b/app/src/main/java/com/tejia/lijin/app/ui/recommend/RecommendFragment.java index 8b8e147..254bbef 100644 --- a/app/src/main/java/com/tejia/lijin/app/ui/recommend/RecommendFragment.java +++ b/app/src/main/java/com/tejia/lijin/app/ui/recommend/RecommendFragment.java @@ -47,6 +47,8 @@ import com.tejia.lijin.app.entity.RecommendHot; import com.tejia.lijin.app.entity.SpecialOffer2; import com.tejia.lijin.app.entity.TaoBaoGoodsBrief; +import com.tejia.lijin.app.entity.hongbao.LijinSendInfo; +import com.tejia.lijin.app.ui.dialog.RecommendHbDialog; import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog; import com.tejia.lijin.app.ui.invite.ShareBrowserActivity; import com.tejia.lijin.app.ui.timeLimitedSpike.TimeLimitedSpikeActivity; @@ -57,6 +59,7 @@ import com.tejia.lijin.app.util.user.UserUtil; import com.wpc.library.RetainViewFragment; import com.wpc.library.content.ConnectivityChangeHelper; +import com.wpc.library.recyclerviewhelper.DividerItemDecoration; import com.wpc.library.util.NetUtils; import com.wpc.library.util.ScreenUtils; import com.wpc.library.util.SystemCommon; @@ -119,6 +122,7 @@ private List<SpecialOffer2> mSpecial3s = new ArrayList<>(); private List<HomeBanner> mBanners2 = new ArrayList<>(); private List<TaoBaoGoodsBrief> mList = new ArrayList<>(); + private List<TaoBaoGoodsBrief> mHotGoodsList = new ArrayList<>(); private List<String> lList = new ArrayList<>(); private List<String> lList2 = new ArrayList<>(); @@ -131,6 +135,12 @@ private boolean isCache = false; private boolean isLoad = false; ShapeLoadingDialog pd = null; + + //鐑棬鍟嗗搧 + private LinearLayout ll_hot_goods; + private RecyclerView rv_hot_goods; + private TextView tv_hot_goods_more; + private RecommendHotGoodsAdapter mRecommendHotGoodsAdapter; TextView @@ -174,6 +184,7 @@ public void onCreateView(View contentView, Bundle savedInstanceState) { init(contentView); initCacheData(); + } @Override @@ -227,21 +238,22 @@ } else outRect.bottom = 0; + outRect.left = 0; if ((index == total - 1) || (index == total - 2 && total % 2 == 0)) { outRect.right = 0; } else { outRect.right = DimenUtils.dipToPixels(space, view.getContext()); } + } }; - private void init(View contentView) { - rv_recommend_goods = contentView.findViewById(R.id.rv_recommend_goods); - rl_first_page = contentView.findViewById(R.id.rl_first_page); - iv_slid_top = contentView.findViewById(R.id.iv_slid_top); + private View initHeader() { final View top = LayoutInflater.from(rv_recommend_goods.getContext()) .inflate(R.layout.item_recommend_top, null); + + top.setBackground(HomeUIUtil.getHomeTopBg(getContext())); ll_fragment_activity = top.findViewById(R.id.ll_fragment_activity); ll_special_offer = top.findViewById(R.id.ll_special_offer); @@ -269,17 +281,57 @@ sv_hot = top.findViewById(R.id.sv_hot); iv_hot_img = top.findViewById(R.id.iv_hot_img); + //灏忛粍鏉� + tv_notice_content = top.findViewById(R.id.tv_notice_content); + ll_notice = top.findViewById(R.id.ll_notice); + iv_close = top.findViewById(R.id.iv_close); + + seekBar = top.findViewById(R.id.slide_indicator_point); + seekBar.setPadding(0, 0, 0, 0); + seekBar.setThumbOffset(0); + + ll_hot_goods = top.findViewById(R.id.ll_hot_goods); + rv_hot_goods = top.findViewById(R.id.rv_hot_goods); + tv_hot_goods_more = top.findViewById(R.id.tv_hot_goods_more); + + rv_hot_goods.addItemDecoration(new RecyclerView.ItemDecoration() { + @Override + public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + outRect.right = DimenUtils.dip2px(getContext(), 10); + int position = parent.getChildAdapterPosition(view); + if (position == mHotGoodsList.size() - 1) { + outRect.right = 0; + } +// super.getItemOffsets(outRect, view, parent, state); + } + }); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); + linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); + rv_hot_goods.setLayoutManager(linearLayoutManager); + return top; + } + + + private void init(View contentView) { + rv_recommend_goods = contentView.findViewById(R.id.rv_recommend_goods); + rl_first_page = contentView.findViewById(R.id.rl_first_page); + iv_slid_top = contentView.findViewById(R.id.iv_slid_top); + + View top = initHeader(); + iv_hot_img.setOnClickListener(this); ll_no_net = contentView.findViewById(R.id.ll_no_net); ll_no_data = contentView.findViewById(R.id.ll_no_data); ll_request_failture = contentView.findViewById(R.id.ll_request_failture); + contentView.findViewById(R.id.tv_net_setting).setOnClickListener(this); contentView.findViewById(R.id.tv_refresh).setOnClickListener(this); iv_slid_top.setOnClickListener(this); ll_limit_time_buy.setOnClickListener(this); ll_jinbi_exchange_buy.setOnClickListener(this); + mChangeHelper = new ConnectivityChangeHelper(ll_no_data.getContext(), new ConnectivityChangeHelper.OnConnectivityChangeListener() { @@ -349,10 +401,7 @@ } }); - //灏忛粍鏉� - tv_notice_content = top.findViewById(R.id.tv_notice_content); - ll_notice = top.findViewById(R.id.ll_notice); - iv_close = top.findViewById(R.id.iv_close); + getAppPageNotification(); //璁剧疆鍒楄〃鍙互姘村钩婊戝姩锛屼袱琛� @@ -361,9 +410,7 @@ specialAdapter2 = new RecommendCircleSpecialAdapter(getActivity(), circleSpecials); rv_special_offer.setAdapter(specialAdapter2); - seekBar = top.findViewById(R.id.slide_indicator_point); - seekBar.setPadding(0, 0, 0, 0); - seekBar.setThumbOffset(0); + // seekBar.setVisibility(View.GONE); rv_special_offer.addItemDecoration(circleSpecialItemDecoration); @@ -427,6 +474,27 @@ goodsAdapter.addHeaderView(top); initTimeHandle(); setBannerData(); + } + + + /** + * 鍒濆鍖栫儹闂ㄥ晢鍝� + */ + private void setHotGoods() { + for (TaoBaoGoodsBrief goodsBrief : mHotGoodsList) { + goodsBrief.setHasCoupon(false); + } + if (mRecommendHotGoodsAdapter == null) { + mRecommendHotGoodsAdapter = new RecommendHotGoodsAdapter(getContext(), mHotGoodsList, "jingxuan"); + rv_hot_goods.setAdapter(mRecommendHotGoodsAdapter); + } else { + rv_hot_goods.getAdapter().notifyDataSetChanged(); + } + if (mHotGoodsList.size() == 0) { + ll_hot_goods.setVisibility(View.GONE); + } else { + ll_hot_goods.setVisibility(View.VISIBLE); + } } @@ -812,6 +880,40 @@ } } } + { + //浠婃棩鐖嗘 + + DiskLruCache.Snapshot snapshot = null; + try { + snapshot = cache.get(getKey("hotSales")); + if (snapshot != null) { + final Gson gson = new GsonBuilder().serializeNulls().create(); + final JSONObject hotSales = new JSONObject(snapshot.getString(0)); + List<TaoBaoGoodsBrief> list = gson.fromJson(hotSales. + optJSONArray("goodsList").toString(), new TypeToken<List<TaoBaoGoodsBrief>>() { + }.getType()); + mHotGoodsList.clear(); + mHotGoodsList.addAll(list); + tv_hot_goods_more.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + JumpDetail jumpDetail = gson.fromJson(hotSales.optJSONObject("jumpDetail").toString(), JumpDetail.class); + com.alibaba.fastjson.JSONObject params = com.alibaba.fastjson.JSONObject.parseObject(hotSales.optJSONObject("params").toString()); + JumpActivityUtil.jumpPage(getActivity(), jumpDetail, params); + } + }); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } finally { + if (snapshot != null) { + snapshot.close(); + } + } + setHotGoods(); + } } } @@ -903,12 +1005,12 @@ sv_hot.removeCallbacks(mAutoScroller3); } - private void initSeekBar(){ - seekBar.setVisibility(circleSpecials.size() <= 8 ? View.GONE : View.VISIBLE); - if (circleSpecials.size() > 8) { + private void initSeekBar() { + seekBar.setVisibility(circleSpecials.size() <= 10 ? View.GONE : View.VISIBLE); + if (circleSpecials.size() > 10) { GradientDrawable gradientDrawable = (GradientDrawable) seekBar.getThumb(); //鏍规嵁鍒楄〃鐨勪釜鏁帮紝鍔ㄦ�佽缃父鏍囩殑澶у皬锛岃缃父鏍囩殑鏃跺�欙紝progress杩涘害鐨勯鑹茶缃负鍜宻eekbar鐨勯鑹茶缃殑涓�鏍风殑锛屾墍浠ュ氨涓嶆樉绀鸿繘搴︿簡銆� - gradientDrawable.setSize(DimenUtils.dip2px(getContext(), 50) * 4 / (circleSpecials.size() / 2) + gradientDrawable.setSize(DimenUtils.dip2px(getContext(), 50) * 5 / (circleSpecials.size() / 2) , DimenUtils.dip2px(getContext(), 4)); } } @@ -936,10 +1038,11 @@ @Override public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { if (jsonObject.optString("code").equalsIgnoreCase("0")) { + JSONObject data = jsonObject.optJSONObject("data"); isCache = false; //椤堕儴banner - Gson gson = new GsonBuilder().serializeNulls().create(); - List<HomeBanner> list1 = gson.fromJson(jsonObject.optJSONObject("data") + final Gson gson = new GsonBuilder().serializeNulls().create(); + List<HomeBanner> list1 = gson.fromJson(data .optJSONArray("topPicList").toString(), new TypeToken<List<HomeBanner>>() { }.getType()); @@ -951,12 +1054,12 @@ DiskLruCache.Editor editor0 = cache .edit(getKey("BannerAd")); - editor0.set(0, jsonObject.optJSONObject("data").optJSONArray("topPicList").toString()); + editor0.set(0, data.optJSONArray("topPicList").toString()); editor0.commit(); //鍦嗗舰涓撻 List<SpecialOffer2> list2 = gson.fromJson( - jsonObject.optJSONObject("data").optJSONObject("arcArea") + data.optJSONObject("arcArea") .optJSONArray("list").toString(), new TypeToken<List<SpecialOffer2>>() { }.getType()); @@ -975,19 +1078,19 @@ DiskLruCache.Editor editor1 = cache .edit(getKey("arcArea")); - editor1.set(0, jsonObject.optJSONObject("data").optJSONObject("arcArea") + editor1.set(0, data.optJSONObject("arcArea") .optJSONArray("list").toString()); editor1.commit(); //娲诲姩涓撻3 List<SpecialOffer2> list3 = gson.fromJson( - jsonObject.optJSONObject("data").optJSONObject("activityArea") + data.optJSONObject("activityArea") .optJSONArray("list").toString(), new TypeToken<List<SpecialOffer2>>() { }.getType()); if (mSpecial3s.size() > 0) { mSpecial3s.clear(); } - String url = jsonObject.optJSONObject("data") + String url = data .optJSONObject("activityArea").optString("bottomPicture"); showBigActivity(list3, url); @@ -998,12 +1101,12 @@ } DiskLruCache.Editor editor2 = cache .edit(getKey("activityArea")); - editor2.set(0, jsonObject.optJSONObject("data") + editor2.set(0, data .optJSONObject("activityArea").toString()); editor2.commit(); //娲诲姩涓撻4 List<HomeBanner> list4 = gson.fromJson( - jsonObject.optJSONObject("data") + data .optJSONArray("invitePicList").toString(), new TypeToken<List<HomeBanner>>() { }.getType()); @@ -1020,12 +1123,12 @@ } DiskLruCache.Editor editor3 = cache .edit(getKey("invitePicList")); - editor3.set(0, jsonObject.optJSONObject("data") + editor3.set(0, data .optJSONArray("invitePicList").toString()); editor3.commit(); //娲诲姩涓撻5 List<SpecialOffer2> list5 = gson.fromJson( - jsonObject.optJSONObject("data").optJSONObject("blockArea") + data.optJSONObject("blockArea") .optJSONArray("list").toString(), new TypeToken<List<SpecialOffer2>>() { }.getType()); @@ -1039,9 +1142,35 @@ } DiskLruCache.Editor editor4 = cache .edit(getKey("blockArea")); - editor4.set(0, jsonObject.optJSONObject("data").optJSONObject("blockArea") + editor4.set(0, data.optJSONObject("blockArea") .optJSONArray("list").toString()); editor4.commit(); + + + //浠婃棩鐖嗘 + final JSONObject hotSales = data.optJSONObject("hotSales"); + if (hotSales != null) { + List<TaoBaoGoodsBrief> list = gson.fromJson(hotSales. + optJSONArray("goodsList").toString(), new TypeToken<List<TaoBaoGoodsBrief>>() { + }.getType()); + mHotGoodsList.clear(); + mHotGoodsList.addAll(list); + tv_hot_goods_more.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + JumpDetail jumpDetail = gson.fromJson(hotSales.optJSONObject("jumpDetail").toString(), JumpDetail.class); + com.alibaba.fastjson.JSONObject params = com.alibaba.fastjson.JSONObject.parseObject(hotSales.optJSONObject("params").toString()); + JumpActivityUtil.jumpPage(getActivity(), jumpDetail, params); + } + }); + + DiskLruCache.Editor editorHotSales = cache + .edit(getKey("hotSales")); + editorHotSales.set(0, hotSales.toString()); + editorHotSales.commit(); + } + setHotGoods(); + //鎺ㄨ崘鐑偣 // RecommendHot recommendHot = gson.fromJson(jsonObject.optJSONObject("data") @@ -1160,6 +1289,7 @@ }); } + /* *鎺ㄨ崘鍟嗗搧 */ @@ -1198,6 +1328,8 @@ } mList.addAll(list); + + goodsAdapter.setGoodsType(goodsType); goodsAdapter.notifyDataSetChanged(); if (isTop) { -- Gitblit v1.8.0