admin
2020-07-14 41b23417cd62af3cd77b695a2b03446243431fc1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
package com.yeshi.ec.rebate.myapplication.ui.BrandRebate;
 
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.viewpagerindicator.CirclePageIndicator;
import com.wpc.library.content.ConnectivityChangeHelper;
import com.wpc.library.util.NetUtils;
import com.wpc.library.util.cache.DiskLruCache;
import com.wpc.library.util.common.StorageUtils;
import com.wpc.library.widget.MyGridView;
import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
import com.yeshi.ec.rebate.myapplication.R;
import com.yeshi.ec.rebate.myapplication.ShoppingApi;
import com.yeshi.ec.rebate.myapplication.entity.BranShopInfo;
import com.yeshi.ec.rebate.myapplication.entity.HomeBanner;
import com.yeshi.ec.rebate.myapplication.ui.recommend.RecommendTopAdapter2;
 
import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;
 
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
//import static android.content.Context.MODE_PRIVATE;
 
/**
 * 商品返利 加载页
 */
public class FragmentBrandFragment2 extends RetainView_LJZFragment implements View.OnClickListener {
    private SwipeRefreshLayout fragment_brand_fragment_sf;//刷新控件
    private RecyclerView fragment_brand_fragment_rv;//RecyclerView
 
    private Bundle mBundle;//获取Activity传递过来的参数
    private List<BranShopInfo> secondList = new ArrayList<>();
    private MyGridView gv_category_top;
    private BrandShoplistAdapter adapter;//淘宝商品适配
    private List<BranShopInfo> mList = new ArrayList<>();
    private View bottom;
    private TextView tv_loading, tv_invite_player;
    private ImageView iv_loading;
 
    private int page = 1;
    private boolean isLoad = true;
    private int count = 1;
    private LinearLayout ll_no_net, ll_no_data, ll_request_failture;    private ImageView ll_no_data_rf;
    private RelativeLayout ff_loading_no_data;//无数据
    private ConnectivityChangeHelper mChangeHelper;
    private DiskLruCache cache;
 
    private String tag1 = "brand/getShopList";
    private String tag2 = "brand/getHistory";
    private int MODE_PRIVATE = android.content.Context.MODE_PRIVATE;
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_brand_fragment;//引入对应的布局文件frag.xml
    }
 
    private int getVersionNum(Context context) {
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo(
                    context.getPackageName(), 0);
            return pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return 1;
        }
    }
 
 
    private ShopHistoryAdapter gvadapter;
 
    ViewPager vp_banner = null;
    CirclePageIndicator indicator_banner = null;
    private RecommendTopAdapter2 bannerAdapter = null;
    private List<HomeBanner> bannerList = new ArrayList<>();
    View bannerContainer = null;
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        try {
            cache = DiskLruCache.open(
                    new File(StorageUtils.getCacheDirectory(getContext())
                            .toString(), "http"), getVersionNum(getContext()),
                    1, 1024 * 1024);
        } catch (IOException e) {
            e.printStackTrace();
        }
        fragment_brand_fragment_sf = contentView.findViewById(R.id.fragment_brand_fragment_sf);//下拉刷新控件
        fragment_brand_fragment_rv = contentView.findViewById(R.id.fragment_brand_fragment_rv);//RecyclerView 列表
        //设置一个位置变量,每次点击tab传入不同的tab位置以便textview上显示相应的标题
        //获取Activity传递过来的参数
        mBundle = getArguments();
        fragment_brand_fragment_rv.setLayoutManager(new LinearLayoutManager(fragment_brand_fragment_sf.getContext()));
 
        View top_view = LayoutInflater.from(fragment_brand_fragment_sf.getContext()).inflate(R.layout.item_fragment_brand_top, null);
        gv_category_top = top_view.findViewById(R.id.fragment_brand_top_top);
        if (mBundle.getString("id").equals("0")) { //精选 5个
            gv_category_top.setNumColumns(5);
        } else {//其他 4个
            gv_category_top.setNumColumns(4);
        }
 
        adapter = new BrandShoplistAdapter(fragment_brand_fragment_sf.getContext(), mList, mBundle.getString("id"), false);
        adapter.isHorizontal = true;
        adapter.isFirst = true;
        fragment_brand_fragment_rv.setAdapter(adapter);
        bottom = LayoutInflater.from(fragment_brand_fragment_sf.getContext()).inflate(R.layout.item_recyclerview_bottom2, null);
        tv_loading = bottom.findViewById(R.id.tv_loading2);
        iv_loading = bottom.findViewById(R.id.iv_loading2);
        ff_loading_no_data = bottom.findViewById(R.id.ff_loading_no_data2);
        AnimationDrawable animationDrawable = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_list_loading);
        iv_loading.setImageDrawable(animationDrawable);
        animationDrawable.start();
        bottom.setVisibility(View.GONE);
        adapter.addHeaderView(top_view);
        adapter.addFooterView(bottom);
 
        //----------------banner初始化开始-------------------
        bannerContainer = LayoutInflater.from(fragment_brand_fragment_sf.getContext()).inflate(R.layout.item_brand_banner, null);
        vp_banner = bannerContainer.findViewById(R.id.vp_brand);
        indicator_banner = bannerContainer.findViewById(R.id.indicator_brand);
        bannerAdapter = new RecommendTopAdapter2(bannerList, getActivity(), true);
        vp_banner.setAdapter(bannerAdapter);
        indicator_banner.setViewPager(vp_banner);
        bannerContainer.setVisibility(View.GONE);
