admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
package com.tejia.lijin.app.ui.main;
 
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.alibaba.baichuan.trade.biz.login.AlibcLogin;
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
import com.alibaba.fastjson.JSONArray;
import com.bumptech.glide.Glide;
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.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.ShoppingApplication;
import com.tejia.lijin.app.entity.EntityFather;
import com.tejia.lijin.app.entity.FirstCategory;
import com.tejia.lijin.app.entity.TrendsType;
import com.tejia.lijin.app.entity.UserInfo;
import com.tejia.lijin.app.entity.eventbus.UserProtocolEvent;
import com.tejia.lijin.app.entity.hongbao.LijinSendInfo;
import com.tejia.lijin.app.sqlite.HomeConfigSQHelper;
import com.tejia.lijin.app.ui.BrandRebate.BrandFragment;
import com.tejia.lijin.app.ui.category.CategoryTypeActivity;
import com.tejia.lijin.app.ui.dialog.RecommendHbDialog;
import com.tejia.lijin.app.ui.dialog.RedPacketHintDialog;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.ui.dialog.UserGuideDialog;
import com.tejia.lijin.app.ui.dialog.UserProtocolDialog;
import com.tejia.lijin.app.ui.gmtemplate.GmTemplateContentFragment;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.ui.mine.ShoppingTrolleyActivity;
import com.tejia.lijin.app.ui.recommend.RecommendCategoryFragment;
import com.tejia.lijin.app.ui.recommend.SearchActivity;
import com.tejia.lijin.app.ui.subview.HomeRecommendNavIndicator;
import com.tejia.lijin.app.updateApp.UpdateApp;
import com.tejia.lijin.app.util.GlideCircleTransform;
import com.tejia.lijin.app.util.JumpActivityUtil;
import com.tejia.lijin.app.util.SystemParamsUtil;
import com.tejia.lijin.app.util.ToolUtil;
import com.tejia.lijin.app.util.ui.HomeUIUtil;
import com.tejia.lijin.app.util.umengCustomEvent.CategoryCustomEvent;
import com.tejia.lijin.app.util.umengCustomEvent.MainCustomEvent;
import com.tejia.lijin.app.util.umengCustomEvent.SearchCustomEvent;
import com.tejia.lijin.app.util.user.UserUtil;
import com.umeng.analytics.MobclickAgent;
import com.wpc.library.RetainViewFragment;
import com.wpc.library.content.ConnectivityChangeHelper;
import com.wpc.library.okhttp.OkHttpUtils;
import com.wpc.library.util.NetUtils;
import com.wpc.library.util.SystemCommon;
import com.wpc.library.util.cache.DiskLruCache;
import com.wpc.library.util.common.DimenUtils;
import com.wpc.library.util.common.StorageUtils;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.ui.recommend.RecommendFragment;
 
import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import de.greenrobot.event.EventBus;
 
import static android.content.Context.MODE_PRIVATE;
 
/**
 * Created by weikou2015 on 2017/12/7.
 */
 
public class RecommendTopFragment extends RetainViewFragment implements View.OnClickListener, MainActivity.MyTouchListener {
 
 
    private LinearLayout ll_no_net, ll_no_data, ll_request_failture;
    private ConnectivityChangeHelper mChangeHelper;
    private FrameLayout fl_search_content;
    private RelativeLayout ll_recommend_content;
 
    private MagicIndicator magic_indicator;
 
    //上次请求homeConfig的uid
    private Long lastRquestHomeConfigUid = null;
 
    /*
     * viewpager定义
     */
    CategoryTopAdapter adapter;
    ViewPager pager;
    ShapeLoadingDialog pd = null;
 
    private DiskLruCache cache;
    private boolean isCache = false;
    private int clickState = 0;
    //热门功能
    private ImageView recommend_top_img;
 
 
    //福利底部提醒
    private FrameLayout fl_fuli;
    private ImageView iv_fuli_portrait;
    private TextView tv_fuli_title;
    private TextView tv_fuli_sub_title;
    private TextView tv_time_h, tv_time_m, tv_time_s;
 
 
    String tag1 = "config/getHomeConfig";
    String tag2 = "navbar/getHomeItems";
    String tag3 = "navbar/changeSex";
    String tag4 = "customer/getuserinfoNew";
    String tag5 = "dynamic/getClass";
    String tag6 = "dynamic/getList";
    String tag7 = "brand/getClass";
    String tag8 = "brand/getShopList";
    String tag9 = "brand/getHistory";
    String tag10 = "msg/getHomeMsgListNew";
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_recommend_top;
    }
 
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            cache = DiskLruCache.open(
                    new File(StorageUtils.getCacheDirectory(getContext())
                            .toString(), "http"), getVersionNum(getContext()),
                    1, 1024 * 1024);
        } catch (IOException e) {
            e.printStackTrace();
        }
