wjc
2024-12-18 c58893ebe3a003d35c687a183ef3c9d4de1430fe
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
package com.hdl.photovoltaic.ui.powerstation;
 
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
 
import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 
import com.google.gson.Gson;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.bean.PageNumberObject;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.databinding.FragmentHouseListBinding;
import com.hdl.photovoltaic.base.CustomBaseFragment;
import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
import com.hdl.photovoltaic.enums.LowerTagType;
import com.hdl.photovoltaic.enums.PowerStationStatus;
import com.hdl.photovoltaic.enums.ShowErrorMode;
import com.hdl.photovoltaic.enums.SortType;
import com.hdl.photovoltaic.enums.SortValue;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.listener.LinkCallBack;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlDeviceLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlOtaLogic;
import com.hdl.photovoltaic.other.HdlResidenceLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.ui.adapter.DeviceInfoAdapter;
import com.hdl.photovoltaic.ui.adapter.HouseInfoAdapter;
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.ui.bean.StatusOverviewBean;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.photovoltaic.utils.URLEncodingUtils;
import com.hdl.photovoltaic.widget.DefaultFilteringDialog;
import com.hdl.photovoltaic.widget.DelayedConfirmationCancelDialog;
import com.hdl.sdk.link.common.exception.HDLLinkException;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
import com.hdl.sdk.link.core.config.HDLLinkConfig;
import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient;
import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
 
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 电站和设备-界面
 */
public class HouseAndDeviceFragment extends CustomBaseFragment {
 
    private boolean isReadData = false;
    private FragmentHouseListBinding viewBinding;
    private HouseInfoAdapter houseInfoAdapter;
 
    private DeviceInfoAdapter deviceInfoAdapter;
 
    private List<HouseIdBean> houseListBeanIDList;
    private List<CloudInverterDeviceBean> deviceInfoList;
    private int currentHouseListPage = 0; // 当前电站列表页码
    private int currentHouseListTotal = 0; // 电站列表总页码
    private boolean isHouseLoadingMore = false; // 标记电站列表正在加载更多数据
 
    private int currentDeviceListPage = 0; // 当前设备列表页码
    private int currentDeviceListTotal = 0; // 设备列表总页码
    private boolean isDeviceLoadingMore = false; // 标记设备列表正在加载更多数据
 
    private boolean isClickPowerStationLabel = true;//(电站标签=true,设备标签=false)
 
    private String key = SortValue.all;
    private String value = SortValue.all;//descending:降序,ascending:升序
    private String installedCapacityMinValue = "";//最小组串容量(装机容量)
    private String installedCapacityMaxValue = "";//最大组串容量(装机容量)
    private String gridTypeValue = "";//并网状态(全部 不传该过滤参数,FULL_GRID:并网,OFFLINE:离网)
    private String powerStationStatusValue = PowerStationStatus.All;//电站状态(全部 不传该过滤参数,1:正常(运行),2:离线,3:待接入,4:故障)
 
    private final long pageSize = 20;//页数
 
    /**
     * 还原条件的初始化状态
     */
    private void initializationState() {
        key = SortValue.all;
        value = SortValue.all;
        installedCapacityMinValue = "";
        installedCapacityMaxValue = "";
        gridTypeValue = "";
        powerStationStatusValue = PowerStationStatus.All;
    }
 
    @Override
    public Object getContentView() {
        viewBinding = FragmentHouseListBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        getStatusOverview();
        initData();
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
    }
 
