From 01e23be6118d68d38a71d186296d440eadcaa197 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 07 六月 2021 18:23:41 +0800
Subject: [PATCH] 特价bug修复

---
 app/src/main/java/com/tejia/lijin/app/ui/recommend/RecommendFragment.java |   93 +++++++++++++++++++++++++++-------------------
 1 files changed, 55 insertions(+), 38 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 e28be84..8b8e147 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
@@ -6,6 +6,7 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Rect;
 import android.graphics.drawable.AnimationDrawable;
 import android.graphics.drawable.GradientDrawable;
@@ -57,6 +58,7 @@
 import com.wpc.library.RetainViewFragment;
 import com.wpc.library.content.ConnectivityChangeHelper;
 import com.wpc.library.util.NetUtils;
+import com.wpc.library.util.ScreenUtils;
 import com.wpc.library.util.SystemCommon;
 import com.wpc.library.util.cache.DiskLruCache;
 import com.wpc.library.util.common.DimenUtils;
@@ -240,7 +242,7 @@
         iv_slid_top = contentView.findViewById(R.id.iv_slid_top);
         final View top = LayoutInflater.from(rv_recommend_goods.getContext())
                 .inflate(R.layout.item_recommend_top, null);
-        top.setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E"));
+        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);
         ll_limit_time_buy = top.findViewById(R.id.ll_limit_time_buy);
@@ -362,7 +364,7 @@
         seekBar = top.findViewById(R.id.slide_indicator_point);
         seekBar.setPadding(0, 0, 0, 0);
         seekBar.setThumbOffset(0);
-        seekBar.setVisibility(View.GONE);
+//        seekBar.setVisibility(View.GONE);
 
         rv_special_offer.addItemDecoration(circleSpecialItemDecoration);
 
@@ -370,7 +372,7 @@
             @Override
             public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                 super.onScrolled(recyclerView, dx, dy);
-//                //鏄剧ず鍖哄煙鐨勯珮搴︺��
+//                //鏄剧ず鍖哄煙鐨勫銆�
                 int extent = rv_special_offer.computeHorizontalScrollExtent();
                 //鏁翠綋鐨勯珮搴︼紝娉ㄦ剰鏄暣浣擄紝鍖呮嫭鍦ㄦ樉绀哄尯鍩熶箣澶栫殑銆�
                 int range = rv_special_offer.computeHorizontalScrollRange();
@@ -699,13 +701,7 @@
                         circleSpecials.addAll(list2);
                         specialAdapter2.notifyDataSetChanged();
 
-                        if (circleSpecials.size() > 10) {
-                            GradientDrawable gradientDrawable = (GradientDrawable) seekBar.getThumb();
-                            //鏍规嵁鍒楄〃鐨勪釜鏁帮紝鍔ㄦ�佽缃父鏍囩殑澶у皬锛岃缃父鏍囩殑鏃跺�欙紝progress杩涘害鐨勯鑹茶缃负鍜宻eekbar鐨勯鑹茶缃殑涓�鏍风殑锛屾墍浠ュ氨涓嶆樉绀鸿繘搴︿簡銆�
-                            gradientDrawable.setSize(DimenUtils.dip2px(getContext(), 50) * 5 / (circleSpecials.size() / 2)
-                                    , DimenUtils.dip2px(getContext(), 4));
-                        }
-//                        seekBar.setVisibility(mSpecial2s.size() <= 10 ? View.GONE : View.VISIBLE);
+                        initSeekBar();
 
                         if (list2 == null || list2.size() == 0) {
                             rv_special_offer.setVisibility(View.GONE);
@@ -907,6 +903,16 @@
         sv_hot.removeCallbacks(mAutoScroller3);
     }
 