//        Log.e("mResult", "首页onCreate");
    }
 
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        OkHttpUtils.getInstance().cancelTag(tag1);
        OkHttpUtils.getInstance().cancelTag(tag2);
        OkHttpUtils.getInstance().cancelTag(tag3);
        OkHttpUtils.getInstance().cancelTag(tag4);
        OkHttpUtils.getInstance().cancelTag(tag5);
        OkHttpUtils.getInstance().cancelTag(tag6);
        OkHttpUtils.getInstance().cancelTag(tag7);
        OkHttpUtils.getInstance().cancelTag(tag8);
        OkHttpUtils.getInstance().cancelTag(tag9);
        OkHttpUtils.getInstance().cancelTag(tag10);
    }
 
    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 String getKey(String method) {
        return new Md5FileNameGenerator().generate(method);
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getActivity().getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            int result = 0;
            int resourceId = getActivity().getResources().getIdentifier("status_bar_height",
                    "dimen", "android");
            if (resourceId > 0) {
                result = getActivity().getResources().getDimensionPixelSize(resourceId);
            }
            //设置状态栏文字颜色及图标为深色
//            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    result);
//            contentView.findViewById(R.id.v_status_bar).setLayoutParams(params);
            try {
                Class decorViewClazz = Class.forName("com.android.internal.policy.DecorView");
                Field field = decorViewClazz.getDeclaredField("mSemiTransparentStatusBarColor");
                field.setAccessible(true);
                field.setInt(getActivity().getWindow().getDecorView(), Color.TRANSPARENT);  //改为透明
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            if (contentView.findViewById(R.id.v_status_bar) != null)
                contentView.findViewById(R.id.v_status_bar).setVisibility(View.GONE);
        }
 
        contentView.findViewById(R.id.tv_course).setOnClickListener(this);
        recommend_top_img = contentView.findViewById(R.id.recommend_top_img);//热门功能
        fl_search_content = contentView.findViewById(R.id.fl_search_content);
        fl_search_content.setOnClickListener(this);
        recommend_top_img.setOnClickListener(this);
        /**
         * 热门活动长按删除
         */
        recommend_top_img.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                SharedPreferences.Editor editor = getContext().getSharedPreferences("guide", MODE_PRIVATE).edit();
//                .getBoolean("longdelete", false)
                editor.putBoolean("longdelete", true);//设置长按删除
                editor.commit();
                recommend_top_img.setVisibility(View.GONE);
                Toast.makeText(ll_no_data.getContext(), "感谢使用,删除成功", Toast.LENGTH_LONG).show();
                return false;
            }
        });
 
        ll_recommend_content = contentView.findViewById(R.id.ll_recommend_content);
        magic_indicator = contentView.findViewById(R.id.magic_indicator);
        pager = contentView.findViewById(R.id.viewpager);
 
        ll_no_net = contentView.findViewById(R.id.ll_no_net);
        ll_no_data = contentView.findViewById(R.id.ll_no_data);
        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);
        mChangeHelper = new ConnectivityChangeHelper(ll_recommend_content.getContext(),
                new ConnectivityChangeHelper.OnConnectivityChangeListener() {
 
                    @Override
                    public void onNetworkUnAvailable() {
                        if (mList.size() == 0)
                            requestState(3);
                    }
 
                    @Override
                    public void onNetworkAvailable() {
                        requestState(0);
                        if (mList.size() == 0 || isCache) {
                            getHomeNavbar();
                        }
                    }
                });
 
        ll_no_data.setOnClickListener(this);
 
        initFuliFloat(contentView);
 
        MainCustomEvent.mainHome(getContext());
        loadCacheData();
        getTrendsType();//缓存动态标题
        getTab();//缓存品牌标题
        getMessage();
 