//        adapter.addBannerView(bannerContainer);
        //----------------------banner初始化结束---------------
 
 
        gvadapter = new ShopHistoryAdapter(fragment_brand_fragment_sf.getContext(), secondList, mBundle.getString("id"), mBundle.getString("arg"));
        gv_category_top.setAdapter(gvadapter);
        /**
         * RecyclerView 滑动监听 判断到底部
         */
        fragment_brand_fragment_rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
                int last = manager.findLastVisibleItemPosition();
                int total = manager.getItemCount();
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    if (last == total - 1 && mList.size() < count && isLoad) {
                        page++;
                        isLoad = false;
                        tv_loading.setText("正在加载更多数据");
                        iv_loading.setVisibility(View.VISIBLE);
                        getGoodsList();
                    }
                }
            }
        });
 
        //无数据 无网络  网络异常
        ll_no_net = contentView.findViewById(R.id.ll_no_net);
        ll_no_data = contentView.findViewById(R.id.ll_no_data);
        tv_invite_player = contentView.findViewById(R.id.tv_invite_player);//无数据点击刷新
        tv_invite_player.setVisibility(View.VISIBLE);
        ll_request_failture = contentView.findViewById(R.id.ll_request_failture);
 
        contentView.findViewById(R.id.tv_net_setting).setOnClickListener(this);
        contentView.findViewById(R.id.tv_refresh).setOnClickListener(this);
        ll_no_data_rf = contentView.findViewById(R.id.iv_refresh);
        ll_no_data_rf.setOnClickListener(this);
        tv_invite_player.setOnClickListener(this);
 
//            fragment_brand_fragment_sf.setRefreshing(true);
        fragment_brand_fragment_sf.setColorSchemeColors(getResources().getColor(R.color.theme));
        fragment_brand_fragment_sf.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                page = 1;
                if (refresh1 && refresh2) {
                    getGoodsList();
                }
            }
        });
        ((SimpleItemAnimator) fragment_brand_fragment_rv.getItemAnimator()).setSupportsChangeAnimations(false); //取消RecyclerView的动画效果
        InitData();
        loadCacheData();
    }
 
 
    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {
//        getGoodsList();
    }
 
    private boolean lazy = false;
 
    //加载数据方法