    private void initEvent() {
 
        //电站标签
        viewBinding.powerStationLabel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isClickPowerStationLabel) {
                    return;
                }
                isClickPowerStationLabel = true;
                selectedTitleLabelStyle();
                initializationState();
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
 
            }
        });
        //设备标签
        viewBinding.deviceLabel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isClickPowerStationLabel) {
                    return;
                }
                isClickPowerStationLabel = false;
                selectedTitleLabelStyle();
                loadNextPageDeviceList(true, 1, true);
            }
        });
        //全部
        viewBinding.allLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                powerStationStatusValue = PowerStationStatus.All;
                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //故障
        viewBinding.faultsLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                powerStationStatusValue = PowerStationStatus.malfunction;
                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //离线
        viewBinding.offlineLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                powerStationStatusValue = PowerStationStatus.off;
                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //待接入
        viewBinding.connectedLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                powerStationStatusValue = PowerStationStatus.connecting;
                viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
                viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
 
        //电站添加
        viewBinding.addIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null);
 
            }
        });
        //电站搜索
        viewBinding.powerStationSearchClickCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(_mActivity, HouseSearchActivity.class);
                startActivity(intent);
            }
        });
        //默认选择参数图标
        viewBinding.powerStationDefaultConditionIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DefaultFilteringDialog defaultFilteringDialog = new DefaultFilteringDialog(_mActivity);
                defaultFilteringDialog.show();
                defaultFilteringDialog.initState(installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue);
                defaultFilteringDialog.setOnClickListener(new DefaultFilteringDialog.OnClickListener() {
                    @Override
                    public void confirm(String min, String max, String state) {
                        installedCapacityMinValue = min;//最小组串容量(装机容量)
                        installedCapacityMaxValue = max;//最大组串容量(装机容量)
                        gridTypeValue = state;//并网状态(全部 不传该过滤参数,FULL_GRID:并网,OFFLINE:离网)
                        loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
                    }
                });
            }
        });
 
        //电站设置下拉箭头颜色
        viewBinding.fragmentHouseSrl.setColorSchemeResources(R.color.text_FF245EC3);
        //电站下拉读取
        viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                viewBinding.fragmentHouseSrl.setRefreshing(false);
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
                getStatusOverview();
            }
        });
        //电站上拉读取
        viewBinding.fragmentHouseSrlListRc.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