//viewpager滑动监听
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
 
            @Override
            public void onPageSelected(int position) {
                //首页精选+未长按删除+服务返回显示
                if (position == 0 && !isTestingUser() && hotFucion && !hotFuctionLink.equals("")) {
                    if (recommend_top_img != null) {
                        recommend_top_img.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (recommend_top_img != null) {
                        recommend_top_img.setVisibility(View.GONE);
                    }
                }
            }
 
            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
 
 
        /** 触摸事件的注册 */
        ((MainActivity) getActivity()).registerMyTouchListener(this);
 
 
        //app更新检测
        new UpdateApp(getActivity(), getResources().getString(R.string.update_key)).getUpdateInfo(new UpdateApp.UpdateJudgeCallback() {
 
            @Override
            public void onSuccess(boolean show) {
 
            }
 
            @Override
            public void closeUpdate(boolean close) {
 
            }
 
            @Override
            public void onFinish() {
                getHomeConfig();
            }
        }, false);//强制检测更新-否.
 
        //设置背景色
        contentView.findViewById(R.id.apl_search).setBackground(HomeUIUtil.getHomeTopBg(getContext()));
        magic_indicator.setBackground(HomeUIUtil.getHomeTopBg(getContext()));
 
    }
 
    CommonNavigator commonNavigator = null;
 
    private void loadCacheData() {
        if (cache != null) {
            getActivity().setTheme(R.style.AppTabTheme1);
            isCache = false;
            requestState(0);
 
            DiskLruCache.Snapshot snapshot = null;
            try {
                snapshot = cache.get(getKey("getFirstCategory"));
                if (snapshot != null) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    final List<FirstCategory> list = gson.fromJson(
                            snapshot.getString(0),
                            new TypeToken<List<FirstCategory>>() {
                            }.getType());
                    //获取性别
                    sex = ll_recommend_content.getContext().getSharedPreferences("user",
                            MODE_PRIVATE).getInt("sex", 0);
 
                    if (mList.size() > 0)
                        mList.clear();
                    FirstCategory category = new FirstCategory();
                    category.setName("精选");
                    mList.add(category);
                    mList.addAll(list);
                    loadHomeNavData();
                    requestState(0);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (snapshot != null) {
                    snapshot.close();
                }
            }
        }
 
    }
 
    private CommonNavigatorAdapter n1 = new CommonNavigatorAdapter() {
 
        @Override
        public int getCount() {
            return mList == null ? 0 : mList.size();
        }
 
        @Override
        public IPagerTitleView getTitleView(final Context context, final int index) {
            CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(getContext());
            //设置自定义布局文件及view赋值
            commonPagerTitleView.setContentView(R.layout.item_recommend_nav);
            commonPagerTitleView.setHovered(false);
            final TextView tvTitle = commonPagerTitleView.findViewById(R.id.tv_title);
            tvTitle.setHighlightColor(context.getResources().getColor(android.R.color.transparent));
            tvTitle.setText(mList.get(index).getName());
            tvTitle.setBackground(null);
 
            //tab切换监听
            commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() {
                @Override
                public void onSelected(int index, int totalCount) {
                    tvTitle.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                }
 
                @Override
                public void onDeselected(int index, int totalCount) {
                    tvTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                }
 
                @Override
                public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {
 
                }
 
                @Override
                public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {
 
                }
            });
 
            //tab单个item点击事件监听
            commonPagerTitleView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pager.setCurrentItem(index);
                }
            });
 
            return commonPagerTitleView;
        }
 
        //此为tab指示器回调
        @Override
        public IPagerIndicator getIndicator(Context context) {
            int height = magic_indicator.getLayoutParams().height; //UIUtil.dip2px(context, 40);
            HomeRecommendNavIndicator indicator = new HomeRecommendNavIndicator(context);
            float navigatorHeight = DimenUtils.sp2px(context, 25); //context.getResources().getDimension(R.dimen.dp_130);
            float borderWidth = UIUtil.dip2px(context, 1);
            float lineHeight = navigatorHeight - 2 * borderWidth;
            indicator.setLineHeight(lineHeight);
            indicator.setRoundRadius(lineHeight / 2);
            indicator.setXOffset(UIUtil.dip2px(context, 5));
            indicator.setYOffset((height - navigatorHeight) / 2);
            indicator.setColors(Color.parseColor("#FFFFFF"));
            return indicator;
        }
    };
 
 
    private CommonNavigatorAdapter n2 = new CommonNavigatorAdapter() {
 
        @Override
        public int getCount() {
            return mList == null ? 0 : mList.size();
        }
 
        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context);
            clipPagerTitleView.setText(mList.get(index).getName());
            clipPagerTitleView.setTextColor(Color.parseColor("#FFFFFF"));
            clipPagerTitleView.setClipColor(Color.WHITE);
            clipPagerTitleView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pager.setCurrentItem(index);
                }
            });
            return clipPagerTitleView;
        }
 
        //此为tab指示器回调
        @Override
        public IPagerIndicator getIndicator(Context context) {
            int height = magic_indicator.getLayoutParams().height; //UIUtil.dip2px(context, 40);
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            float navigatorHeight = DimenUtils.sp2px(context, 25); //context.getResources().getDimension(R.dimen.dp_130);
            float borderWidth = UIUtil.dip2px(context, 1);
            float lineHeight = navigatorHeight - 2 * borderWidth;
            indicator.setLineHeight(lineHeight);
            indicator.setRoundRadius(lineHeight / 2);
            indicator.setYOffset((height - navigatorHeight) / 2);
            indicator.setColors(Color.parseColor("#bc2a2a"));
            return indicator;
        }
    };
 
 
    private void loadHomeNavData() {
        if (adapter == null) {
            adapter = new CategoryTopAdapter(
                    getChildFragmentManager());
            pager.setAdapter(adapter);
            pager.setOffscreenPageLimit(0);
            pager.setCurrentItem(0);
        } else {
            adapter.notifyDataSetChanged();
        }
 
 
        if (commonNavigator == null) {
            commonNavigator = new CommonNavigator(getContext());
            commonNavigator.setAdapter(n1);
            //设置给magicIndicator
            magic_indicator.setNavigator(commonNavigator);
            ViewPagerHelper.bind(magic_indicator, pager);
        } else {
            commonNavigator.notifyDataSetChanged();
        }
 
 
    }
 
    @Override
    public void onResume() {
        super.onResume();
        mChangeHelper.registerReceiver();
        SharedPreferences sp = ll_recommend_content.getContext()
                .getSharedPreferences("user", MODE_PRIVATE);
 
        isChange = false;
        ll_no_data.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mList.size() == 0) {
                    getHomeNavbar();
                }
                if (couponUrl.equals("")) {
                }
            }
        }, 1000);
 
        boolean isLogin = UserUtil.isLogin(getContext());
        if (isLogin) {
            getUserInfo(UserUtil.getUid(ShoppingApplication.application));
            if (accountLogin && floatImgDetail != null) {//弹框需要登陆
                accountLogin = false;
                final String showTime = floatImgDetail.optString("showTime"); // everyday-每天显示   always-每次进来都显示
                final String adid = floatImgDetail.optString("id"); // 唯一id
                final boolean playSound = floatImgDetail.optBoolean("playSound");//是否播放音效
                final HomeConfigSQHelper sqHelper = new HomeConfigSQHelper(ll_recommend_content.getContext());
                //记录是everyday 每天打开 第一次打开时间
                if (showTime.equalsIgnoreCase("everyday")) {
                    sqHelper.setShowTime(adid, System.currentTimeMillis() + "");//记录时间
                }
                Gson gson = new GsonBuilder().setPrettyPrinting().create();
                final EntityFather info = gson.fromJson(floatImgDetail.toString(), new TypeToken<EntityFather>() {
                }.getType());
                if (clickState == 3) {
                    clickState = 0;
                    if (playSound)//播放声音
                        ToolUtil.getPlaySound(ll_recommend_content.getContext());
                    ToolUtil.setClickSpe(info, ll_recommend_content.getContext());
                } else if (clickState == 4) {
                    clickState = 0;
                    //记录是everyday 每天打开 第一次打开时间
                    if (showTime.equalsIgnoreCase("everyday")) {
                        sqHelper.setShowTime(adid, System.currentTimeMillis() + "");//记录时间
                    }
                    if (playSound)//播放声音
                        ToolUtil.getPlaySound(ll_recommend_content.getContext());
                    ToolUtil.setClickSpe(info, ll_recommend_content.getContext());
                }
            }
        }
 
        if (isLogin && lastRquestHomeConfigUid == null) {
            getHomeConfig();
        }
 
        getSendingHongbao();
    }
 
    /*
     *刷新分类
     */
    private void refreshCategory(SharedPreferences sp) {
        //通过判断数据是否相等,决定是否刷新数据
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < mList.size(); i++) {
            if (!StringUtils.isEmpty(mList.get(i).getId()))
                jsonArray.add(mList.get(i).getId());
        }
        String ids = jsonArray.toJSONString();
        String changeIds = sp.getString("myCategory", "");
        if (!ids.equalsIgnoreCase(changeIds)) {
            getHomeNavbar();
            isChange = false;
        }
    }
 
 
    @Override
    public void onPause() {
        super.onPause();
        mChangeHelper.unregisterReceiver();
//        Log.e("mResult", "首页onPause");
    }
 
    boolean isChange = false;
 
    @Override
    public void onClick(View view) {
        clickState = 0;
        switch (view.getId()) {
 
            case R.id.fl_search_content:
                SearchCustomEvent.searchHome(getContext());
                Intent intent = new Intent(ll_recommend_content.getContext(), SearchActivity.class);
                startActivity(intent);
                break;
            //分类
            case R.id.iv_category_top:
                CategoryCustomEvent.classHomeRight(getContext());
                startActivity(new Intent(ll_no_data.getContext(), CategoryTypeActivity.class));
                break;
            case R.id.ll_no_data:
                getHomeNavbar();
                break;
            case R.id.tv_net_setting:
                ll_recommend_content.getContext().startActivity(new Intent(Settings.ACTION_SETTINGS));
                break;
            //热门功能
            case R.id.recommend_top_img:
                //没有显示状态
                if (recommend_top_img.getVisibility() != View.VISIBLE) {
                    return;
                }
                if (!top_img) {//收入状态 点击弹出
                    top_img = true;
                    translateAnimation(imgwidth, false);
                    //第一次点击
                    if (getContext().getSharedPreferences("guide", MODE_PRIVATE).getInt("homeonclick", 0) == 0) {
                        Toast.makeText(ll_no_data.getContext(), "滑出后长按可删除", Toast.LENGTH_LONG).show();
                        SharedPreferences.Editor editor = getContext().getSharedPreferences("guide", MODE_PRIVATE).edit();
                        editor.putInt("homeonclick", 1);//设置 已经点击过
                        editor.apply();
                    }
                } else {//伸出状态 点击跳转
                    if (hotFuctionLink != null && !hotFuctionLink.equals("")) {
                        Intent intent1 = new Intent(getContext(), ShareBrowserActivity.class);
                        intent1.putExtra("url", hotFuctionLink);
                        startActivity(intent1);
                    }
                }
                break;
            case R.id.tv_course:
                //教程
                startActivity(new Intent(getContext(), ShareBrowserActivity.class).putExtra("url", SystemParamsUtil.getNewerCourse(getContext())));
                break;
            default:
                break;
        }
    }
 
    //热门功能 伸缩状态  false缩 ture伸
    private boolean top_img = false;
    //热门功能 图片宽度
    private float imgwidth = 270;
 
    /**
     * 平移
     * 热门功能 弹出状态
     * android:translationY 属性值意思就是在水平方向移动
     * ...values: 动画过渡值,过渡值可以有一个到N个,如果是一个值的话,就默认是这个动画过渡值的结束值,
     * 如果有N个值,动画就在这N个值之间过渡,本例中有三个过渡值"0.0f, 350.0f, 0f",意思就是从当前位置向右滑到350的位置,再滑到位置0,即初始位置。
     */
    private void translateAnimation(float Width, boolean isTesting) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(recommend_top_img, "translationX", -(Width - 75), -23);
        objectAnimator.setDuration(190);
        objectAnimator.setRepeatCount(0);//重复次数
