|
|
@@ -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
|
+}
|