+    private void initSeekBar(){
+        seekBar.setVisibility(circleSpecials.size() <= 8 ? View.GONE : View.VISIBLE);
+        if (circleSpecials.size() > 8) {
+            GradientDrawable gradientDrawable = (GradientDrawable) seekBar.getThumb();
+            //鏍规嵁鍒楄〃鐨勪釜鏁帮紝鍔ㄦ�佽缃父鏍囩殑澶у皬锛岃缃父鏍囩殑鏃跺�欙紝progress杩涘害鐨勯鑹茶缃负鍜宻eekbar鐨勯鑹茶缃殑涓�鏍风殑锛屾墍浠ュ氨涓嶆樉绀鸿繘搴︿簡銆�
+            gradientDrawable.setSize(DimenUtils.dip2px(getContext(), 50) * 4 / (circleSpecials.size() / 2)
+                    , DimenUtils.dip2px(getContext(), 4));
+        }
+    }
+
 
     private void setGoodsIndex() {
         if (pd == null) {
@@ -959,13 +965,7 @@
                     }
                     circleSpecials.addAll(list2);
                     specialAdapter2.notifyDataSetChanged();
-//                    seekBar.setVisibility(mSpecial2s.size() <= 10 ? View.GONE : View.VISIBLE);
-                    if (circleSpecials.size() > 10) {
-                        GradientDrawable gradientDrawable = (GradientDrawable) seekBar.getThumb();
-                        //鏍规嵁鍒楄〃鐨勪釜鏁帮紝鍔ㄦ�佽缃父鏍囩殑澶у皬锛岃缃父鏍囩殑鏃跺�欙紝progress杩涘害鐨勯鑹茶缃负鍜宻eekbar鐨勯鑹茶缃殑涓�鏍风殑锛屾墍浠ュ氨涓嶆樉绀鸿繘搴︿簡銆�
-                        gradientDrawable.setSize(DimenUtils.dip2px(getContext(), 50) * 5 / (circleSpecials.size() / 2)
-                                , DimenUtils.dip2px(getContext(), 4));
-                    }
+                    initSeekBar();
                     if (list2 == null || list2.size() == 0) {
                         rv_special_offer.setVisibility(View.GONE);
                     } else {
@@ -1029,6 +1029,7 @@
                                     .optJSONArray("list").toString(),
                             new TypeToken<List<SpecialOffer2>>() {
                             }.getType());
+                    list5.clear();
                     showActivity2(list5);
 
                     if (list5 == null || list5.size() == 0) {
@@ -1207,7 +1208,6 @@
 //                    goodsAdapter.notifyItemRangeChanged(goodsAdapter.getItemCount(), list.size());//鍊掑簭鎵归噺鍒锋柊鍒楄〃
                     count = jsonObject.optJSONObject("data").optInt("count");
 //                    tv_recommend_goods_hint.setVisibility(mList.size() > 0 ? View.VISIBLE : View.GONE);
-                    v_divider.setVisibility(mList.size() > 0 ? View.VISIBLE : View.GONE);
 
                     if (mList.size() == count) {
                         bottom.setVisibility(View.VISIBLE);
@@ -1284,27 +1284,36 @@
      */
     private void showBigActivity(final List<SpecialOffer2> mList, String bottomPic) {
         if (mList.size() > 0) {
-            float screenWidth = SystemCommon.getScreenWidth(vp_banner.getContext());
-            float actTotalHeight = (screenWidth - DimenUtils.dip2px(getContext(), 20)) * 7 / 20;
+            int screenWidth = ScreenUtils.getScreenWidth(getContext());
+            ViewGroup.MarginLayoutParams p1 = (ViewGroup.MarginLayoutParams) ((View) fl_fragment_activity.getParent()).getLayoutParams();
+
+            float bigratio = 0.35f;
+            float smallratio = 0.4571f;
+            int rowSpace = DimenUtils.dip2px(getContext(), 10);
+            int columnSpace = DimenUtils.dip2px(getContext(), 5);
+            int bigImageWidth = screenWidth - p1.leftMargin - p1.rightMargin;
+            int bigImageHeight = (int) (bigImageWidth * bigratio);
+            int smallImageWidth = (bigImageWidth - columnSpace) / 2;
+            int smallImageHeight = (int) (smallImageWidth * smallratio);
+
+
+            int actTotalHeight = bigImageHeight + rowSpace;
             for (int i = 0; i < mList.size(); i++) {
                 if (i > 0 && i % 2 == 0) {
-                    actTotalHeight += ((screenWidth / 2 - DimenUtils.dip2px(getContext(), 15))
-                            * 16 / 35 + DimenUtils.dip2px(getContext(), 10));
+                    actTotalHeight += smallImageHeight + rowSpace;
                 }
             }
-            FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams((int) (screenWidth -
-                    DimenUtils.dip2px(getContext(), 20)), (int) actTotalHeight);
+            FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams(bigImageWidth, FrameLayout.LayoutParams.WRAP_CONTENT);
             params0.leftMargin = DimenUtils.dip2px(getContext(), 0);
             params0.rightMargin = DimenUtils.dip2px(getContext(), 0);
             params0.topMargin = DimenUtils.dip2px(getContext(), 15);
-            params0.bottomMargin = DimenUtils.dip2px(getContext(), 10);
             ll_fragment_activity.setLayoutParams(params0);
             if (ll_fragment_activity.getChildCount() > 0) {
                 ll_fragment_activity.removeAllViews();
             }
 
-            iv_activity_bg.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams
-                    .MATCH_PARENT, (int) actTotalHeight + DimenUtils.dip2px(getContext(), 25)));
+//            iv_activity_bg.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams
+//                    .MATCH_PARENT, (int) actTotalHeight + DimenUtils.dip2px(getContext(), 25)));
 //            Glide.with(getContext()).load(bottomPic).into(iv_activity_bg);
 
             for (int i = 0; i < mList.size(); i++) {
@@ -1312,8 +1321,8 @@
                     final SpecialOffer2 info = mList.get(i);
                     ImageView iv = new ImageView(getContext());
                     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
-                            (int) (screenWidth - DimenUtils.dip2px(getContext(), 20)),
-                            (int) (screenWidth - DimenUtils.dip2px(getContext(), 20)) * 7 / 20);
+                            bigImageWidth,
+                            bigImageHeight);
                     params.gravity = Gravity.TOP;
                     iv.setLayoutParams(params);
                     iv.setScaleType(ImageView.ScaleType.FIT_XY);
@@ -1330,6 +1339,9 @@
                 } else {
                     if (i % 2 == 1) {
                         LinearLayout ll_img = new LinearLayout(getContext());
+                        LinearLayout.LayoutParams p2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
+                        p2.topMargin = rowSpace;
+                        ll_img.setLayoutParams(p2);
                         ll_img.setOrientation(LinearLayout.HORIZONTAL);
                         for (int j = i; j < (i + 2); j++) {
                             if (j >= mList.size()) {
@@ -1337,15 +1349,13 @@
                             }
 
                             ImageView iv = new ImageView(getContext());
-                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int) screenWidth / 2 -
-                                    (DimenUtils.dip2px(getContext(), 15)), (int) ((screenWidth / 2 -
-                                    (DimenUtils.dip2px(getContext(), 15))) * 16 / 35));
-                            params.topMargin = DimenUtils.dip2px(getContext(), 10);
-                            if (j % 2 == 1) {
-                                params.rightMargin = DimenUtils.dip2px(getContext(), 3);
-                            } else {
-                                params.leftMargin = DimenUtils.dip2px(getContext(), 3);
-                            }
+                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(smallImageWidth, smallImageHeight);
+
+//                            if (j % 2 == 1) {
+//                                params.rightMargin = columnSpace / 2;
+//                            } else {
+//                                params.leftMargin = columnSpace / 2;
+//                            }
                             iv.setLayoutParams(params);
                             Glide.with(getContext()).load(mList.get(j).getPicture()).into(iv);
                             final int k = j;
@@ -1357,6 +1367,13 @@
                                 }
                             });
                             ll_img.addView(iv);
+                            if (j % 2 == 1) {
+                                View view = new View(getContext());
+                                LinearLayout.LayoutParams p3 = new LinearLayout.LayoutParams(0, 1);
+                                p3.weight = 1;
+                                view.setLayoutParams(p3);
+                                ll_img.addView(view);
+                            }
                         }
                         ll_fragment_activity.addView(ll_img);
                     }

--
Gitblit v1.8.0