Explorar o código

2024-5-11 代码备份
首页bannerUI开发完成
首页中部导航视图UI开发完成
365专区UI开发完成
首页商品列表UI开发完成

zhangbing %!s(int64=2) %!d(string=hai) anos
pai
achega
fab668eb20

+ 0 - 1
.idea/gradle.xml

@@ -19,6 +19,5 @@
19 19
         </option>
20 20
       </GradleProjectSettings>
21 21
     </option>
22
-    <option name="offlineMode" value="true" />
23 22
   </component>
24 23
 </project>

+ 12 - 5
app/src/main/java/com/yihucha/hbyhc/presentation/home/HomeFragment.java

@@ -3,6 +3,7 @@ package com.yihucha.hbyhc.presentation.home;
3 3
 import android.app.Activity;
4 4
 import android.content.Context;
5 5
 import android.content.Intent;
6
+import android.graphics.Color;
6 7
 import android.net.Uri;
7 8
 import android.os.Bundle;
8 9
 import android.os.CountDownTimer;
@@ -82,7 +83,7 @@ HomeFragment extends BaseFragment implements View.OnClickListener {
82 83
 
83 84
     private List<HomeProductBean.PageInfoDTO.ListDTO> homeProductListBeans = new ArrayList<>();
84 85
     private HomeProductListAdapter homeProductListAdapter;
85
-
86
+    private boolean isScrolled = false;
86 87
     //秒杀商品
87 88
     private HomeMSAdapter adapter;
88 89
     private HomeVipAdapter adapterVip;
@@ -204,7 +205,7 @@ HomeFragment extends BaseFragment implements View.OnClickListener {
204 205
             adapterVip.setDatas(data);
205 206
         });
206 207
 