//        objectAnimator.setRepeatMode(Animation.RESTART);//重复模式
        objectAnimator.start();
        //做5秒延时 隐藏
        if (isTesting) {
//            Log.e("eee", "做5秒延时 隐藏: ");
            objectAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    //滑动 完成
                    ll_no_data.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //显示状态 隐藏
                            if (recommend_top_img != null && recommend_top_img.getVisibility() == View.VISIBLE) {
                                recommend_top_img.setVisibility(View.GONE);
                            }
//                            Log.e("eee", "做5秒延时 隐藏完成: ");
                        }
                    }, 5000);
                }
            });
        }
    }
 
    /**
     * 平移
     * 热门功能 收入状态
     */
    private void translateAnimation2(float Width, int duration) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(recommend_top_img, "translationX", -(Width - 75));
        objectAnimator.setDuration(duration);
        objectAnimator.setRepeatCount(0);//重复次数
        objectAnimator.start();
    }
 
    //手指按下的点为(x1, y1)手指离开屏幕的点为(x2, y2)
    private float x1 = 0;
    private float x2 = 0;
    private float y1 = 0;
    private float y2 = 0;
 
    /**
     * fragment 的触摸事件
     *
     * @param event
     */
    @Override
    public void onTouchEvent(MotionEvent event) {
        //继承了Activity的onTouchEvent方法,直接监听点击事件
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            //当手指按下的时候
            x1 = event.getX();
            y1 = event.getY();
        }
        //手指滑动状态
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            //当手指滑动的时候
            x2 = event.getX();
            y2 = event.getY();
            if (y1 - y2 > 50) {   //向上滑
                if (top_img) {//收入状态 点击弹出
                    top_img = false;
                    if (recommend_top_img != null && recommend_top_img.getVisibility() == View.VISIBLE) {
                        translateAnimation2(imgwidth, 85);
                    }
                }
            } else if (y2 - y1 > 50) {//向下滑
                if (top_img) {//收入状态 点击弹出
                    top_img = false;
                    if (recommend_top_img != null && recommend_top_img.getVisibility() == View.VISIBLE) {
                        translateAnimation2(imgwidth, 85);
                    }
                }
            }
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
            //当手指离开的时候
        }
    }
 
 
    boolean accountLogin = false;
    String couponUrl = "";
    JSONObject floatImgDetail;
 
    org.json.JSONArray adArray = null;
 
    /**
     * 显示用户协议与弹窗
     */
    private void showUserProtocolAndGuide(String protocol,
                                          final UserGuideDialog.FinishCallback callback) {
 
        boolean agreeProtocol = UserUtil.isAgreeUserProtocol(getContext());
        final boolean shownUserGuide = UserUtil.isShownUserGuide(getContext());
        if (agreeProtocol) {//已经同意用户协议
            if (shownUserGuide) {//用户引导已经显示
                callback.onFinish();
            } else {//需要显示用户引导
                new UserGuideDialog.Builder(getActivity()).setFinishCallback(new UserGuideDialog.FinishCallback() {
                    @Override
                    public void onFinish() {
                        callback.onFinish();
                    }
                }).create().show();
            }
        } else {
            final UserProtocolDialog.Builder dialogBuilder = new UserProtocolDialog.Builder(getActivity()).setData(protocol).setNegativeButton(null, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    getActivity().finish();
                }
            }).setPositiveButton(null, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    UserUtil.agreeUserProtocol(getContext());
                    dialog.dismiss();
                    if (shownUserGuide) {//用户引导已经显示
                        callback.onFinish();
                    } else {//需要显示用户引导
                        new UserGuideDialog.Builder(getActivity()).setFinishCallback(new UserGuideDialog.FinishCallback() {
                            @Override
                            public void onFinish() {
                                callback.onFinish();
                            }
                        }).create().show();
                    }
                }
            });
            dialogBuilder.create().show();
        }
    }
 
 
    private void getHomeConfig() {
        Long uid = UserUtil.getUid(ShoppingApplication.application);
        if (uid != null)
            lastRquestHomeConfigUid = uid;
        ShoppingApi.getHomeConfig(ll_recommend_content.getContext(), uid, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    String protocol = data.optString("protocol");
                    adArray = data.optJSONArray("listAD");
                    if (!UserUtil.isAgreeUserProtocol(getContext()) || !UserUtil.isShownUserGuide(getContext())) {
                        showUserProtocolAndGuide(protocol, new UserGuideDialog.FinishCallback() {
                            @Override
                            public void onFinish() {
                                EventBus.getDefault().post(new UserProtocolEvent(true));
                                showAdDialog(adArray);
                            }
                        });
                    } else {
                        showAdDialog(adArray);
                    }
 
 
//                    SharedPreferences sp = ll_recommend_content.getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
 
                    /***************** 热门功能 滑动展示*****/
                    //热门功能用户未长按删除 判断新老用户
                    if (!isTestingUser()) {
                        //0-新人  1-老人  新人显示热门功能
                        if (jsonObject.optJSONObject("data").getInt("userTimeType") == 0) {
                            recommend_top_img.setVisibility(View.VISIBLE);
                            //收入 热门弹窗
                            translateAnimation2(imgwidth, 0);
                            hotFucion = true;
                        } else {
                            //老人隐藏 (检测版本更新后 显示5秒)
                            //检测老用户是否更新版本
                            if (isTestingCode()) {//更新版本了
                                recommend_top_img.setVisibility(View.VISIBLE);
                                translateAnimation(imgwidth, true);//弹出 热门活动5秒后隐藏
                            } else {//隐藏热门活动
                                recommend_top_img.setVisibility(View.GONE);
                            }
                            hotFucion = false;
                        }
                        //当链接为空则 隐藏
                        if (jsonObject.optJSONObject("data").optString("hotFuctionLink") == null || jsonObject.optJSONObject("data").optString("hotFuctionLink").equals("")) {
                            //隐藏热门活动
                            recommend_top_img.setVisibility(View.GONE);
                        } else {
                            hotFuctionLink = jsonObject.optJSONObject("data").optString("hotFuctionLink");//热门功能链接
                        }
                    } else {//长按删除后 就一直隐藏
                        recommend_top_img.setVisibility(View.GONE);
                        hotFucion = false;
                    }
                }
            }
        });
    }
 
    /**
     * 显示广告弹窗
     *
     * @param array
     */
    private void showAdDialog(org.json.JSONArray array) {
 
        if (array != null) {
            for (int i = 0; i < array.length(); i++) {
                try {
                    floatImgDetail = (JSONObject) array.get(i);//传入 json数据
                    accountLogin = floatImgDetail.optBoolean("accountLogin");// 是否登录
                    String imgUrl = floatImgDetail.optString("img");// 悬浮图链接
                    JSONObject jumpDetail = floatImgDetail.optJSONObject("jumpDetail");
                    RedPacketHintDialog.Builder builder = new RedPacketHintDialog.Builder(getActivity());
                    builder.imgUrl(imgUrl);
                    if (jumpDetail == null) {
                        builder.setPositiveButton(new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).setNegativeButton(new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();
                    } else {
                        final String showTime = floatImgDetail.optString("showTime"); // everyday-每天显示   always-每次进来都显示
                        final String adid = floatImgDetail.optString("id"); // 唯一id
                        final boolean playSound = floatImgDetail.optBoolean("playSound");//是否播放音效
                        final HomeConfigSQHelper sqHelper = new HomeConfigSQHelper(ll_recommend_content.getContext());
                        //查询上次打开时间
                        String localtime = sqHelper.getShowTime(adid);
                        //设置每天打开 并且 今天打开过
//                                if (showTime.equalsIgnoreCase("everyday") && isSameDay(new Date(System.currentTimeMillis()), new Date(sp.getLong("redPacketHint", 0l)))) {
                        if (showTime.equalsIgnoreCase("everyday") && isSameDay(new Date(System.currentTimeMillis()),
                                new Date(StringUtils.isEmpty(localtime) ? 0l : Long.valueOf(localtime)))) {
                            continue;
                        }
                        Gson gson = new GsonBuilder().setPrettyPrinting().create();
                        final EntityFather info = gson.fromJson(floatImgDetail.toString(), new TypeToken<EntityFather>() {
                        }.getType());
                        //百川打开方式
                        if (jumpDetail.optString("type").equalsIgnoreCase("baichuan")) {
                            builder.setPositiveButton(new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    final boolean isLogin = UserUtil.isLogin(getContext());
                                    if (accountLogin && !isLogin) {
                                        clickState = 3;
                                        UserUtil.jumpLogin(getContext());
                                        dialog.dismiss();
                                    } else {
                                        //记录是everyday 每天打开 第一次打开时间
                                        if (showTime.equalsIgnoreCase("everyday")) {
                                            sqHelper.setShowTime(adid, System.currentTimeMillis() + "");//记录时间
                                        }
                                        if (playSound)//播放声音
                                            ToolUtil.getPlaySound(ll_recommend_content.getContext());
                                        clickState = 0;
                                        ToolUtil.setClickSpe(info, ll_recommend_content.getContext());
                                        dialog.dismiss();
                                    }
                                }
                            }).imgUrl(imgUrl).setNegativeButton(new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //记录是everyday 每天打开 第一次打开时间
                                    if (showTime.equalsIgnoreCase("everyday")) {
                                        sqHelper.setShowTime(adid, System.currentTimeMillis() + "");//记录时间
                                    }
                                    accountLogin = false;
                                    dialog.dismiss();
                                }
                            }).create();
                        } else {//直接展示
                            showHintDialog(builder, info, showTime, sqHelper, adid, playSound);
                        }
                        break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
    private String hotFuctionLink = "";//热门功能点击 跳转页面
    private boolean hotFucion = false;//热门功能是否显示
 
    /**
     * 检测用户是否 长按删除热门活动
     *
     * @return true(长按删除) false(未删除)
     */
    private boolean isTestingUser() {
        //引导页 记录
        if (getContext().getSharedPreferences("guide", MODE_PRIVATE).getBoolean("longdelete", false))
            return true;  //已经删除
        else
            return false;//未删除
    }
 
    /**
     * 检测老用户 是否更新版本
     */
    private boolean isTestingCode() {
        //当前版本号
        int versionCode = SystemCommon.getVersonCode(getContext());
        //未更新版本
        if (versionCode == getContext().getSharedPreferences("user", MODE_PRIVATE).getInt("versionCode", 0)) {
            return false;
        } else {//更新版本
            SharedPreferences.Editor editor = getContext().getSharedPreferences("user", MODE_PRIVATE).edit();
            editor.putInt("versionCode", versionCode);
            editor.commit();
            return true;
        }
 
    }
 
    /**
     * @param date     当前时间
     * @param sameDate 上次打开时间
     * @return
     */
    private boolean isSameDay(Date date, Date sameDate) {
        if (null == date || null == sameDate) {
            return false;
        }
 
        Calendar nowCalendar = Calendar.getInstance();
        nowCalendar.setTime(sameDate);
 
        Calendar dateCalendar = Calendar.getInstance();
        dateCalendar.setTime(date);
        return nowCalendar.get(Calendar.YEAR) == dateCalendar.get(Calendar.YEAR)//四位年份
                && nowCalendar.get(Calendar.MONTH) == dateCalendar.get(Calendar.MONTH)//月份
                && nowCalendar.get(Calendar.DATE) == dateCalendar.get(Calendar.DATE);//一个月的日期
    }
 
    /**
     * 展示提示Dialog
     *
     * @param builder
     * @param info      图片信息
     * @param showTime  显示时间 everyday always
     * @param sqHelper  数据库查询
     * @param adid      ad唯一ID
     * @param playSound 是否播放声音
     */
    private void showHintDialog(RedPacketHintDialog.Builder builder, final EntityFather info,
                                final String showTime,
                                final HomeConfigSQHelper sqHelper, final String adid, final boolean playSound) {
 
        builder.setPositiveButton(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                final boolean isLogin = UserUtil.isLogin(getContext());
                if (accountLogin && !isLogin) {
                    clickState = 4;
                    UserUtil.jumpLogin(getContext());
                    dialog.dismiss();
                } else {
//                    openActivity();
                    //记录是everyday 每天打开 第一次打开时间
                    if (showTime.equalsIgnoreCase("everyday")) {
                        sqHelper.setShowTime(adid, System.currentTimeMillis() + "");//记录时间
                    }
                    if (playSound)//播放声音
                        ToolUtil.getPlaySound(ll_recommend_content.getContext());
//                    ToolUtil.setClickSpe(info, ll_recommend_content.getContext());
 
                    JumpActivityUtil.jumpPage(getActivity(), info.getJumpDetail(), info.getParams());
                    dialog.dismiss();
                }
 
            }
        }).setNegativeButton(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //记录是everyday 每天打开 第一次打开时间
                if (showTime.equalsIgnoreCase("everyday")) {
                    sqHelper.setShowTime(adid, System.currentTimeMillis() + "");//记录时间
                }
                accountLogin = false;
                dialog.dismiss();
            }
        }).create();
    }
 
    List<FirstCategory> mList = new ArrayList<>();
 
    /**
     * 首页分类
     */
    private void getHomeNavbar() {
        if (pd == null) {
            pd = new ShapeLoadingDialog.Builder(getContext()).build();
        }
        if (mList.size() == 0)
            pd.show();
 
        ShoppingApi.getHomeNavbar(ll_recommend_content.getContext(), UserUtil.getUid(ShoppingApplication.application),
                new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                            getActivity().setTheme(R.style.AppTabTheme1);
                            isCache = false;
                            ll_recommend_content.setVisibility(View.VISIBLE);
                            ll_no_net.setVisibility(View.GONE);
                            ll_no_data.setVisibility(View.GONE);
 
                            sex = jsonObject.optJSONObject("data").optInt("sex");
 
                            ll_recommend_content.getContext().getSharedPreferences("user",
                                    MODE_PRIVATE).edit().putInt("sex", sex).commit();
                            Gson gson = new GsonBuilder().serializeNulls().create();
                            final List<FirstCategory> list = gson.fromJson(
                                    jsonObject.optJSONObject("data")
                                            .optJSONArray("listNavbar").toString(),
                                    new TypeToken<List<FirstCategory>>() {
                                    }.getType());
                            if (mList.size() > 0)
                                mList.clear();
                            FirstCategory category = new FirstCategory();
                            category.setName("精选");
                            mList.add(category);
                            mList.addAll(list);
 
 
                            DiskLruCache.Editor editor = cache
                                    .edit(getKey("getFirstCategory"));
                            editor.set(0, jsonObject.optJSONObject("data")
                                    .optJSONArray("listNavbar").toString());
                            editor.commit();
                            loadHomeNavData();
                            requestState(mList.size() == 0 ? 1 : 0);
                        } else {
                            requestState(2);
                            if (jsonObject != null && getContext() != null)
                                Toast.makeText(getContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                        }
                    }
 
                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        super.onFailure(statusCode, headers, responseString, throwable);
                        if (cache != null) {
                            DiskLruCache.Snapshot snapshot = null;
                            try {
                                snapshot = cache.get(getKey("getFirstCategory"));
                            } catch (Exception e) {
 
                            }
                            if (snapshot == null && mList.size() == 0) {
                                if (NetUtils.getNetworkState(getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                                    requestState(3);
                                    Toast.makeText(getContext(), "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
                                } else {
                                    requestState(2);
                                    Toast.makeText(getContext(), "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                if (NetUtils.getNetworkState(getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                                    Toast.makeText(getContext(), "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(getContext(), "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
                                }
                            }
                        } else {
                            if (NetUtils.getNetworkState(getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                                requestState(3);
                                Toast.makeText(getContext(), "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
                            } else {
                                requestState(2);
                                Toast.makeText(getContext(), "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        if (pd.isShowing())
                            pd.dismiss();
                    }
                });
    }
 
    /**
     * 性别改变
     */
    int sex = -2;
    //男女切换 标识
    private boolean isSexChange = true;
 
 
    private void tbLogin() {
        final AlibcLogin alibcLogin = AlibcLogin.getInstance();
        if (!alibcLogin.isLogin()) {
//            Log.e("mResult", "RecommendTopFragment调用淘宝登录");
            alibcLogin.showLogin(new AlibcLoginCallback() {
 
                @Override
                public void onSuccess(int i, String s, String s1) {
                    SharedPreferences.Editor editor = getContext()
                            .getSharedPreferences("user", MODE_PRIVATE).edit();
                    editor.putString("TrolleyTransformationLink", "");
                    editor.commit();
                    bindInfo();
                }
 
                @Override
                public void onFailure(int code, String msg) {
                    Toast.makeText(ll_no_data.getContext(), "登录失败,请稍候再试",
                            Toast.LENGTH_LONG).show();
                    clickState = 0;
                    MobclickAgent.reportError(ll_no_data.getContext(), "MineFragment---sscode:" + code + "---msg:" + msg);
                }
            });
        } else {
            bindInfo();
        }
    }
 
 
    class CategoryTopAdapter extends FragmentStatePagerAdapter {
 
 
        public CategoryTopAdapter(FragmentManager fm) {
            super(fm);
        }
 
        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }
 
        @Override
        public Fragment getItem(int position) {
            if (position == 0 || (!StringUtils.isEmpty(mList.get(position).getType()) && mList.get(position).getType().equals("weex"))) {
                CategoryCustomEvent.classHomeList(getContext(), "");
                return RecommendFragment.newInstance(mList.get(position));
            }
            CategoryCustomEvent.classHomeList(getContext(), mList.get(position).getName());
            if (!StringUtils.isEmpty(mList.get(position).getType()) && mList.get(position).getType().equals("commonTemplate")) {//跳转通用模版
                //新建一个Fragment来展示ViewPager item的内容,并传递参数
                GmTemplateContentFragment fragment = new GmTemplateContentFragment();
                Bundle args = new Bundle();
                args.putString("key", mList.get(position).getParams().getString("key"));
                args.putString("type", mList.get(position).getParams().getInteger("type") + "");
                fragment.setArguments(args);
                return fragment;
            } else {
                return RecommendCategoryFragment.newInstance(mList.get(position), position);
            }
        }
 
        @Override
        public CharSequence getPageTitle(int position) {
//            if (position == 1) {
//                mList.get(position).setName("");
//            }
            return mList.get(position % mList.size()).getName();
        }
 
        @Override
        public int getCount() {
            return mList.size();
        }
 
    }
 
    private void bindInfo() {
        if (clickState == 1) {
            clickState = 0;
            startActivity(new Intent(ll_no_data.getContext(), ShoppingTrolleyActivity.class));
        }
    }
 
    String openid;
 
    private void getUserInfo(final Long uid) {
        ShoppingApi.getUserInfo2(ll_no_data.getContext(), uid, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    UserInfo info = gson.fromJson(data.optJSONObject("user").toString(), new TypeToken<UserInfo>() {
                    }.getType());
                    openid = info.getOpenid();
                    String inviteCode = data.optString("invitCode");
                    UserUtil.setInviteCode(getContext(), inviteCode);
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                SharedPreferences sp = ll_no_data.getContext().getSharedPreferences("user", MODE_PRIVATE);
                AlibcLogin alibcLogin = AlibcLogin.getInstance();
                if (clickState == 1) {
                    if (alibcLogin.isLogin()) {
                        clickState = 0;
                        startActivity(new Intent(ll_no_data.getContext(), ShoppingTrolleyActivity.class));
                    } else {
                        tbLogin();
                    }
                }
            }
        });
    }
 
    /**
     * 请求状态 0 数据正常展示;1 返回数据为空;2 网络请求失败;3 没有连接网络
     *
     * @param state
     */
    private void requestState(int state) {
        ll_recommend_content.setVisibility(state == 0 ? 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 onDestroy() {
        super.onDestroy();
        /** 触摸事件的注销 */
        ((MainActivity) this.getActivity()).unRegisterMyTouchListener();
    }
 
    /**
     * 动态页面数据添加分类缓存
     */
    private void getTrendsType() {
        ShoppingApi.getTrendsClass(getContext(), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
 
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    List<TrendsType> types = gson.fromJson(jsonObject.optJSONObject("data")
                                    .optJSONArray("list").toString(),
                            new TypeToken<List<TrendsType>>() {
                            }.getType());
 
                    DiskLruCache.Editor editor = cache
                            .edit(getKey("getTrendsType"));
                    editor.set(0, jsonObject.optJSONObject("data")
                            .optJSONArray("list").toString());
                    editor.commit();
 
                    getTrendsList(types.get(0).getId() + "", types.get(0).getListSub().get(0).getId() + "");
                }
            }
        });
    }
 
    /**
     * 获取动态首屏内容
     *
     * @param cId
     * @param subId
     */
    private void getTrendsList(String cId, String subId) {
        ShoppingApi.getRecommendActivity(ll_recommend_content.getContext(), 1 + "", cId + "",
                subId, new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        if (jsonObject.optString("code").equalsIgnoreCase("0")) {
 
                            DiskLruCache.Editor editor = cache
                                    .edit(getKey("getTrendsList"));
                            editor.set(0, jsonObject.optJSONObject("data").optJSONArray("list").toString());
                            editor.commit();
                        }
                    }
                });
    }
 
 
    /**
     * 获取 品牌标题栏数据
     */
    private void getTab() {
        ShoppingApi.getClass(ll_recommend_content.getContext(), new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    BrandFragment.navBgPicture = jsonObject.optJSONObject("data").optString("bgPicture");
                    DiskLruCache.Editor editor = cache
                            .edit(getKey("getBrandType"));
                    editor.set(0, jsonObject.optJSONObject("data")
                            .optJSONArray("list").toString());
                    editor.commit();
                    getShopList(0 + "");
                    getCateGorySecond(0 + "");
                }
            }
 
        });
    }
 
    /**
     * 获取品牌首屏内容
     */
    private void getShopList(String id) {
        //精选
        SharedPreferences sp = getActivity().getSharedPreferences("user", MODE_PRIVATE);
        ShoppingApi.getShopList(ll_recommend_content.getContext(), 1 + "", id, UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() {
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
 
                    DiskLruCache.Editor editor = cache
                            .edit(getKey("getShopList"));
                    editor.set(0, jsonObject.optJSONObject("data").toString());
                    editor.commit();
                }
            }
        });
    }
 
 
    /**
     * 获取店铺足迹/上方店铺  九宫格数据
     */
    private void getCateGorySecond(String id) {
        //精选
        if (id.equals("0")) {
            SharedPreferences sp = getActivity().getSharedPreferences("user", MODE_PRIVATE);
            ShoppingApi.getHistory(ll_recommend_content.getContext(), "1", UserUtil.getUid(ShoppingApplication.application), "1", new BasicTextHttpResponseHandler() {
                @Override
                public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                    if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                        DiskLruCache.Editor editor = cache
                                .edit(getKey("getJingxuanHistory"));
                        editor.set(0, jsonObject.optJSONObject("data")
                                .optJSONArray("list").toString());
                        editor.commit();
                    }
                }
            });
        }
    }
 
    /**
     * 获取消息列表并缓存
     */
    private void getMessage() {
        SharedPreferences sp = ll_recommend_content.getContext().getSharedPreferences("user", MODE_PRIVATE);
        ShoppingApi.getHomeMsgList(ll_recommend_content.getContext(), UserUtil.getUid(ShoppingApplication.application), 1 + "", new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                DiskLruCache.Editor editor = cache
                        .edit(getKey("getHomeMsgList"));
                editor.set(0, jsonObject.optJSONObject("data")
                        .optJSONArray("list").toString());
                editor.commit();
 
                if (jsonObject.optJSONObject("data")
                        .optJSONArray("systemMsg") != null) {
                    DiskLruCache.Editor editor1 = cache
                            .edit(getKey("systemMsg"));
                    editor1.set(0, jsonObject.optJSONObject("data")
                            .optJSONArray("systemMsg").toString());
                    editor1.commit();
                }
 
                if (jsonObject.optJSONObject("data")
                        .optJSONArray("commonList") != null) {
                    DiskLruCache.Editor editor2 = cache
                            .edit(getKey("commonList"));
                    editor2.set(0, jsonObject.optJSONObject("data")
                            .optJSONArray("commonList").toString());
                    editor2.commit();
                }
 
            }
        });
    }
 
 
    private void initFuliFloat(View contentView) {
        fl_fuli = contentView.findViewById(R.id.fl_fuli);
        iv_fuli_portrait = contentView.findViewById(R.id.iv_portrait);
        tv_fuli_title = contentView.findViewById(R.id.tv_title);
        tv_fuli_sub_title = contentView.findViewById(R.id.tv_sub_title);
        tv_time_h = contentView.findViewById(R.id.tv_time_h);
        tv_time_m = contentView.findViewById(R.id.tv_time_m);
        tv_time_s = contentView.findViewById(R.id.tv_time_s);
        fl_fuli.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLijinHongBaoDialog();
            }
        });
    }
 
    private Runnable lijinHongBaoRunnable = new Runnable() {
        @Override
        public void run() {
            if (lijinSendInfo == null) {
                if (fl_fuli != null)
                    fl_fuli.setVisibility(View.GONE);
                return;
            }
 
            //倒计时设置
            int leftTime = (int) ((lijinSendInfo.getExpireTime() - System.currentTimeMillis()) / 1000);
            if (leftTime <= 0) {
                if (fl_fuli != null)
                    fl_fuli.setVisibility(View.GONE);
                //移除SharePreference
                SharedPreferences.Editor editor = getContext().getSharedPreferences("lijinHongBao", MODE_PRIVATE).edit();
                editor.remove(lijinSendInfo.getMd5());
                editor.commit();
                return;
            }
            //设置时间
            int h = leftTime / (60 * 60);
            int m = (leftTime - h * 60 * 60) / 60;
            int s = leftTime % 60;
            if (tv_time_h != null)
                tv_time_h.setText(h < 10 ? ("0" + h) : (h + ""));
            if (tv_time_m != null)
                tv_time_m.setText(m < 10 ? ("0" + m) : (m + ""));
            if (tv_time_s != null)
                tv_time_s.setText(s < 10 ? ("0" + s) : (s + ""));
            if (fl_fuli != null) {
                fl_fuli.postDelayed(lijinHongBaoRunnable, 1000);
            }
        }
    };
 
    LijinSendInfo lijinSendInfo;
 
    /**
     * 设置福利数据
     */
    private void setFuliData() {
        //移除监听
        fl_fuli.removeCallbacks(lijinHongBaoRunnable);
        if (lijinSendInfo == null) {
            fl_fuli.setVisibility(View.GONE);
        } else {
            fl_fuli.setVisibility(View.VISIBLE);
            tv_fuli_title.setText(lijinSendInfo.getNotifyTitle());
            tv_fuli_sub_title.setText(lijinSendInfo.getNotifySubtitle());
            if (lijinHongBaoRunnable != null)
                lijinHongBaoRunnable.run();
            if (lijinSendInfo.getUser() != null) {
                Glide.with(this).load(lijinSendInfo.getUser().getPortrait()).transform(new GlideCircleTransform(getContext())).into(iv_fuli_portrait);
            } else
                Glide.with(this).load(R.drawable.ic_default_portrait_light).transform(new GlideCircleTransform(getContext())).into(iv_fuli_portrait);
        }
    }
 
 
    //显示礼金红包
    private void showLijinHongBaoDialog() {
        final SharedPreferences sharedPreferences = getContext().getSharedPreferences("lijinHongBao", MODE_PRIVATE);
        //显示
        new RecommendHbDialog.Builder(getContext()).setHBInfo(lijinSendInfo).setActionListener(new RecommendHbDialog.Builder.ILijinHongBaoAction() {
            @Override
            public void onClose() {
                if (lijinSendInfo != null && !StringUtils.isNullOrEmpty(lijinSendInfo.getMd5())) {
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString(lijinSendInfo.getMd5(), new Gson().toJson(lijinSendInfo));
                    editor.commit();
                }
 
                setFuliData();
            }
 
            @Override
            public void onRecieveSuccess() {
                //领取成功
                //移除sharePrefer
 
                //移除当前的md5
                if (lijinSendInfo != null) {
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.remove(lijinSendInfo.getMd5());
                    editor.commit();
                    lijinSendInfo = null;
                }
                setFuliData();
            }
        }).create().show();
 
    }
 
    /**
     * 获取发送中的红包
     */
    private synchronized void getSendingHongbao() {
 
        ShoppingApi.getSendingHongBao(getContext(), new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                super.onSuccessPerfect(statusCode, headers, jsonObject);
                if (jsonObject.optInt("code") == 0) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    final LijinSendInfo sendInfo = new Gson().fromJson(data.toString(), LijinSendInfo.class);
                    lijinSendInfo = sendInfo;
                    final SharedPreferences sharedPreferences = getContext().getSharedPreferences("lijinHongBao", MODE_PRIVATE);
                    if (StringUtils.isNullOrEmpty(sharedPreferences.getString(sendInfo.getMd5(), "")))
                        showLijinHongBaoDialog();
                    else {
                        setFuliData();
                    }
 
                } else {
                    lijinSendInfo = null;
                    setFuliData();
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
            }
        });
    }
 
 
}