//                super.onScrolled(recyclerView, dx, dy);
 
                LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                if (layoutManager == null) {
                    return;
                }
                int visibleItemCount = layoutManager.getChildCount();
                int totalItemCount = layoutManager.getItemCount();
                int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
                if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) {
                    if (!isHouseLoadingMore) {
                        // 滑动到了底部,执行相应的操作
                        HdlLogLogic.print("---滑动到了底部");
                        loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, ++currentHouseListPage, false);
                    }
                }
            }
        });
        //电站详情进入,删除电站,移动电站位置
        houseInfoAdapter.setNoOnclickListener(new HouseInfoAdapter.OnclickListener() {
            @Override
            public void onClick(int position, HouseIdBean houseIdBean) {
                //点击住宅详情
                HdlLogLogic.print("点击住宅详情---" + new Gson().toJson(houseIdBean), false);
                HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
                String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName() + "&powerStationStatus=" + houseIdBean.getPowerStationStatus();
                HdlUniLogic.getInstance().openUniMP(path, null);
 
            }
 
            @Override
            public void onMoveClick(int position, HouseIdBean houseIdBean) {
                if (position == 0) {
                    HdlThreadLogic.toast(_mActivity, getString(R.string.already_the_first_one));
                    return;
                }
                String frontHomeId = "";
                if (position > 1) {
                    frontHomeId = houseListBeanIDList.get(position - 2).getHomeId();
                }
                HdlResidenceLogic.getInstance().moveResidence(houseIdBean.getHomeId(), frontHomeId, new CloudCallBeak<Boolean>() {
                    @Override
                    public void onSuccess(Boolean obj) {
                        //移动电站位置
                        HdlResidenceLogic.getInstance().moveHouseId(houseIdBean.getHomeId());
                        initData();//初始化缓存数据
                        houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);//重新刷新列表
                        nullDataUpdateUi();//检测数据是否为空
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HdlThreadLogic.toast(_mActivity, e);
                    }
                });
 
 
            }
 
            @Override
            public void onDelClick(int position, HouseIdBean houseIdBean) {
 
                DelayedConfirmationCancelDialog delayedConfirmationCancelDialog = new DelayedConfirmationCancelDialog(_mActivity);
                delayedConfirmationCancelDialog.show();
                delayedConfirmationCancelDialog.isHideTitle(true);
                String homeName = "\"" + houseIdBean.getHomeName() + "\"";
                delayedConfirmationCancelDialog.setContent(getString(R.string.delete_power_station).replace("%s", homeName));
 
                delayedConfirmationCancelDialog.startCountdown(4);
                delayedConfirmationCancelDialog.setYesOnclickListener(new DelayedConfirmationCancelDialog.onYesOnclickListener() {
                    @Override
                    public void Confirm() {
                        delayedConfirmationCancelDialog.dismiss();
                        showLoading(getString(R.string.deleting_please_wait));
                        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(houseIdBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                            @Override
                            public void onSuccess(List<GatewayBean> list) {
                                //发起删除电站指令
                                deleteResidence(houseIdBean.getHomeId(), list);
 
                            }
 
                            @Override
                            public void onFailure(HDLException e) {
                                //发起删除电站指令
                                deleteResidence(houseIdBean.getHomeId(), null);
                            }
                        });
 
//                        //删除住宅
//                        HdlResidenceLogic.getInstance().delResidence(houseIdBean.getHomeId(), new CloudCallBeak<Boolean>() {
//                            @Override
//                            public void onSuccess(Boolean obj) {
//                                HdlResidenceLogic.getInstance().delHouseId(houseIdBean.getHomeId());
//                                initData();//初始化缓存数据
//                                houseInfoAdapter.setList(houseListBeanIDList);//重新刷新列表
//                                nullDataUpdateUi(houseListBeanIDList);//检测数据是否为空
//                            }
//
//                            @Override
//                            public void onFailure(HDLException e) {
//                                HdlThreadLogic.toast(_mActivity, e);
//                            }
//                        });
                    }
                });
                delayedConfirmationCancelDialog.setNoOnclickListener(new DelayedConfirmationCancelDialog.onNoOnclickListener() {
                    @Override
                    public void Cancel() {
                        delayedConfirmationCancelDialog.dismiss();
                    }
                });
 
            }
        });
        //电站编辑按钮
        viewBinding.editIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(HouseListEditActivity.class);
            }
        });
        //电站名称筛选
        viewBinding.stationNameRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSelected = !v.isSelected();
                viewBinding.stationNameRl.setSelected(isSelected);
                viewBinding.stationNameIv.setSelected(isSelected);
                key = SortType.homeNameSort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //电站发电功率筛选
        viewBinding.stationPowerRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSelected = !v.isSelected();
                viewBinding.stationPowerRl.setSelected(isSelected);
                viewBinding.stationPowerIv.setSelected(isSelected);
                key = SortType.powerSort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //电站当日发电量筛选
        viewBinding.stationDayRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSelected = !v.isSelected();
                viewBinding.stationDayRl.setSelected(isSelected);
                viewBinding.stationDayIv.setSelected(isSelected);
                key = SortType.todayElectricitySort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //电站当月发电量筛选
        viewBinding.stationMonthRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSelected = !v.isSelected();
                viewBinding.stationMonthRl.setSelected(isSelected);
                viewBinding.stationMonthIv.setSelected(isSelected);
                key = SortType.monthElectricitySort;
                value = isSelected ? SortValue.ascending : SortValue.descending;
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        });
        //设备点击
        deviceInfoAdapter.setOnclickListener(new DeviceInfoAdapter.OnClickListener() {
            @Override
            public void onClick(int position, CloudInverterDeviceBean deviceBean) {
//                GatewayBean gatewayBean = new GatewayBean();
//                gatewayBean.setCategorySecondName(deviceBean.getCategorySecondName());
//                gatewayBean.setDevice_mac(deviceBean.getOsn());
//                gatewayBean.setDevice_model(deviceBean.getOmodel());
//                gatewayBean.setOid(deviceBean.getOid());
//                gatewayBean.setGatewayId(deviceBean.getGatewayId());
//                gatewayBean.setAddresses(deviceBean.getAddresses());
//                gatewayBean.setSid(deviceBean.getSid());
//                gatewayBean.setDeviceId(deviceBean.getDeviceId());
//                gatewayBean.setDevice_name(deviceBean.getName());
//                gatewayBean.setDeviceStatus(deviceBean.getDeviceStatus());
//                gatewayBean.setHomeId(deviceBean.getHomeId());
//                gatewayBean.setSpk(deviceBean.getSpk());
//                gatewayBean.setDeviceType(deviceBean.getDeviceType());
                if (deviceBean.getDeviceStatus() == 4) {
                    HdlThreadLogic.toast(_mActivity, R.string.device_off);
                    return;
                }
                //配置本地通信的信息
                HDLLinkConfig.getInstance().setHomeId(deviceBean.getHomeId());
                HDLLinkConfig.getInstance().setLocalSecret(deviceBean.getLocalSecret());
                List<CloudInverterDeviceBean> newList = new ArrayList<>();
                newList.add(deviceBean);
                //目的是为了获取拿到网关ID,mqtt通讯秘钥等信息,拿到后缓存到本地逆变器列表里面,发送数据数据时自动去缓存列表里面去查找;
                HdlDeviceLogic.getInstance().setDeviceRemoteInfo(newList, deviceBean.getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                    @Override
                    public void onSuccess(List<GatewayBean> obj) {
                        GatewayBean newGatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceBean.getOsn());
                        String jsonEncryption = URLEncodingUtils.encodeURIComponent(new Gson().toJson(newGatewayBean));
                        String path = HDLUniMP.UNI_EVENT_OPEN_DEVICE_DETAILS + "?inverterInfo=" + jsonEncryption;
                        HdlUniLogic.getInstance().openUniMP(path, null);
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
 
                    }
                });
            }
        });
        //设备设置下拉箭头颜色
        viewBinding.fragmentDeviceSrl.setColorSchemeResources(R.color.text_FF245EC3);
        //设备下拉读取
        viewBinding.fragmentDeviceSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                viewBinding.fragmentDeviceSrl.setRefreshing(false);
                loadNextPageDeviceList(false, 1, true);
            }
        });
        //设备上拉读取
        viewBinding.fragmentDeviceSrlListRc.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
