| | |
| | | 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; |
| | |
| | | import com.tejia.lijin.app.BasicTextHttpResponseHandler; |
| | | import com.tejia.lijin.app.R; |
| | | import com.tejia.lijin.app.ShoppingApi; |
| | | import com.tejia.lijin.app.ShoppingApplication; |
| | | import com.tejia.lijin.app.entity.FirstCategory; |
| | | import com.tejia.lijin.app.entity.HomeBanner; |
| | | import com.tejia.lijin.app.entity.JumpDetail; |
| | |
| | | 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; |
| | |
| | | */ |
| | | |
| | | public class RecommendFragment extends RetainViewFragment implements View.OnClickListener { |
| | | private static final String TAG = "RecommendFragment"; |
| | | private LinearLayout ll_fragment_activity, ll_special_offer, ll_limit_time_buy, ll_jinbi_exchange_buy; |
| | | private MyGridView gv_limit_time_goods, gv_jinbi_exchange_goods; |
| | | private SwipeRefreshLayout rl_first_page; |
| | |
| | | super.getItemOffsets(outRect, view, parent, state); |
| | | int index = parent.getChildAdapterPosition(view); |
| | | int total = parent.getAdapter().getItemCount(); |
| | | int minWidth = DimenUtils.dipToPixels(6, view.getContext()); |
| | | if (index % 4 == 0) { |
| | | outRect.left = 0; //第一列左边贴边 |
| | | outRect.right = minWidth * 3; |
| | | } else if (index % 4 == 1) { |
| | | outRect.left = minWidth * 1; |
| | | outRect.right = minWidth * 2; |
| | | } else if (index % 4 == 2) { |
| | | outRect.left = minWidth * 2; |
| | | outRect.right = minWidth * 1; |
| | | int space = RecommendCircleSpecialAdapter.SPCAE_DP; |
| | | |
| | | if (index % 2 == 0) { |
| | | outRect.bottom = DimenUtils.dipToPixels(space, view.getContext()); |
| | | Log.i(TAG, circleSpecials.get(index).getName()); |
| | | } else |
| | | outRect.bottom = 0; |
| | | |
| | | |
| | | if ((index == total - 1) || (index == total - 2 && total % 2 == 0)) { |
| | | outRect.right = 0; |
| | | } else { |
| | | outRect.right = 0; //第一列左边贴边 |
| | | outRect.left = minWidth * 3; |
| | | } |
| | | |
| | | int lastRow = total / 4; |
| | | |
| | | if (lastRow != index / 4) { |
| | | outRect.bottom = minWidth * 4; |
| | | outRect.right = DimenUtils.dipToPixels(space, view.getContext()); |
| | | } |
| | | } |
| | | }; |
| | |
| | | if (last == total - 1 && mList.size() < count && isLoad) { |
| | | page++; |
| | | isLoad = false; |
| | | tv_loading.setText("正在加载更多数据"); |
| | | tv_loading.setText(getResources().getString(R.string.loading_more_text)); |
| | | iv_loading.setVisibility(View.VISIBLE); |
| | | guessLikeByDevice(); |
| | | } |
| | |
| | | getAppPageNotification(); |
| | | |
| | | //设置列表可以水平滑动,两行 |
| | | GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 4, GridLayoutManager.VERTICAL, false) { |
| | | @Override |
| | | public boolean canScrollVertically() { |
| | | return false; |
| | | } |
| | | }; |
| | | GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 2, GridLayoutManager.HORIZONTAL, false); |
| | | rv_special_offer.setLayoutManager(layoutManager); |
| | | 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); |
| | | // seekBar.setVisibility(View.GONE); |
| | | |
| | | rv_special_offer.addItemDecoration(circleSpecialItemDecoration); |
| | | |
| | |
| | | @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(); |
| | |
| | | circleSpecials.addAll(list2); |
| | | specialAdapter2.notifyDataSetChanged(); |
| | | |
| | | if (circleSpecials.size() > 10) { |
| | | GradientDrawable gradientDrawable = (GradientDrawable) seekBar.getThumb(); |
| | | //根据列表的个数,动态设置游标的大小,设置游标的时候,progress进度的颜色设置为和seekbar的颜色设置的一样的,所以就不显示进度了。 |
| | | 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); |
| | |
| | | } else { |
| | | fl_fragment_activity.setVisibility(View.VISIBLE); |
| | | } |
| | | showActivity1(list3, url); |
| | | showBigActivity(list3, url); |
| | | } |
| | | |
| | | } |
| | |
| | | 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进度的颜色设置为和seekbar的颜色设置的一样的,所以就不显示进度了。 |
| | | gradientDrawable.setSize(DimenUtils.dip2px(getContext(), 50) * 4 / (circleSpecials.size() / 2) |
| | | , DimenUtils.dip2px(getContext(), 4)); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void setGoodsIndex() { |
| | | if (pd == null) { |
| | |
| | | && mList.size() == 0) { |
| | | pd.show(); |
| | | } |
| | | String uid = getContext().getSharedPreferences("user", MODE_PRIVATE).getString("uid", ""); |
| | | ShoppingApi.getRecommendIndex(vp_banner.getContext(), uid, new BasicTextHttpResponseHandler() { |
| | | ShoppingApi.getRecommendIndex(vp_banner.getContext(), UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | |
| | | } |
| | | circleSpecials.addAll(list2); |
| | | specialAdapter2.notifyDataSetChanged(); |
| | | // seekBar.setVisibility(mSpecial2s.size() <= 10 ? View.GONE : View.VISIBLE); |
| | | if (circleSpecials.size() > 10) { |
| | | GradientDrawable gradientDrawable = (GradientDrawable) seekBar.getThumb(); |
| | | //根据列表的个数,动态设置游标的大小,设置游标的时候,progress进度的颜色设置为和seekbar的颜色设置的一样的,所以就不显示进度了。 |
| | | 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 { |
| | |
| | | String url = jsonObject.optJSONObject("data") |
| | | .optJSONObject("activityArea").optString("bottomPicture"); |
| | | |
| | | showActivity1(list3, url); |
| | | showBigActivity(list3, url); |
| | | if (list3 == null || list3.size() == 0) { |
| | | fl_fragment_activity.setVisibility(View.GONE); |
| | | } else { |
| | |
| | | .optJSONArray("list").toString(), |
| | | new TypeToken<List<SpecialOffer2>>() { |
| | | }.getType()); |
| | | list5.clear(); |
| | | showActivity2(list5); |
| | | |
| | | if (list5 == null || list5.size() == 0) { |
| | |
| | | // 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); |
| | |
| | | }); |
| | | } |
| | | |
| | | /* |
| | | 活动专题3 |
| | | |
| | | /** |
| | | * 大活动专题 |
| | | * |
| | | * @param mList |
| | | * @param bottomPic |
| | | */ |
| | | private void showActivity1(final List<SpecialOffer2> mList, String bottomPic) { |
| | | 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); |
| | | params0.leftMargin = DimenUtils.dip2px(getContext(), 10); |
| | | params0.rightMargin = DimenUtils.dip2px(getContext(), 10); |
| | | 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))); |
| | | Glide.with(getContext()).load(bottomPic).into(iv_activity_bg); |
| | | // 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++) { |
| | | if (i == 0) { |
| | | 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.CENTER_CROP); |
| | | iv.setScaleType(ImageView.ScaleType.FIT_XY); |
| | | |
| | | Glide.with(getContext()).load(info.getPicture()).into(iv); |
| | | iv.setOnClickListener(new View.OnClickListener() { |
| | |
| | | } 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()) { |
| | |
| | | } |
| | | |
| | | 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; |
| | |
| | | } |
| | | }); |
| | | 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); |
| | | } |