//    @Override
    public void InitData() {
//        getGoodsList();
        mChangeHelper = new ConnectivityChangeHelper(fragment_brand_fragment_sf.getContext(),
                new ConnectivityChangeHelper.OnConnectivityChangeListener() {
 
                    @Override
                    public void onNetworkUnAvailable() {
                        if (mList.size() == 0) {
                            requestState(3);
                        }
                    }
 
                    @Override
                    public void onNetworkAvailable() {
                        requestState(0);
                        if (mList.size() == 0) {
                            getGoodsList();
                        }
                    }
                });
        //精选
        if (mBundle.getString("id").equals("0")) {
//            getGoodsList();
        }
        getGoodsList();
    }
 
    private void loadCacheData() {
        if (cache != null && mBundle.getString("id").equals("0")) {
            {
                DiskLruCache.Snapshot snapshot = null;
                try {
                    snapshot = cache.get(getKey("getShopList"));
                    if (snapshot != null) {
                        try {
                            JSONObject data = new JSONObject(snapshot.getString(0));
                            JSONArray brandArray = data.optJSONArray("list");
                            JSONArray bannerArray = data.optJSONArray("banners");
 
                            Gson gson = new GsonBuilder().serializeNulls().create();
                            List<BranShopInfo> list = gson.fromJson(brandArray.toString()
                                    , new TypeToken<List<BranShopInfo>>() {
                                    }.getType());
                            settop(list);
 
                            if (bannerArray != null) {
                                List<HomeBanner> listBanner = gson.fromJson(
                                        bannerArray.toString(),
                                        new TypeToken<List<HomeBanner>>() {
                                        }.getType());
                                bannerList.clear();
                                bannerList.addAll(listBanner);
                                bannerAdapter.notifyDataSetChanged();
                                if (bannerList.size() > 0) {
                                    bannerContainer.setVisibility(View.VISIBLE);
                                    adapter.addBannerView(bannerContainer);
                                } else {
                                    adapter.removeBannerView();
                                }
                            }
 
 
                            if (page == 1 && mList.size() > 0)//第一页的时候表示刷新 需要情况list
                                mList.clear();
                            mList.addAll(list);
 
                            if (mList.size() >= count) { //下拉数据请求完 到底了
                                bottom.setVisibility(View.VISIBLE);
                                iv_loading.setVisibility(View.GONE);
                                tv_loading.setText(getResources().getString(R.string.list_no_more));
                            } else {  //下拉还有数据时
                                if (bottom.getVisibility() == View.VISIBLE) {
                                    bottom.setVisibility(View.GONE);
                                }
                            }
                            if (mList.size() == 0) { //没有数据情况
                                bottom.setVisibility(View.VISIBLE);
                                ff_loading_no_data.setVisibility(View.VISIBLE); //展示 无数据页
                            } else {
                                ff_loading_no_data.setVisibility(View.GONE); //隐藏无数据页
                            }
                            adapter.notifyItemRangeChanged(1, mList.size()); //进行列表全部刷新
                        } catch (Exception e) {
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (snapshot != null) {
                        snapshot.close();
                    }
                }
            }
            {
                DiskLruCache.Snapshot snapshot = null;
                try {
                    snapshot = cache.get(getKey("getJingxuanHistory"));
                    if (snapshot != null) {
                        Gson gson = new GsonBuilder().serializeNulls().create();
                        List<BranShopInfo> list = gson.fromJson(snapshot.getString(0)
                                , new TypeToken<List<BranShopInfo>>() {
                                }.getType());
                        settop(list);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (snapshot != null) {
                        snapshot.close();
                    }
                }
            }
        }
 
    }
 
    private String getKey(String method) {
        return new Md5FileNameGenerator().generate(method);
    }
 
    //防止重复刷新
    private boolean refresh1 = true;//商品
    private boolean refresh2 = true;//足迹
 
 
    @Override
    public void onResume() {
        super.onResume();
        ll_no_data.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mList != null && (mList.size() == 0 || secondList.size() == 0)) {
                    getGoodsList();
                    fragment_brand_fragment_sf.setRefreshing(true);
                }
            }
        }, 600);