//                super.onScrolled(recyclerView, dx, dy);
 
                LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                if (layoutManager == null) {
                    return;
                }
                int visibleItemCount = layoutManager.getChildCount();
                int totalItemCount = layoutManager.getItemCount();
                int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
                if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) {
                    if (!isDeviceLoadingMore) {
                        // 滑动到了底部,执行相应的操作
                        HdlLogLogic.print("---滑动到了底部");
                        loadNextPageDeviceList(false, ++currentDeviceListPage, false);
                    }
                }
            }
        });
        //设备搜索
        viewBinding.deviceSearchCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(_mActivity, DeviceSearchActivity.class);
                startActivity(intent);
            }
        });
 
    }
 
    private void initView() {
        viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);
        viewBinding.deviceLabelParent.setVisibility(View.GONE);
        viewBinding.allLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_yes_ffffff));
        viewBinding.faultsLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
        viewBinding.offlineLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
        viewBinding.connectedLl.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.station_status_no_ffffff));
        //电站标签
        houseInfoAdapter = new HouseInfoAdapter(_mActivity);
        viewBinding.fragmentHouseSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
        viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter);
        houseInfoAdapter.setList(this.houseListBeanIDList, powerStationStatusValue);
 
        //设备标签
        deviceInfoAdapter = new DeviceInfoAdapter(_mActivity);
        viewBinding.fragmentDeviceSrlListRc.setLayoutManager(new LinearLayoutManager(_mActivity));
        viewBinding.fragmentDeviceSrlListRc.setAdapter(deviceInfoAdapter);
        this.nullDataUpdateUi();
 
    }
 
    /**
     * 电站和设备标签样式
     */
    private void selectedTitleLabelStyle() {
        if (isClickPowerStationLabel) {
            viewBinding.powerStationLabel.setTextAppearance(R.style.Text18Style);
            viewBinding.deviceLabel.setTextAppearance(R.style.Text14Style);
//            viewBinding.editIv.setVisibility(View.VISIBLE);//编辑图标隐藏
            viewBinding.addIv.setVisibility(View.VISIBLE);//添加图标隐藏
            viewBinding.powerStationLabelParent.setVisibility(View.VISIBLE);//电站标签【父容器】显示
            viewBinding.deviceLabelParent.setVisibility(View.GONE);//设备标签【父容器】隐藏
            if (viewBinding.deviceNullDataIc.getRoot().getVisibility() == View.VISIBLE) {
                viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE);
            }
        } else {
            viewBinding.deviceLabel.setTextAppearance(R.style.Text18Style);
            viewBinding.powerStationLabel.setTextAppearance(R.style.Text14Style);
//            viewBinding.editIv.setVisibility(View.GONE);//编辑图标隐藏
            viewBinding.addIv.setVisibility(View.GONE);//添加图标隐藏
            viewBinding.powerStationLabelParent.setVisibility(View.GONE);//电站标签【父容器】隐藏
            viewBinding.deviceLabelParent.setVisibility(View.VISIBLE);//设备标签【父容器】显示
            if (viewBinding.homeNullDataIc.getRoot().getVisibility() == View.VISIBLE) {
                viewBinding.homeNullDataIc.getRoot().setVisibility(View.GONE);
            }
        }
 
    }
 
 
    private void initData() {
        if (isClickPowerStationLabel) {
            this.houseListBeanIDList = new ArrayList<>();
            this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList());
        } else {
            this.deviceInfoList = new ArrayList<>();
            this.deviceInfoList.addAll(HdlDeviceLogic.getInstance().getDeviceList());
        }
 
 
    }
 
    /**
     * 收到EventBUs通知
     *
     * @param eventBus 数据
     */
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEventMessage(BaseEventBus eventBus) {
        super.onEventMessage(eventBus);
        if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(eventBus.getTopic())) {
            if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) {
                // 取消粘性事件
                EventBus.getDefault().removeStickyEvent(eventBus);
                //uin创建电站成功后通知
                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
                if (eventBus.getData() != null) {
                    Gson gson = new Gson();
                    String json = eventBus.getData().toString();
                    HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class);
                    HdlResidenceLogic.getInstance().switchHouse(houseIdBean, true);
 
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT.equals(eventBus.getType())) {
                // 取消粘性事件
                EventBus.getDefault().removeStickyEvent(eventBus);
                //todo 现在默认刷新全部
                //uin编辑住宅通知
//                String homeId = HdlUniLogic.getInstance().getKeyValue("homeId", eventBus.getData());
//                String home_name = HdlUniLogic.getInstance().getKeyValue("powerStationName", eventBus.getData());
//                if (TextUtils.isEmpty(homeId) || TextUtils.isEmpty(home_name)) {
//                    return;
//                }
//                int index = -1;
//                for (int i = 0; i < houseListBeanIDList.size(); i++) {
//                    HouseIdBean houseIdBean = houseListBeanIDList.get(i);
//                    if (houseIdBean.getHomeId().equals(homeId)) {
//                        index = i;
//                        houseIdBean.setHomeName(home_name);
//                        break;
//                    }
//                }
//                if (index > -1) {
//                    if (houseInfoAdapter != null) {
//                        //更新单个数据
//                        houseInfoAdapter.notifyItemChanged(index);
//                    }
//                }
 
            }
        } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getTopic())) {
            // 取消粘性事件
            EventBus.getDefault().removeStickyEvent(eventBus);
            //是在(电站)模块且在(电站)标签页才进来这里
            if (HdlCommonLogic.lowerTagType == LowerTagType.power_station && isClickPowerStationLabel) {
//                //uin关闭住宅详情界面通知
//                if (MqttRecvClient.getInstance() != null) {
//                    MqttRecvClient.getInstance().removeAllTopic();
//                }
                loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            }
        } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) {
            // 取消粘性事件
            EventBus.getDefault().removeStickyEvent(eventBus);
//            if (!isClickPowerStationLabel) {
//                return;
//            }
            //先清空订阅主题
            if (MqttRecvClient.getInstance() != null) {
                MqttRecvClient.getInstance().removeAllTopic();
            }
            String homeId = eventBus.getData().toString();
            //进去住宅详情uni读取逆变器列表成功后通知
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
                //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值;
                String topic = "/user/" + gatewayId + "/#";
                //进去住宅详情开始订阅主题
                MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topic);//订阅【逆变器】消息
            }
            String topicHome = "/user/" + homeId + "/#";
            MqttRecvClient.getInstance().checkAndsubscribeAllTopics(topicHome);//订阅【电站】消息
 
 
        } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) {
            // 取消粘性事件
            EventBus.getDefault().removeStickyEvent(eventBus);
            //接收外部点击事件
            if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) {
                HdlLogLogic.print("正在点击【电站】");
//                if (!isReadData) {
//                    //1,从首页-故障-进来-电站(不读取)
//                    //2,从电站-进来-电站(读取一次,后面进来不在读取)
//                    loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
//                    getStatusOverview();
//                }
                //2024年06月24日14:34:01 产品经理要求进去电站列表都要读取 且默认进去都是默认电站标签
                isClickPowerStationLabel = true;
                selectedTitleLabelStyle();
                initializationState();
                getStatusOverview();
                loadNextPageHouseList(true, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
            } else if (eventBus.getType().equals(ConstantManage.station_page)) {
                //通过首页电站进来的
                if (eventBus.getData().equals(PowerStationStatus.All)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.allLl.performClick();
                } else if (eventBus.getData().equals(PowerStationStatus.malfunction)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.faultsLl.performClick();
                } else if (eventBus.getData().equals(PowerStationStatus.off)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.offlineLl.performClick();
                } else if (eventBus.getData().equals(PowerStationStatus.connecting)) {
                    isClickPowerStationLabel = true;
                    selectedTitleLabelStyle();
                    viewBinding.connectedLl.performClick();
                }
            } else if (eventBus.getType().equals(ConstantManage.station_edit)) {
                //编辑后更新一下住宅列表
                //loadNextPageHouseList(false, key, value, installedCapacityMinValue, installedCapacityMaxValue, gridTypeValue, powerStationStatusValue, 1, true);
//                getStatusOverview();
                if (houseInfoAdapter != null) {
                    initData();
                    //更新UI
                    houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);
                }
            }
        }
    }
 
 
    /**
     * 电站状态概览
     */
    private void getStatusOverview() {
        HdlResidenceLogic.getInstance().getStatusOverview(new CloudCallBeak<StatusOverviewBean>() {
            @Override
            public void onSuccess(StatusOverviewBean statusOverviewBean) {
                if (statusOverviewBean == null) {
                    return;
                }
                viewBinding.allTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getTotal()));
                viewBinding.faultsTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getFault()));
                viewBinding.offlineTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getOffline()));
                viewBinding.connectedTotalTv.setText(HdlCommonLogic.convertString(statusOverviewBean.getConnecting()));
            }
 
            @Override
            public void onFailure(HDLException e) {
 
            }
        });
    }
 
 
    /**
     * 刷新UI(电站)
     *
     * @param isRefreshing         表示是下拉刷新的
     * @param key                  发电功率排序(powerSort);
     *                             今日发电量排序(todayElectricitySort);
     *                             创建时间排序(createTimeSort);
     * @param keyValue             (descending:降序
     *                             ascending:升序),
     * @param installedCapacityMin 最小组串容量(装机容量)
     * @param installedCapacityMax 最大组串容量(装机容量)
     * @param gridType             并网状态 (全部 :"";FULL_GRID : 并网;OFFLINE :离网)
     * @param powerStationStatus   电站状态 (全部  :"";1 : 正常;2 : 离线; 3 : 待接入;4 : 故障)
     * @param pageNo               页码
     * @param isClear              是否清除数据
     */
    private void loadNextPageHouseList(boolean isRefreshing, String key, String keyValue, String installedCapacityMin, String installedCapacityMax, String gridType, String powerStationStatus, long pageNo, boolean isClear) {
        isReadData = true;
        if (isClear) {
            clearData();
        }
        //第一页读取数据强制读取
        if (pageNo > 1 && currentHouseListPage > currentHouseListTotal) {
            --currentHouseListPage;
            //当前页不能大于总页数
            return;
        }
        isHouseLoadingMore = true;//标记读取状态
        if (isRefreshing) {
            showLoading(getString(R.string.device_loading));
        }
 
        //获取住宅(电站)ID列表
        HdlResidenceLogic.getInstance().getResidenceIdList(key, keyValue, installedCapacityMin, installedCapacityMax, gridType, powerStationStatus, pageNo, pageSize, new CloudCallBeak<HdlResidenceLogic.HouseBeanClass>() {
            @Override
            public void onSuccess(HdlResidenceLogic.HouseBeanClass houseBeanClass) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (isRefreshing) {
                            hideLoading();
                        }
                        isHouseLoadingMore = false;
                        if (houseBeanClass != null) {
                            currentHouseListTotal = (int) houseBeanClass.getTotalPage();
                            currentHouseListPage = (int) houseBeanClass.getPageNo();
                            //更新缓存
                            HdlResidenceLogic.getInstance().setHouseIdList(houseBeanClass.getList());
                            if (houseInfoAdapter != null) {
                                initData();
                                //更新UI
                                houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);
                            }
                        }
                        nullDataUpdateUi();
                    }
                }, _mActivity, ShowErrorMode.YES);
 
            }
 
            @Override
            public void onFailure(HDLException e) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (currentHouseListPage > 1) {
                            --currentHouseListPage;
                        }
                        isHouseLoadingMore = false;
                        if (isRefreshing) {
                            hideLoading();
                        }
 
                    }
                }, _mActivity, ShowErrorMode.YES);
            }
        });
    }
 
    /**
     * 刷新UI(设备)
     *
     * @param isRefreshing 表示是下拉刷新的
     * @param pageNo       页码
     * @param isClear      true表示清空缓存
     */
    private void loadNextPageDeviceList(boolean isRefreshing, long pageNo, boolean isClear) {
        if (isClear) {
            clearData();
        }
        //第一页读取数据强制读取
        if (pageNo > 1 && currentDeviceListPage > currentDeviceListTotal) {
            --currentDeviceListPage;
            //当前页不能大于总页数
            return;
        }
        isDeviceLoadingMore = true;//标记读取状态
        if (isRefreshing) {
            showLoading(getString(R.string.device_loading));
        }
        //获取住宅(电站)ID列表
        HdlDeviceLogic.getInstance().getPowerStationDeviceList("", pageNo, pageSize, new CloudCallBeak<PageNumberObject<CloudInverterDeviceBean>>() {
            @Override
            public void onSuccess(PageNumberObject<CloudInverterDeviceBean> pageNumberObject) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (isRefreshing) {
                            hideLoading();
                        }
                        isDeviceLoadingMore = false;
                        if (pageNumberObject != null) {
                            currentDeviceListTotal = (int) pageNumberObject.getTotalPage();
                            currentDeviceListPage = (int) pageNumberObject.getPageNo();
                            //更新缓存
                            HdlDeviceLogic.getInstance().setListDevice(pageNumberObject.getList());
                            //更新缓存
                            if (deviceInfoAdapter != null) {
                                initData();
                                //更新UI
                                deviceInfoAdapter.setList(deviceInfoList);
                            }
                        }
                        nullDataUpdateUi();
                    }
                }, _mActivity, ShowErrorMode.YES);
 
            }
 
            @Override
            public void onFailure(HDLException e) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (currentDeviceListPage > 1) {
                            --currentDeviceListPage;
                        }
                        isDeviceLoadingMore = false;
                        if (isRefreshing) {
                            hideLoading();
                        }
                    }
                }, _mActivity, ShowErrorMode.YES);
            }
        });
    }
 
 
    /**
     * 清空缓存数据
     */
    private void clearData() {
        if (isClickPowerStationLabel) {
            currentHouseListPage = 0;// 重置当前电站列表页码
            currentHouseListTotal = 0;// 重置当前电站列表总页码
            if (houseListBeanIDList != null) {
                houseListBeanIDList.clear(); //清空临时缓存列表
            }
            HdlResidenceLogic.getInstance().clearHouseList(); //表示强制清空所有缓存信息
        } else {
            currentDeviceListPage = 0; // 重置当前设备列表页码
            currentDeviceListTotal = 0; // 重置设备列表总页码
            if (deviceInfoList != null) {
                deviceInfoList.clear();//清空临时缓存列表
            }
            HdlDeviceLogic.getInstance().clearDeviceList(); //表示强制清空所有缓存信息
        }
    }
 
 
    /**
     * 没有电站列表的样式
     */
    private void nullDataUpdateUi() {
        boolean is_data;
        String tipText = "";
        if (isClickPowerStationLabel) {
            is_data = houseListBeanIDList != null && houseListBeanIDList.size() > 0;
            tipText = getString(R.string.my_power_station_data_null);
            HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.homeNullDataIc.getRoot(), viewBinding.homeNullDataIc.nullDataGifAnimationIv, viewBinding.homeNullDataIc.nullDataTv, tipText, is_data);
 
        } else {
            is_data = deviceInfoList != null && deviceInfoList.size() > 0;
            tipText = getString(R.string.no_equipment);
 
            HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.deviceNullDataIc.getRoot(), viewBinding.deviceNullDataIc.nullDataGifAnimationIv, viewBinding.deviceNullDataIc.nullDataTv, tipText, is_data);
 
        }
    }
 
    /**
     * 删除电站,逆变器
     * (开始删除电站,同时,向逆变器发送初始化逆变器指令,无须处理结果)
     *
     * @param list 设备列表
     */
    private void initializeInverter(List<GatewayBean> list) {
        if (list == null || list.size() == 0) {
            return;
        }
        for (int i = 0; i < list.size(); i++) {
            GatewayBean gatewayBean = list.get(i);
            HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() {
                @Override
                public void onSuccess(Boolean obj) {
//                                HdlLogLogic.print("初始化逆变器成功-->mac:" + cloudInverterDeviceBean.getOsn(),true);
                }
 
                @Override
                public void onError(HDLLinkException e) {
//                                HdlLogLogic.print("初始化逆变器失败-->mac:" + cloudInverterDeviceBean.getOsn(),true);
                }
            });
        }
    }
 
    /**
     * 删除电站
     *
     * @param homeId 电站id
     * @param list   逆变器列表
     */
    private void deleteResidence(String homeId, List<GatewayBean> list) {
 
        //删除住宅
        HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                hideLoading();
                initializeInverter(list); //发起初始化指令给逆变器;(注意:只能是本地发送了(要搜索局域网逆变器列表,建立本地通讯通道),删除电站成功后,云端解绑逆变器的关系)
                HdlResidenceLogic.getInstance().delHouseId(homeId);//删除电站缓存
                initData();//初始化缓存数据
                houseInfoAdapter.setList(houseListBeanIDList, powerStationStatusValue);//重新刷新列表
                getStatusOverview();//删除成功后刷新电站状态概览
                nullDataUpdateUi();//检测数据是否为空
            }
 
            @Override
            public void onFailure(HDLException e) {
                hideLoading();
                HdlThreadLogic.toast(_mActivity, e);
            }
        });
    }
 
 
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == PermissionUtils.STATUS_SUCCESS) {
            for (int i = 0; i < permissions.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    if (mPermissionsResultCallback != null) {
                        mPermissionsResultCallback.succeed();
                    }
                } else {
                    if (mPermissionsResultCallback != null) {
                        mPermissionsResultCallback.failing();
                    }
                }
 
            }
        }
 
    }
 
 
    private PermissionsResultCallback mPermissionsResultCallback;
 
    public interface PermissionsResultCallback {
 
        void succeed();
 
        void failing();
 
    }
 
 
}