207
-        seckillViewModel.getDcSeckill();
208
+//        seckillViewModel.getDcSeckill(); //秒杀模块隐藏掉
208 209
         seckillViewModel.mDcSeckillBean.observe(getViewLifecycleOwner(), dcSeckillBeans -> {
209 210
             if (dcSeckillBeans == null || dcSeckillBeans.size() == 0) {
210 211
                 binding.layoutSeckill.setVisibility(View.GONE);
@@ -450,15 +451,21 @@ HomeFragment extends BaseFragment implements View.OnClickListener {
450 451
     private void showHeaderAlphaAction(int y) {
451 452
         final int rootPicHeight = binding.headView.viewTop.getHeight();
452 453
         if (y <= rootPicHeight) {
453
-            binding.headView.viewHeaderBg.setBackgroundResource(R.mipmap.home_top_bg_scroll);
454 454
             //状态栏深色模式
455 455
             binding.tvScrollTop.setVisibility(View.GONE);
456
+            isScrolled = false;
456 457
         } else {
457 458
             binding.tvScrollTop.setVisibility(View.VISIBLE);
458
-            binding.headView.viewHeaderBg.setBackgroundResource(R.mipmap.home_top_bg);
459
+            isScrolled = true;
459 460
         }
461
+        setTitleColor();
462
+    }
463
+    private void setTitleColor(){
464
+        binding.headView.btvName.setTextColor(!isScrolled?Color.WHITE:Color.parseColor("#333333"));
465
+        binding.headView.tvMessage.setTextColor(!isScrolled?Color.WHITE:Color.parseColor("#333333"));
466
+        binding.headView.viewTop.setVisibility(isScrolled?View.VISIBLE:View.INVISIBLE);
467
+        binding.headView.viewHeaderBg.setVisibility(isScrolled?View.VISIBLE:View.INVISIBLE);
460 468
     }
461
-
462 469
     @Override
463 470
     public void onAttach(@NonNull Context context) {
464 471
         super.onAttach(context);

+ 605 - 0
app/src/main/java/com/yihucha/hbyhc/presentation/home/HomeFragment_copy.java

@@ -0,0 +1,605 @@
1
+package com.yihucha.hbyhc.presentation.home;
2
+
3
+import android.app.Activity;
4
+import android.content.Context;
5
+import android.content.Intent;
6
+import android.net.Uri;
7
+import android.os.Bundle;
8
+import android.os.CountDownTimer;
9
+import android.os.Handler;
10
+import android.util.Log;
11
+import android.view.LayoutInflater;
12
+import android.view.View;
13
+import android.view.ViewGroup;
14
+import android.widget.Toast;
15
+
16
+import androidx.annotation.NonNull;
17
+import androidx.annotation.Nullable;
18
+import androidx.core.content.ContextCompat;
19
+import androidx.core.widget.NestedScrollView;
20
+import androidx.lifecycle.Observer;
21
+import androidx.lifecycle.ViewModelProvider;
22
+import androidx.recyclerview.widget.DividerItemDecoration;
23
+import androidx.recyclerview.widget.GridLayoutManager;
24
+import androidx.recyclerview.widget.LinearLayoutManager;
25
+import androidx.recyclerview.widget.RecyclerView;
26
+
27
+import com.bumptech.glide.Glide;
28
+import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
29
+import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
30
+import com.yihucha.hbyhc.R;
31
+import com.yihucha.hbyhc.base.BaseFragment;
32
+import com.yihucha.hbyhc.config.Constants;
33
+import com.yihucha.hbyhc.databinding.FragmentHomeBinding;
34
+import com.yihucha.hbyhc.network.DataResponse;
35
+import com.yihucha.hbyhc.presentation.MainActivity;
36
+import com.yihucha.hbyhc.presentation.annuity.AnnuityActivity;
37
+import com.yihucha.hbyhc.presentation.big_storehouse.DacangSeckillActivity;
38
+import com.yihucha.hbyhc.presentation.big_storehouse.adapter.HomeMSAdapter;
39
+import com.yihucha.hbyhc.presentation.big_storehouse.adapter.HomeVipAdapter;
40
+import com.yihucha.hbyhc.presentation.big_storehouse.model.DcSeckillBean;
41
+import com.yihucha.hbyhc.presentation.big_storehouse.view_model.BigWarehouseViewModel;
42
+import com.yihucha.hbyhc.presentation.home.adapter.HomeImageAdapter;
43
+import com.yihucha.hbyhc.presentation.home.adapter.HomeProductListAdapter;
44
+import com.yihucha.hbyhc.presentation.home.model.BannerDataBean;
45
+import com.yihucha.hbyhc.presentation.home.model.HomeProductBean;
46
+import com.yihucha.hbyhc.presentation.home.view_model.HomeViewModel;
47
+import com.yihucha.hbyhc.presentation.members.AGuestMemberActivity;
48
+import com.yihucha.hbyhc.presentation.message.MessageActivity;
49
+import com.yihucha.hbyhc.presentation.mine.model.UserInfoModel;
50
+import com.yihucha.hbyhc.presentation.product.ProductDetailsActivity;
51
+import com.yihucha.hbyhc.presentation.shop.VipAreaActivity;
52
+import com.yihucha.hbyhc.presentation.shop.model.VipAreaBean;
53
+import com.yihucha.hbyhc.presentation.shop.view_model.VipAreaViewModel;
54
+import com.yihucha.hbyhc.utils.GlideUtils;
55
+import com.yihucha.hbyhc.utils.ImmersedStatusbarUtils;
56
+import com.yihucha.hbyhc.utils.LogUtil;
57
+import com.yihucha.hbyhc.utils.LoginUtils;
58
+import com.yihucha.hbyhc.utils.MVUtils;
59
+import com.yihucha.hbyhc.utils.StringsUtil;
60
+import com.yihucha.hbyhc.utils.TimeUtils;
61
+import com.yihucha.hbyhc.view.MyToast;
62
+import com.youth.banner.indicator.CircleIndicator;
63
+import com.youth.banner.listener.OnBannerListener;
64
+
65
+import java.util.ArrayList;
66
+import java.util.List;
67
+
68
+import qiu.niorgai.StatusBarCompat;
69
+
70
+public class HomeFragment_copy extends BaseFragment {
71
+    /*private FragmentHomeBinding binding;
72
+
73
+    private HomeViewModel homeViewModel;
74
+    private BigWarehouseViewModel seckillViewModel;
75
+    private VipAreaViewModel vipAreaViewModel;
76
+
77
+    private List<HomeProductBean.PageInfoDTO.ListDTO> homeProductListBeans = new ArrayList<>();
78
+    private HomeProductListAdapter homeProductListAdapter;
79
+    private boolean isScrolled = false;
80
+    //秒杀商品
81
+    private HomeMSAdapter adapter;
82
+    private HomeVipAdapter adapterVip;
83
+    private List<DcSeckillBean.Product_data> seckillBeans = new ArrayList<>();
84
+    private List<VipAreaBean.ListDTO> vipBeans = new ArrayList<>();
85
+    private int mPage = 1;
86
+    private String mer_keyword = "1";
87
+    private String isNew = "0";
88
+    private String priceType = "1";
89
+    private String sales = "0";
90
+
91
+    private boolean isPriceUp = false;
92
+    private boolean isSalesUp = false;
93
+
94
+    //正在滚动
95
+    public static final int SCROLL_STATE_IDLE = 0;
96
+
97
+    //正在被外部拖拽,一般为用户正在用手指滚动
98
+    public static final int SCROLL_STATE_DRAGGING = 1;
99
+
100
+    //自动滚动开始
101
+    public static final int SCROLL_STATE_SETTLING = 2;
102
+    private CountDownTimer timer;
103
+
104
+    @Override
105
+    public void onCreate(@Nullable Bundle savedInstanceState) {
106
+        super.onCreate(savedInstanceState);
107
+        //状态栏深色模式
108
+        StatusBarCompat.changeToLightStatusBar(getActivity());
109
+    }
110
+
111
+    public View onCreateView(@NonNull LayoutInflater inflater,
112
+                             ViewGroup container, Bundle savedInstanceState) {
113
+
114
+        homeViewModel =
115
+                new ViewModelProvider(this).get(HomeViewModel.class);
116
+        seckillViewModel =
117
+                new ViewModelProvider(this).get(BigWarehouseViewModel.class);
118
+        vipAreaViewModel =
119
+                new ViewModelProvider(this).get(VipAreaViewModel.class);
120
+
121
+
122
+        binding = FragmentHomeBinding.inflate(inflater, container, false);
123
+        View root = binding.getRoot();
124
+        ImmersedStatusbarUtils.initAfterSetContentView(getActivity(), binding.viewOccupy);
125
+        initView();
126
+        initClick();
127
+        initApi();
128
+        return root;
129
+    }
130
+
131
+    @Override
132
+    public void onResume() {
133
+        super.onResume();
134
+        initData();
135
+    }
136
+
137
+
138
+    private void initClick() {
139
+        binding.headView.rlTop.setOnClickListener(this);
140
+        binding.headView.llSearch.setOnClickListener(this);
141
+        binding.headView.ivMessage.setOnClickListener(this);
142
+        binding.headView.tvMessage.setOnClickListener(this);
143
+        binding.tvGetMore.setOnClickListener(this);
144
+        binding.tvBuyNow.setOnClickListener(this);
145
+        homeProductListAdapter.setOnClickListener(position -> ProductDetailsActivity.launch(getActivity(),
146
+                homeProductListBeans.get(position).getProduct_id() + ""));
147
+        binding.tvScrollTop.setOnClickListener(this);
148
+
149
+        binding.llRecommend.setOnClickListener(this);
150
+        binding.llSearchUpdate.setOnClickListener(this);
151
+        binding.llSearchSales.setOnClickListener(this);
152
+        binding.llSearchPrice.setOnClickListener(this);
153
+        binding.headView.ivMessage.setOnClickListener(this);
154
+        binding.headView.tvMessage.setOnClickListener(this);
155
+
156
+    }
157
+
158
+    private void initApi() {
159
+        //商品列表
160
+        homeViewModel.getHomeProductListData(mPage, mer_keyword, isNew, priceType, sales);
161
+        //网络发生错误
162
+        homeViewModel.failed.observe(getActivity(), s -> MyToast.makeText(getContext(), s, Toast.LENGTH_LONG).show());
163
+        //商品列表请求成功
164
+        homeViewModel.homeProductListDataYHC.observe(getActivity(), data -> {
165
+            if (data == null || data.size() == 0) {
166
+                if (mPage > 1) {
167
+                    mPage -= 1;
168
+                }
169
+                return;
170
+            }
171
+            if (mPage == 1) {
172
+                homeProductListBeans.clear();
173
+            }
174
+            homeProductListBeans.addAll(data);
175
+            homeProductListAdapter.setData(homeProductListBeans);
176
+        });
177
+        //用户信息
178
+        homeViewModel.userModel.observe(getActivity(), new Observer<UserInfoModel>() {
179
+            @Override
180
+            public void onChanged(UserInfoModel uesrInfoMpdel) {
181
+                Log.i("qmz", "235");
182
+                GlideUtils.loadCircleImage(getActivity(), uesrInfoMpdel.getAvatar(), binding.headView.ivHead, R.mipmap.home_default_avatar_220614);
183
+                binding.headView.btvName.setText(uesrInfoMpdel.getNickname());
184
+            }
185
+        });
186
+
187
+        homeViewModel.getBannerData();
188
+        getBanner();
189
+
190
+        vipAreaViewModel.requestData(1, 10, "");
191
+        vipAreaViewModel.vipAreaData.observe(getViewLifecycleOwner(), data -> {
192
+            if (data == null || data.size() == 0) {
193
+                binding.layoutVip.setVisibility(View.GONE);
194
+                return;
195
+            }else {
196
+                binding.layoutVip.setVisibility(View.VISIBLE);
197
+            }
198
+            adapterVip.setDatas(data);
199
+        });
200
+
201
+        seckillViewModel.getDcSeckill();
202
+        seckillViewModel.mDcSeckillBean.observe(getViewLifecycleOwner(), dcSeckillBeans -> {
203
+            if (dcSeckillBeans == null || dcSeckillBeans.size() == 0) {
204
+                binding.layoutSeckill.setVisibility(View.GONE);
205
+                return;
206
+            }
207
+            setMS(dcSeckillBeans);
208
+        });
209
+        seckillViewModel.failed.observe(getViewLifecycleOwner(), new Observer<String>() {
210
+            @Override
211
+            public void onChanged(String s) {
212
+                binding.layoutSeckill.setVisibility(View.GONE);
213
+            }
214
+        });
215
+    }
216
+
217
+    //设置秒杀的显示状态
218
+    private void setMS(List<DcSeckillBean> dcSeckillBeans) {
219
+        int usePos = -1;
220
+        for (int i = 0; i < dcSeckillBeans.size(); i++) {
221
+            //找秒杀中或者下一场秒杀的数据
222
+            if (dcSeckillBeans.get(i).getStatus() == 1 || dcSeckillBeans.get(i).getStatus() == 2) {
223
+                usePos = i;
224
+                break;
225
+            }
226
+        }
227
+        if (usePos == -1) {
228
+            binding.layoutSeckill.setVisibility(View.GONE);
229
+            return;
230
+        }else {
231
+            binding.layoutSeckill.setVisibility(View.VISIBLE);
232
+        }
233
+        //数据
234
+        DcSeckillBean dcSeckillBean = dcSeckillBeans.get(usePos);
235
+        List<DcSeckillBean.Product_data> product_data = dcSeckillBean.getProduct_data();
236
+        if (product_data == null || product_data.size() < 1) {
237
+            binding.layoutSeckill.setVisibility(View.GONE);
238
+            return;
239
+        }
240
+        binding.layoutSeckill.setVisibility(View.VISIBLE);
241
+        seckillBeans.clear();
242
+        seckillBeans.addAll(product_data);
243
+        adapter.setDatas(seckillBeans);
244
+        if (dcSeckillBean.getStatus() == 1) {
245
+            //正在秒杀
246
+            binding.layoutTime.setVisibility(View.VISIBLE);
247
+            if (TimeUtils.init(dcSeckillBean.getSeckill_date())) {
248
+                long timeLong = TimeUtils.getTimeLong();
249
+                timer = new CountDownTimer(timeLong, 1000) {
250
+                    @Override
251
+                    public void onTick(long l) {
252
+                        long timeHour = StringsUtil.getHour(l);
253
+                        binding.tvHours.setText(timeHour >= 10 ? timeHour + "" : "0" + timeHour);
254
+                        long timeMinute = StringsUtil.getMinute(l);
255
+                        binding.tvMinute.setText(timeMinute >= 10 ? timeMinute + "" : "0" + timeMinute);
256
+                        long timeSecond = StringsUtil.getSecond(l);
257
+                        binding.tvSencond.setText(timeSecond >= 10 ? timeSecond + "" : "0" + timeSecond);
258
+                    }
259
+
260
+                    @Override
261
+                    public void onFinish() {
262
+                        timer.cancel();
263
+                        //重新加载秒杀数据
264
+                        seckillViewModel.getDcSeckill();
265
+                    }
266
+                };
267
+                timer.start();
268
+            }
269
+        } else {
270
+            //即将开始
271
+            binding.layoutTime.setVisibility(View.GONE);
272
+        }
273
+    }
274
+
275
+    private void initData() {
276
+
277
+        if (!"".equals(MVUtils.getString(Constants.TOKEN))) {
278
+            //用户信息
279
+            homeViewModel.getUserInfo();
280
+        }
281
+
282
+//养老金
283
+        *//*if (!"".equals(MVUtils.getString(Constants.TOKEN))) {
284
+            homeViewModel.getYanglaojin();
285
+        }*//*
286
+    }
287
+
288
+    private void initView() {
289
+        binding.scrollview.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
290
+            @Override
291
+            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
292
+                LogUtil.LogError("fjy", "222");
293
+                showHeaderAlphaAction(scrollY);
294
+            }
295
+        });
296
+        //会员专区
297
+        LinearLayoutManager layoutManagerVip = new LinearLayoutManager(getActivity()
298
+                , LinearLayoutManager.HORIZONTAL, false);
299
+        binding.rvVip.setLayoutManager(layoutManagerVip);
300
+        binding.rvVip.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.HORIZONTAL));
301
+        adapterVip = new HomeVipAdapter(vipBeans, getActivity());
302
+        binding.rvVip.setAdapter(adapterVip);
303
+
304
+//        //布局 秒杀
305
+        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()
306
+                , LinearLayoutManager.HORIZONTAL, false);
307
+        binding.rvMiaosha.setLayoutManager(layoutManager);
308
+        binding.rvMiaosha.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.HORIZONTAL));
309
+        adapter = new HomeMSAdapter(seckillBeans, getActivity());
310
+        binding.rvMiaosha.setAdapter(adapter);
311
+
312
+        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
313
+        binding.rvHomeList.setLayoutManager(gridLayoutManager);
314
+        homeProductListAdapter = new HomeProductListAdapter(getActivity(), homeProductListBeans);
315
+        //给RecyclerView设置适配器
316
+        binding.rvHomeList.setAdapter(homeProductListAdapter);
317
+
318
+        binding.refreshLayout.setAutoLoadMore(true);
319
+
320
+        binding.refreshLayout.setOverScrollRefreshShow(false);
321
+        //刷新
322
+        binding.refreshLayout.setOnRefreshListener(new RefreshListenerAdapter() {
323
+            @Override
324
+            public void onPullUpReleasing(TwinklingRefreshLayout refreshLayout, float fraction) {
325
+                super.onPullUpReleasing(refreshLayout, fraction);
326
+                LogUtil.LogInfo("qmzzzzz", "上拉释放过程" + fraction);
327
+                if (fraction == 0.0) {
328
+                    new Handler().postDelayed(new Runnable() {
329
+                        @Override
330
+                        public void run() {
331
+                            mPage++;
332
+                            homeViewModel.getHomeProductListData(mPage, mer_keyword, isNew, priceType, sales);
333
+                        }
334
+                    }, 1000);
335
+                }
336
+            }
337
+
338
+            @Override
339
+            public void onPullDownReleasing(TwinklingRefreshLayout refreshLayout, float fraction) {
340
+                super.onPullDownReleasing(refreshLayout, fraction);
341
+                if (fraction == 0.0) {
342
+                    seckillViewModel.getDcSeckill();
343
+                }
344
+            }
345
+
346
+            @Override
347
+            public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
348
+
349
+
350
+            }
351
+
352
+            @Override
353
+            public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {
354
+            }
355
+        });
356
+
357
+        binding.rvHomeList.addOnScrollListener(new RecyclerView.OnScrollListener() {
358
+            @Override
359
+            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
360
+                super.onScrollStateChanged(recyclerView, newState);
361
+//                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
362
+                //停止滚动时才加载图片,可以很大的提升流畅度
363
+                if (newState == SCROLL_STATE_IDLE) {
364
+                    Glide.with(getActivity()).resumeRequests();
365
+                } else {
366
+                    Glide.with(getActivity()).pauseRequests();
367
+
368
+                }
369
+            }
370
+
371
+            @Override
372
+            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
373
+                super.onScrolled(recyclerView, dx, dy);
374
+                LogUtil.LogInfo("qmzzz", dy + "" + dx);
375
+
376
+            }
377
+        });
378
+    }
379
+
380
+    private void getBanner() {
381
+        homeViewModel.bannerData.observe(getActivity(), new Observer<DataResponse<List<BannerDataBean>>>() {
382
+            @Override
383
+            public void onChanged(DataResponse<List<BannerDataBean>> listDataResponse) {
384
+                HomeImageAdapter imageAdapter = new HomeImageAdapter(getActivity(), listDataResponse.getData());
385
+                //加载本地图片
386
+                binding.bannerHome.setAdapter(imageAdapter)
387
+                        .addBannerLifecycleObserver(getActivity())
388
+                        .setIndicator(new CircleIndicator(getContext()), false)
389
+                        .setOnBannerListener(new OnBannerListener() {
390
+                            @Override
391
+                            public void OnBannerClick(Object data, int position) {
392
+//                                if (LoginUtils.isLogin(getContext())) {
393
+                                if (listDataResponse.getData().get(position).getUrl().equals(Constants.JINKA)) {
394
+                                    //金卡
395
+
396
+//                                    DacangMemberActivity.launch(getActivity(), "2");
397
+                                    AGuestMemberActivity.launch(getActivity());
398
+                                } else if (listDataResponse.getData().get(position).getUrl().equals(Constants.YINKA)) {
399
+                                    //银卡
400
+                                    // DacangMemberActivity.launch(getActivity(), "2");
401
+                                    AGuestMemberActivity.launch(getActivity());
402
+
403
+                                } else if (listDataResponse.getData().get(position).getUrl().equals(Constants.YINKA)) {
404
+                                    //五一
405
+                                } else if (listDataResponse.getData().get(position).getUrl().contains(Constants.DACANG)) {
406
+
407
+                                    if (listDataResponse.getData().get(position).getUrl().length() > 11) {
408
+                                        //
409
+                                        String index = listDataResponse.getData().get(position).getUrl().substring(13, listDataResponse.getData().get(position).getUrl().length());
410
+                                        LogUtil.LogInfo("urrrr", index);
411
+//                                            getActivity().finish();
412
+                                        MainActivity.launch(getActivity(), "3", index);
413
+                                    } else {
414
+                                        //大仓
415
+//                                            getActivity().finish();
416
+                                        MainActivity.launch(getActivity(), "3");
417
+                                    }
418
+//                                       String str =listDataResponse.getData().get(position).getUrl().replace(listDataResponse.getData().get(position).getUrl().length()-5,listDataResponse.getData().get(position).getUrl().length());
419
+
420
+                                } else if (listDataResponse.getData().get(position).getUrl().equals(Constants.MIAOSHA)) {
421
+                                    //秒杀
422
+                                    if (LoginUtils.isLogin(getActivity())) {
423
+                                        DacangSeckillActivity.launch(getActivity());
424
+                                    }
425
+                                } else if (listDataResponse.getData().get(position).getUrl().equals("rich")) {
426
+                                    //VIP专区
427
+                                    VipAreaActivity.lanuch(getActivity());
428
+                                } else if (listDataResponse.getData().get(position).getUrl().equals(Constants.SHOP)) {
429
+                                    //精品商城
430
+                                    DingShengLianMengActivity.lanunch(getActivity(), 1);
431
+                                }
432
+                            }
433
+
434
+                        });
435
+            }
436
+        });
437
+    }
438
+
439
+    *//**
440
+     * 设置顶部view 上方渐变效果
441
+     *
442
+     * @param y 滑动距离
443
+     *//*
444
+    private void showHeaderAlphaAction(int y) {
445
+        final int rootPicHeight = binding.headView.viewTop.getHeight();
446
+        if (y <= rootPicHeight) {
447
+            binding.headView.viewHeaderBg.setBackgroundResource(R.mipmap.home_top_bg_scroll);
448
+            //状态栏深色模式
449
+            binding.tvScrollTop.setVisibility(View.GONE);
450
+        } else {
451
+            binding.tvScrollTop.setVisibility(View.VISIBLE);
452
+            binding.headView.viewHeaderBg.setBackgroundResource(R.mipmap.home_top_bg);
453
+        }
454
+    }
455
+
456
+    @Override
457
+    public void onAttach(@NonNull Context context) {
458
+        super.onAttach(context);
459
+
460
+    }
461
+
462
+    @Override
463
+    public void onDestroyView() {
464
+        super.onDestroyView();
465
+        binding = null;
466
+        if (timer != null) {
467
+            timer.cancel();
468
+        }
469
+    }
470
+
471
+    @Override
472
+    public void onClick(View view) {
473
+        if (view == binding.tvScrollTop) {
474
+            binding.scrollview.scrollTo(0, 0);
475
+            binding.rvHomeList.scrollToPosition(0);
476
+        } else if (view == binding.headView.rlTop) {
477
+            //养老金
478
+            if (LoginUtils.isLogin(getActivity())) {
479
+                AnnuityActivity.launch(getActivity());
480
+            }
481
+        } else if (view == binding.headView.llSearch) {
482
+            //搜索
483
+//            SearchActivity2.launch(getActivity());
484
+            YHCHomeSearchActivity.launch(getActivity());
485
+        } else if (view == binding.tvBuyNow) {
486
+            //新人专区
487
+            VipAreaActivity.lanuch(getActivity());
488
+        } else if (view == binding.tvGetMore) {
489
+            DacangSeckillActivity.launch(getActivity());
490
+        }else if (view == binding.headView.ivMessage || view == binding.headView.tvMessage){
491
+            MessageActivity.launch(getActivity());
492
+        }else if (view == binding.llRecommend){
493
+            //推荐,默认选项
494
+            isPriceUp = false;
495
+            isSalesUp = false;
496
+            mPage =1;
497
+            isNew = "0";
498
+            priceType = "1";
499
+            sales = "0";
500
+            setSelectButton(0);
501
+        } else if (view == binding.llSearchUpdate){
502
+            //上新
503
+            isPriceUp = false;
504
+            isSalesUp = false;
505
+            mPage =1;
506
+            isNew = "1";
507
+            priceType = "1";
508
+            sales = "0";
509
+            setSelectButton(1);
510
+        } else if (view == binding.llSearchSales){
511
+            //销量
512
+            isPriceUp = false;
513
+            isSalesUp = !isSalesUp;
514
+            mPage =1;
515
+            isNew = "0";
516
+            priceType = "1";
517
+            sales = isSalesUp?"1":"0";
518
+            setSelectButton(2);
519
+        } else if (view == binding.llSearchPrice){
520
+            //价格
521
+            isSalesUp = false;
522
+            isPriceUp = !isPriceUp;
523
+            mPage =1;
524
+            isNew = "0";
525
+            priceType = isPriceUp?"1":"0";
526
+            sales = "1";
527
+            setSelectButton(3);
528
+        }
529
+    }
530
+    private int currentPos = 0;
531
+    private void setSelectButton(int pos){
532
+        if (currentPos == pos && (pos==0||pos==1)) return;  //重复点击 推荐 和 上新选项是无意义的,直接返回
533
+
534
+        binding.btvRecommend.setTextColor(ContextCompat.getColor(getContext(), R.color.black_333333));
535
+        binding.btvSearchUpdate.setTextColor(ContextCompat.getColor(getContext(), R.color.black_333333));
536
+        binding.btvSearchSales.setTextColor(ContextCompat.getColor(getContext(), R.color.black_333333));
537
+        binding.btvSearchPrice.setTextColor(ContextCompat.getColor(getContext(), R.color.black_333333));
538
+        if (pos != 2){
539
+            binding.ivShengxuSales.setImageResource(R.mipmap.tuijian_shangla);
540
+            binding.ivJiangxuSale.setImageResource(R.mipmap.tuijian_xiala);
541
+        }
542
+        if (pos != 3){
543
+            binding.ivShengxu.setImageResource(R.mipmap.tuijian_shangla);
544
+            binding.ivJiangxu.setImageResource(R.mipmap.tuijian_xiala);
545
+        }
546
+        switch (pos) {
547
+            case 0:
548
+                binding.btvRecommend.setTextColor(ContextCompat.getColor(getContext(), R.color.red_fe0032));
549
+                homeViewModel.getHomeProductListData(mPage, mer_keyword, null, null, null);
550
+                break;
551
+            case 1:
552
+                binding.btvSearchUpdate.setTextColor(ContextCompat.getColor(getContext(), R.color.red_fe0032));
553
+                homeViewModel.getHomeProductListData(mPage, mer_keyword, isNew, null, null);
554
+                break;
555
+            case 2:
556
+                binding.btvSearchSales.setTextColor(ContextCompat.getColor(getContext(), R.color.red_fe0032));
557
+                homeViewModel.getHomeProductListData(mPage, mer_keyword, null, null, sales);
558
+                if (isSalesUp){
559
+                    binding.ivShengxuSales.setImageResource(R.mipmap.search_red_shangla_220617);
560
+                    binding.ivJiangxuSale.setImageResource(R.mipmap.tuijian_xiala);
561
+                }else {
562
+                    binding.ivShengxuSales.setImageResource(R.mipmap.tuijian_shangla);
563
+                    binding.ivJiangxuSale.setImageResource(R.mipmap.search_red_xiala_220617);
564
+                }
565
+                break;
566
+            case 3:
567
+                binding.btvSearchPrice.setTextColor(ContextCompat.getColor(getContext(), R.color.red_fe0032));
568
+                homeViewModel.getHomeProductListData(mPage, mer_keyword, null, priceType, null);
569
+                if (isPriceUp){
570
+                    binding.ivShengxu.setImageResource(R.mipmap.search_red_shangla_220617);
571
+                    binding.ivJiangxu.setImageResource(R.mipmap.tuijian_xiala);
572
+                }else {
573
+                    binding.ivShengxu.setImageResource(R.mipmap.tuijian_shangla);
574
+                    binding.ivJiangxu.setImageResource(R.mipmap.search_red_xiala_220617);
575
+                }
576
+                break;
577
+        }
578
+        currentPos = pos;
579
+
580
+    }
581
+    @Override
582
+    public void onDestroy() {
583
+        super.onDestroy();
584
+        *//** 触摸事件的注销 *//*
585
+//        ((MainActivity)this.getActivity()).unRegisterMyTouchListener(myTouchListener);
586
+    }
587
+
588
+
589
+    *//**
590
+     * 跳转至商品页
591
+     *
592
+     * @param activity Activity
593
+     * @param url      商铺地址/商品详情地址
594
+     *//*
595
+    public static void gotoShop(Activity activity, String url) {
596
+        try {
597
+            Intent intent = new Intent();
598
+            intent.setAction("android.intent.action.VIEW");
599
+            intent.setData(Uri.parse(url));
600
+            activity.startActivity(intent);
601
+        } catch (Exception e) {
602
+            e.printStackTrace();
603
+        }
604
+    }*/
605
+}

+ 2 - 3
app/src/main/java/com/yihucha/hbyhc/utils/explainpermissions/ExplainPermissionsUtil.kt

@@ -36,7 +36,6 @@ class ExplainPermissionsUtil : AppCompatActivity() {
36 36
     //需要申请的权限字符串数组
37 37
     private lateinit var permissions: Array<String>
38 38
     private lateinit var recyclerView: RecyclerView
39
-    private var callback: Callback<Boolean>? = null
40 39
     private lateinit var intercept: Intercept
41 40
 
42 41
     //用于展示未授予的权限列表数据
@@ -198,7 +197,7 @@ class ExplainPermissionsUtil : AppCompatActivity() {
198 197
                 if (grant == PackageManager.PERMISSION_DENIED) {
199 198
                     if (intercept == Intercept.NORMAL) {
200 199
                         //不需要弹框级别的在这里就直接返回了
201
-                        Companion.callback?.onCallback(false)
200
+                        callback?.onCallback(false)
202 201
                         toFinish()
203 202
                         return
204 203
                     }
@@ -213,7 +212,7 @@ class ExplainPermissionsUtil : AppCompatActivity() {
213 212
 
214 213
             if (unGranted.size == 0) {
215 214
                 //已全部授予权限
216
-                Companion.callback?.onCallback(true)
215
+                callback?.onCallback(true)
217 216
                 toFinish()
218 217
             } else if (intercept == Intercept.LOW && (shouldShow == null || shouldShow == true)) {
219 218
                 //LOW级别,未设置不再提示,就不弹框

+ 57 - 44
app/src/main/res/layout/fragment_home.xml

@@ -8,18 +8,12 @@
8 8
     android:orientation="vertical"
9 9
     tools:context="com.yihucha.hbyhc.presentation.home.HomeFragment">
10 10
 
11
-    <include
12
-        android:id="@+id/head_view"
13
-        layout="@layout/home_head"
14
-        android:layout_width="wrap_content"
15
-        android:layout_height="wrap_content" />
11
+
16 12
 
17 13
     <com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
18 14
         android:id="@+id/refreshLayout"
19 15
         android:layout_width="match_parent"
20 16
         android:layout_height="match_parent"
21
-        android:layout_below="@+id/head_view"
22
-        android:layout_marginTop="-45dp"
23 17
         app:tr_pureScrollMode_on="true">
24 18
 
25 19
         <com.yihucha.hbyhc.view.NaviBarChangeStatusScrollView
@@ -40,51 +34,61 @@
40 34
                 android:orientation="vertical"
41 35
                 android:paddingTop="3dp">
42 36
 
43
-                <androidx.cardview.widget.CardView
37
+                <com.youth.banner.Banner
38
+                    android:id="@+id/banner_home"
44 39
                     android:layout_width="match_parent"
45
-                    android:layout_height="wrap_content"
46
-                    android:layout_marginLeft="10dp"
47
-                    android:layout_marginRight="10dp"
48
-                    app:cardCornerRadius="10dp">
49
-
50
-                    <com.youth.banner.Banner
51
-                        android:id="@+id/banner_home"
52
-                        android:layout_width="match_parent"
53
-                        android:layout_height="140dp" />
54
-                </androidx.cardview.widget.CardView>
40
+                    android:layout_height="240dp"
41
+                    />
55 42
 
56 43
                 <LinearLayout
57 44
                     android:layout_width="match_parent"
58 45
                     android:layout_height="wrap_content"
59 46
                     android:layout_marginTop="10dp"
60
-                    android:orientation="horizontal">
61
-
47
+                    android:orientation="horizontal"
48
+                    android:padding="16dp"
49
+                    >
62 50
                     <TextView
63 51
                         android:layout_width="0dp"
64 52
                         android:layout_height="wrap_content"
65 53
                         android:layout_weight="1"
66
-                        android:drawableTop="@mipmap/icon_cxb"
54
+                        android:drawableTop="@mipmap/icon_jd"
67 55
                         android:drawablePadding="4dp"
68 56
                         android:gravity="center_horizontal"
69
-                        android:text="储蓄保商城" />
57
+                        android:text="京东" />
70 58
 
71 59
                     <TextView
72 60
                         android:layout_width="0dp"
73 61
                         android:layout_height="wrap_content"
74 62
                         android:layout_weight="1"
75
-                        android:drawableTop="@mipmap/icon_ms"
63
+                        android:drawableTop="@mipmap/icon_pdd"
76 64
                         android:drawablePadding="4dp"
77 65
                         android:gravity="center_horizontal"
78
-                        android:text="限时秒杀" />
66
+                        android:text="拼多多" />
79 67
 
80 68
                     <TextView
81 69
                         android:layout_width="0dp"
82 70
                         android:layout_height="wrap_content"
83 71
                         android:layout_weight="1"
84
-                        android:drawableTop="@mipmap/icon_vip"
72
+                        android:drawableTop="@mipmap/icon_vph"
73
+                        android:drawablePadding="4dp"
74
+                        android:gravity="center_horizontal"
75
+                        android:text="唯品会" />
76
+                    <TextView
77
+                        android:layout_width="0dp"
78
+                        android:layout_height="wrap_content"
79
+                        android:layout_weight="1"
80
+                        android:drawableTop="@mipmap/icon_dy"
81
+                        android:drawablePadding="4dp"
82
+                        android:gravity="center_horizontal"
83
+                        android:text="抖音" />
84
+                    <TextView
85
+                        android:layout_width="0dp"
86
+                        android:layout_height="wrap_content"
87
+                        android:layout_weight="1"
88
+                        android:drawableTop="@mipmap/icon_sn"
85 89
                         android:drawablePadding="4dp"
86 90
                         android:gravity="center_horizontal"
87
-                        android:text="会员专区" />
91
+                        android:text="苏宁易购" />
88 92
                 </LinearLayout>
89 93
 
90 94
                 <RelativeLayout
@@ -94,7 +98,7 @@
94 98
                     android:layout_marginLeft="12dp"
95 99
                     android:layout_marginTop="10dp"
96 100
                     android:layout_marginRight="12dp"
97
-                    android:background="@mipmap/bg_vip_home"
101
+                    android:background="@mipmap/img_bg"
98 102
                     android:paddingLeft="3dp"
99 103
                     android:paddingTop="13dp"
100 104
                     android:paddingRight="3dp"
@@ -105,29 +109,25 @@
105 109
                         android:id="@+id/imgv_vip"
106 110
                         android:layout_width="wrap_content"
107 111
                         android:layout_height="wrap_content"
108
-                        android:text="会员专区\t好物超值购"
109
-                        android:textColor="@color/white"
110
-                        android:textSize="17sp"
111
-                        android:paddingLeft="13dp"
112
+                        android:text="365专区"
113
+                        android:textColor="@color/black_333333"
114
+                        android:textSize="22sp"
115
+                        android:paddingLeft="10dp"
112 116
                         />
113 117
 
114
-                    <com.yihucha.hbyhc.view.BoldText
118
+                    <TextView
115 119
                         android:id="@+id/tv_buy_now"
116 120
                         android:layout_width="wrap_content"
117 121
                         android:layout_height="wrap_content"
118 122
                         android:layout_alignParentRight="true"
119 123
                         android:layout_gravity="center_vertical"
120 124
                         android:layout_marginRight="12dp"
121
-                        android:background="@drawable/shape_line_white_50dp"
122
-                        android:drawableRight="@mipmap/img_jt_right"
125
+                        android:text="更多"
126
+                        android:textColor="@color/gray_666666"
127
+                        android:textSize="15sp"
128
+                        android:drawableRight="@mipmap/jiantou_right_gray"
123 129
                         android:drawablePadding="5dp"
124
-                        android:paddingLeft="8dp"
125
-                        android:paddingTop="3dp"
126
-                        android:paddingRight="8dp"
127
-                        android:paddingBottom="3dp"
128
-                        android:text="立即抢购"
129
-                        android:textColor="@color/white"
130
-                        android:textSize="15sp" />
130
+                        />
131 131
 
132 132
                     <androidx.cardview.widget.CardView
133 133
                         android:layout_width="match_parent"
@@ -144,7 +144,16 @@
144 144
                     </androidx.cardview.widget.CardView>
145 145
 
146 146
                 </RelativeLayout>
147
-
147
+                <ImageView
148
+                    android:layout_width="match_parent"
149
+                    android:layout_height="wrap_content"
150
+                    android:src="@mipmap/vip_chuangke"
151
+                    android:scaleType="centerCrop"
152
+                    android:paddingLeft="12dp"
153
+                    android:paddingRight="12dp"
154
+                    android:layout_marginTop="12dp"
155
+                    android:layout_marginBottom="12dp"
156
+                    />
148 157
                 <RelativeLayout
149 158
                     android:id="@+id/layout_seckill"
150 159
                     android:layout_width="match_parent"
@@ -157,7 +166,7 @@
157 166
                     android:paddingTop="13dp"
158 167
                     android:paddingRight="10dp"
159 168
                     android:paddingBottom="3dp"
160
-                    android:visibility="visible">
169
+                    android:visibility="gone">
161 170
 
162 171
                     <com.yihucha.hbyhc.view.BoldText
163 172
                         android:id="@+id/imgv_xsms"
@@ -426,7 +435,11 @@
426 435
         </com.yihucha.hbyhc.view.NaviBarChangeStatusScrollView>
427 436
 
428 437
     </com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
429
-
438
+    <include
439
+        android:id="@+id/head_view"
440
+        layout="@layout/home_head"
441
+        android:layout_width="wrap_content"
442
+        android:layout_height="wrap_content" />
430 443
 
431 444
     <!--站位-->
432 445
     <View

+ 13 - 9
app/src/main/res/layout/home_head.xml

@@ -8,14 +8,18 @@
8 8
     <View
9 9
         android:id="@+id/view_header_bg"
10 10
         android:layout_width="match_parent"
11
-        android:layout_height="190dp"
12
-        android:alpha="1"
13
-        android:background="@mipmap/home_top_bg" />
11
+        android:layout_height="150dp"
12
+        android:background="@color/white"
13
+        android:visibility="invisible"
14
+        android:alpha="1" />
14 15
 
15 16
     <View
16 17
         android:id="@+id/view_top"
17 18
         android:layout_width="wrap_content"
18
-        android:layout_height="51dp"/>
19
+        android:layout_height="51dp"
20
+        android:visibility="invisible"
21
+        android:background="@color/white"
22
+        />
19 23
 
20 24
     <LinearLayout
21 25
         android:layout_width="match_parent"
@@ -41,9 +45,9 @@
41 45
                 android:layout_width="wrap_content"
42 46
                 android:layout_height="wrap_content"
43 47
                 android:layout_weight="1"
44
-                android:text="@string/login"
45
-                android:textColor="@color/black_333333"
46
-                android:textSize="17sp"
48
+                android:text="登录\n领取养老金"
49
+                android:textColor="@color/white"
50
+                android:textSize="15sp"
47 51
                 android:paddingLeft="12dp"
48 52
                 android:layout_gravity="center_vertical"
49 53
                 />
@@ -68,7 +72,7 @@
68 72
                     android:layout_height="wrap_content"
69 73
                     android:layout_marginTop="3dp"
70 74
                     android:text="@string/message"
71
-                    android:textColor="@color/black_333333"
75
+                    android:textColor="@color/white"
72 76
                     android:textSize="9.5sp" />
73 77
             </LinearLayout>
74 78
         </LinearLayout>
@@ -80,7 +84,7 @@
80 84
             android:layout_marginLeft="16dp"
81 85
             android:layout_marginTop="8dp"
82 86
             android:layout_marginRight="16dp"
83
-            android:background="@drawable/shape_ffffff_15dp"
87
+            android:background="@drawable/shape_line_fe0032_15dp"
84 88
             android:gravity="center_vertical"
85 89
             android:orientation="horizontal">
86 90
 

BIN=BIN
app/src/main/res/mipmap-xxxhdpi/icon_dy.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/icon_jd.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/icon_pdd.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/icon_sn.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/icon_vph.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/img_bg.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/jiantou_right_gray.png


BIN=BIN
app/src/main/res/mipmap-xxxhdpi/vip_chuangke.png