//        if (mBundle.getString("id").equals("0")) { //精选
//            getCateGorySecond(null);//请求 刷新 店铺足迹
//        }
//        gv_category_top.getFocusedChild();
        mChangeHelper.registerReceiver();
    }
 
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            //TODO now it's visible to user
            if (mList.size() == 0 || secondList.size() == 0) {
                if (fragment_brand_fragment_sf != null) {
                    getGoodsList();
                    fragment_brand_fragment_sf.setRefreshing(true);
                }
            }
        } else {
            //TODO now it's invisible to user
        }
    }
 
    /**
     * 获取商品列表
     */
    private void getGoodsList() {
        if (!refresh1) {
            return;
        }
 
        //精选
        SharedPreferences sp = fragment_brand_fragment_sf.getContext().getSharedPreferences("user", MODE_PRIVATE);
        ShoppingApi.getShopList(fragment_brand_fragment_sf.getContext(), page + "", mBundle.getString("id"), (sp.getBoolean("isLogin", false) ? sp.getString("uid", "0") : null), new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                refresh1 = false;
                if (page > 1) {
                    bottom.setVisibility(View.VISIBLE);
                } else {
                    if (page == 1) {
                        bottom.setVisibility(View.VISIBLE);
                        iv_loading.setVisibility(View.GONE);
                        tv_loading.setText("");
                    } else {
                        bottom.setVisibility(View.GONE);
                    }
                }
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                refresh1 = true;
                ff_loading_no_data.setVisibility(View.GONE); //隐藏无数据页
                requestState(0);
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    JSONArray brandlist = jsonObject.optJSONObject("data").optJSONArray("brandlist");
 
                    List<BranShopInfo> list2 = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("list").toString(),
                            new TypeToken<List<BranShopInfo>>() {
                            }.getType());
                    count = Integer.parseInt(jsonObject.optJSONObject("data").optString("count"));
                    isLoad = true;
                    if (page == 1 && mList.size() > 0)//第一页的时候表示刷新 需要情况list
                        mList.clear();
                    mList.addAll(list2);
 
 
                    //解析banner
                    if (page == 1) {
                        JSONArray bannerArray = jsonObject.optJSONObject("data").optJSONArray("banners");
                        if (bannerArray != null && bannerArray.length() > 0) {
                            List<HomeBanner> listBanner = gson.fromJson(
                                    bannerArray.toString(),
                                    new TypeToken<List<HomeBanner>>() {
                                    }.getType());
                            bannerList.clear();
                            bannerList.addAll(listBanner);
                            bannerAdapter.notifyDataSetChanged();
                            if (bannerList.size() > 0) {
                                bannerContainer.setVisibility(View.VISIBLE);
                                adapter.addBannerView(bannerContainer);
                            }
                        }
                    }
 
                    if (mList.size() >= count) { //下拉数据请求完 到底了
                        bottom.setVisibility(View.VISIBLE);
                        iv_loading.setVisibility(View.GONE);
                        tv_loading.setText(getResources().getString(R.string.list_no_more));
                    } else {  //下拉还有数据时
                        bottom.setVisibility(View.GONE);
                    }
                    if (mList.size() == 0) { //没有数据情况
                        bottom.setVisibility(View.VISIBLE);
                        ff_loading_no_data.setVisibility(View.VISIBLE); //展示 无数据页
                    } else {
                        ff_loading_no_data.setVisibility(View.GONE); //隐藏无数据页
                    }
                    adapter.notifyItemRangeChanged(0, mList.size()); //进行列表全部刷新
                    if (page == 1 && !mBundle.getString("id").equals("0")) {//不是精选页 添加店铺宫格数据
                        List<BranShopInfo> list1 = gson.fromJson(brandlist.toString(),
                                new TypeToken<List<BranShopInfo>>() {
                                }.getType());
                        settop(list1);
                    } else if (page == 1 && mBundle.getString("id").equals("0")) { //第一页的情况下 加载店铺足迹 /or 店铺数据
                        getCateGorySecond();
                    }
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                refresh1 = true;
                if (fragment_brand_fragment_sf != null) {
                    fragment_brand_fragment_sf.setRefreshing(false);
                }
                bottom.setVisibility(View.GONE);
                if (mList.size() == 0) {
                    if (NetUtils.getNetworkState(fragment_brand_fragment_sf.getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                        requestState(3);
                    } else {
                        requestState(2);
                    }
                } else {
                    if (NetUtils.getNetworkState(fragment_brand_fragment_sf.getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                        Toast.makeText(fragment_brand_fragment_sf.getContext(), "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(fragment_brand_fragment_sf.getContext(), "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
                    }
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                refresh1 = true;
                if (fragment_brand_fragment_sf != null) {
                    fragment_brand_fragment_sf.setRefreshing(false);
                }
            }
        });
    }
 
 
    /**
     * 获取精选店铺足迹/上方店铺  九宫格数据
     */
    private void getCateGorySecond() {
        refresh2 = false;
        //精选
        SharedPreferences sp = getActivity().getSharedPreferences("user", MODE_PRIVATE);
        ShoppingApi.getHistory(fragment_brand_fragment_sf.getContext(), "1", (sp.getBoolean("isLogin", false) ? sp.getString("uid", "0") : null), "1", new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                refresh2 = true;
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    List<BranShopInfo> list1 = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("list").toString(),
                            new TypeToken<List<BranShopInfo>>() {
                            }.getType());
                    settop(list1);
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                refresh2 = true;
                if (fragment_brand_fragment_sf != null) {
                    fragment_brand_fragment_sf.setRefreshing(false);
                }
            }
        });
    }
 
    /**
     * 设置九宫格数据
     *
     * @param list
     */
    private void settop(List<BranShopInfo> list) {
//        Log.e("eee", "settop: 设置九宫格数据");
        refresh2 = true;
        if (secondList.size() > 0)
            secondList.clear();
        gv_category_top.setVisibility(View.VISIBLE);
        if (list == null || list.size() == 0) { //当数据为0的时候 隐藏九宫格分类
            gv_category_top.setVisibility(View.GONE);
//            list.add(new BranShopInfo());//添加一條數據 是因為 下啦刷新控件在 無數據的時候 下拉失效
//            secondList.addAll(list);
        } else {
            gv_category_top.setVisibility(View.VISIBLE);
        }
        secondList.addAll(list);
        //传入id 判断是不是 精选页arg
//        shopHistoryAdapter.notifyDataSetChanged();
        gv_category_top.setFocusable(true);
        gv_category_top.setFocusableInTouchMode(true);
        gv_category_top.requestFocus();
        gv_category_top.requestFocusFromTouch();
        gvadapter.setListCount();
        gvadapter.notifyDataSetChanged();
//        adapter.notifyItemRangeChanged(0, mList.size()); //进行列表全部刷新
        if (!mBundle.getString("id").equals("0")) {//  不是精选情况  刷新
            adapter.notifyItemRangeChanged(0, mList.size()); //进行列表全部刷新
        }
    }
 
    @Override
    public void onPause() {
        super.onPause();
        if (fragment_brand_fragment_sf != null) {
            fragment_brand_fragment_sf.setRefreshing(false);
            fragment_brand_fragment_sf.destroyDrawingCache();
            fragment_brand_fragment_sf.clearAnimation();
        }
        refresh1 = true;
        refresh2 = true;
//        fragment_brand_fragment_rv.removeOnScrollListener(mOnScrollListener);
        mChangeHelper.unregisterReceiver();
    }
 
    /**
     * 请求状态 0 数据正常展示;1 返回数据为空;2 网络请求失败;3 没有连接网络
     *
     * @param state
     */
    private void requestState(int state) {
//        fragment_brand_fragment_sf.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
//        fragment_brand_fragment_rv.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
        ll_no_data_rf.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
        ll_no_data.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
        ll_request_failture.setVisibility(state == 2 ? View.VISIBLE : View.GONE);
        ll_no_net.setVisibility(state == 3 ? View.VISIBLE : View.GONE);
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_net_setting:
            case R.id.tv_refresh:
                startActivity(new Intent(Settings.ACTION_SETTINGS));
                break;
            case R.id.iv_refresh:
                if (fragment_brand_fragment_sf != null && !fragment_brand_fragment_sf.isRefreshing()) {
                    fragment_brand_fragment_sf.setRefreshing(true);
                }
                getGoodsList();
                break;
            case R.id.tv_invite_player:
                if (fragment_brand_fragment_sf != null && fragment_brand_fragment_sf.isRefreshing()) {
                    fragment_brand_fragment_sf.setRefreshing(false);
                }
                getGoodsList();
                fragment_brand_fragment_sf.setRefreshing(true);
                break;
        }
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
//        mBundle = null;//获取Activity传递过来的参数
//        mList = null;
//        secondList = null;
//        adapter = null;//淘宝商品适配
//        page = 1;
//        count = 0;
//        mChangeHelper = null;
//        OkHttpUtils.getInstance().cancelTag("brand/getList");
    }
 
 
}