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
package cn.flightfeather.thirdapp.dataanalysis;
 
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
 
import com.github.mikephil.charting.charts.PieChart;
import com.ping.greendao.gen.DomainitemDao;
 
import org.greenrobot.greendao.query.QueryBuilder;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.flightfeather.thirdapp.CommonApplication;
import cn.flightfeather.thirdapp.R;
import cn.flightfeather.thirdapp.adapter.AllRecyclerViewAdapter;
import cn.flightfeather.thirdapp.bean.entity.Domainitem;
import cn.flightfeather.thirdapp.bean.vo.RankVo;
import cn.flightfeather.thirdapp.bean.vo.StatisticsVo;
import cn.flightfeather.thirdapp.bean.vo.TaskFrequencyVo;
import cn.flightfeather.thirdapp.bean.vo.TaskVo;
import cn.flightfeather.thirdapp.dataanalysis.rank.AnalysisRankActivity;
import cn.flightfeather.thirdapp.httpservice.ProblemListService;
import cn.flightfeather.thirdapp.httpservice.TaskService;
import cn.flightfeather.thirdapp.util.ChartGenerator;
import cn.flightfeather.thirdapp.util.CommonUtils;
import cn.flightfeather.thirdapp.util.DateFormatter;
import cn.flightfeather.thirdapp.util.DialogUtil;
import cn.flightfeather.thirdapp.util.Domain;
import cn.flightfeather.thirdapp.util.PopupGenerator;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
 
/**
 * 2018.12.25 created by riku
 * 分析总览界面
 *  综合简略展示各统计概况:
 *  任务进度、街镇排名、场景排名、问题类型分布
 */
public class AnalysisOverViewFragment extends Fragment {
 
    //<editor-fold desc="全局变量">
    private final String TITLE = "总览";
 
    private CommonApplication app;
    private Retrofit retrofit;
 
    private Unbinder unbinder;
 
    private String curSceneTypeId = "1";//当前场景类型
    private String curSceneTypeName = "工地";//当前场景类型
    private RankVo rankVo = new RankVo();
    private int maxShowItems = 3;
    private Dialog dialog;
 
    private ViewGroup container;
    //</editor-fold>
 
    //<editor-fold desc="构造函数">
    public AnalysisOverViewFragment() {
        // Required empty public constructor
    }
 
 
    public static AnalysisOverViewFragment newInstance() {
        AnalysisOverViewFragment fragment = new AnalysisOverViewFragment();
        return fragment;
    }
    //</editor-fold>
 
    //<editor-fold desc="生命周期">
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        this.container = container;
         View view = inflater.inflate(R.layout.fragment_analysis_over_view, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }
 
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        app = (CommonApplication) getActivity().getApplication();
        retrofit = app.getRetrofit();
        initPopup();
        initToolBar();
        initBlock1();
        initBlock2();
        initBlock3();
        initBlock4();
        initPannel();
    }
 
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
 
    }
 
    @Override
    public void onDetach() {
        super.onDetach();
    }
 
    /**
     * Called when the fragment is no longer in use.  This is called
     * after {@link #onStop()} and before {@link #onDetach()}.
     */
    @Override
    public void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
    //</editor-fold>
 
    //<editor-fold desc="标题栏">
    @BindView(R.id.action_bar) View action_bar;
    private void initToolBar() {
        action_bar.findViewById(R.id.spinner_topclass_task).setVisibility(View.GONE);
        action_bar.findViewById(R.id.img_left).setVisibility(View.GONE);
        action_bar.findViewById(R.id.img_right).setVisibility(View.INVISIBLE);
        action_bar.findViewById(R.id.ll_menu_text).setVisibility(View.VISIBLE);
        TextView title = action_bar.findViewById(R.id.actionbar_title);
        title.setText(TITLE);
//        title.setGravity(Gravity.CENTER_HORIZONTAL);
//        ViewGroup.LayoutParams layoutParams = title.getLayoutParams();
//        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    }
    //</editor-fold>
 
    //<editor-fold desc="顶部顶层任务选择区">
    List<TaskVo> allTaskVoList = new ArrayList<>();
    List<TaskVo> showingTasks = new ArrayList<>();
    int offset;
 
    private void initPannel() {
        showDialog();
        //顶层任务
        Call<ArrayList<TaskVo>> getTopClassTaskList = retrofit.create(TaskService.class).getTopClassTaskList(0);
        getTopClassTaskList.enqueue(new Callback<ArrayList<TaskVo>>() {
            @Override
            public void onResponse(Call<ArrayList<TaskVo>> call, Response<ArrayList<TaskVo>> response) {
                showingTasks.clear();
                allTaskVoList.clear();
                if (response.body() != null) {
                    allTaskVoList.addAll(response.body());//返回结果默认按时间降序排序
                    for (TaskVo t : allTaskVoList) {
                        if (t.getDistrictcode().equals(app.getCurrentUser().getDguid())) {//主管部门的部门id就是区县id
                            showingTasks.add(t);
                        }
                    }
                }
                refreshPannel();
            }
 
            @Override
            public void onFailure(Call<ArrayList<TaskVo>> call, Throwable t) {
                refreshPannel();
            }
        });
    }
 
    @BindView(R.id.tab_time_pannel) View tab_time_pannel;
    TextView text;
    private void refreshPannel() {
        showDialog();
        text = tab_time_pannel.findViewById(R.id.text_time);
        if (!showingTasks.isEmpty()) {
            Date date = showingTasks.get(offset).getStarttime();
            String s = DateFormatter.YearMonthFormat_CN.format(date);
            text.setText(s);
            refresh();
        }
    }
    //</editor-fold>
 
    //<editor-fold desc="任务进度">
    @BindView(R.id.rv_task_progress) RecyclerView rv_task_progress;
    AllRecyclerViewAdapter<TaskFrequencyVo.FrequencyInfo> freAdapter;
    List<TaskFrequencyVo.FrequencyInfo> frequencyInfos = new ArrayList<>();
 
    private void initBlock1() {
        freAdapter = new AllRecyclerViewAdapter<TaskFrequencyVo.FrequencyInfo>(frequencyInfos, R.layout.item_common_news, getActivity()) {
            @Override
            public void bindView(AllRecyclerViewAdapter.MyViewHolder holder, TaskFrequencyVo.FrequencyInfo obj, boolean isSelected, int position) {
                StringBuilder totalFrequency =  new StringBuilder("总监管频次: " + obj.getTotalFrequency() + "次");
                StringBuilder clearFrequency = new StringBuilder("已监管频次: " + obj.getClearFrequency() + "次");
                int tmpLeft = obj.getTotalFrequency() - obj.getClearFrequency();
                StringBuilder leftFrequency = new StringBuilder("剩余监管频次: " + (tmpLeft >= 0 ? tmpLeft : 0) + "次");
                holder.setText(R.id.text_head, obj.getSceneTypeName())
                        .setText(R.id.text_1_1, totalFrequency)
                        .setText(R.id.text_2_1, clearFrequency)
                        .setText(R.id.text_3_1, leftFrequency)
                        .setVisibility(R.id.text_1_2, View.GONE)
                        .setVisibility(R.id.text_2_2, View.GONE)
                        .setVisibility(R.id.text_3_2, View.GONE)
                        .setImageResource(R.id.image_head, CommonUtils.getIconBySceneType(obj.getSceneTypeId()));
            }
        };
 
        LinearLayoutManager lm = new LinearLayoutManager(getActivity());
        lm.setOrientation(LinearLayoutManager.VERTICAL);
        rv_task_progress.setLayoutManager(lm);
        rv_task_progress.setAdapter(freAdapter);
    }
 
    private void refreshBlock1() {
        String id = getTopTaskId();
        Call<TaskFrequencyVo> getFrequency = retrofit.create(TaskService.class).getFrequency(id);
        getFrequency.enqueue(new Callback<TaskFrequencyVo>() {
            @Override
            public void onResponse(Call<TaskFrequencyVo> call, Response<TaskFrequencyVo> response) {
                if (response.body() != null) {
                    TaskFrequencyVo frequencyVo = response.body();
                    frequencyInfos.clear();
                    frequencyInfos.addAll(frequencyVo.getFrequencyInfos());
                    freAdapter.notifyDataSetChanged();
                } else {
                    loadingOver(false);
                }
            }
 
            @Override
            public void onFailure(Call<TaskFrequencyVo> call, Throwable t) {
                loadingOver(false);
            }
        });
 
    }
 
    //</editor-fold>
 
    //<editor-fold desc="街镇排名">
    @BindView(R.id.rv_rank_town) RecyclerView rv_rank_town;
    AllRecyclerViewAdapter<RankVo.TownRank> townRankAdapter;
    List<RankVo.TownRank> townRanks = new ArrayList<>();
    List<RankVo.TownRank> allTownRanks = new ArrayList<>();
 
    private void initBlock2() {
        townRankAdapter = new AllRecyclerViewAdapter<RankVo.TownRank>(townRanks, R.layout.item_problem_count, getActivity()) {
            @Override
            public void bindView(AllRecyclerViewAdapter.MyViewHolder holder, RankVo.TownRank obj, boolean isSelected, int position) {
 
                if (position < 3) {
                    int rank = obj.getRankNo();
                    holder.setText(R.id.text_name, obj.getTownName())
                            .setText(R.id.text_firstCount, getScore(obj.getAverageScore()))
                            .setVisibility(R.id.text_secondCount, View.GONE)
                            .setVisibility(R.id.image_rank, View.GONE)
                            .setText(R.id.text_no, String.valueOf(rank));
                    switch (rank) {
                        case 1:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_4);
                            break;
                        case 2:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_3);
                            break;
                        case 3:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_2);
                            break;
                        default:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_1);
                            break;
                    }
                }
            }
        };
        LinearLayoutManager lm = new LinearLayoutManager(getActivity());
        lm.setOrientation(LinearLayoutManager.VERTICAL);
        rv_rank_town.setLayoutManager(lm);
        rv_rank_town.setAdapter(townRankAdapter);
    }
 
    private void refreshBlock2and3() {
        String id = getTopTaskId();
        Call<RankVo> getRank = retrofit.create(TaskService.class).getRank(id, curSceneTypeId, null);
        getRank.enqueue(new Callback<RankVo>() {
            @Override
            public void onResponse(Call<RankVo> call, Response<RankVo> response) {
                if (response.body() != null) {
                    rankVo = response.body();
                    rankS(rankVo.getSceneRanks());
                    rankT(rankVo.getTownRanks());
                    townRanks.clear();
                    allTownRanks.clear();
                    allTownRanks.addAll(rankVo.getTownRanks());
                    int tmpMax = maxShowItems <= allTownRanks.size() ? maxShowItems : allTownRanks.size();
                    for (int i = 0; i < tmpMax; i++) {
                        townRanks.add(allTownRanks.get(i));
                    }
                    townRankAdapter.notifyDataSetChanged();
 
                    sceneRanks.clear();
                    allSceneRanks.clear();
                    allSceneRanks.addAll(rankVo.getSceneRanks());
                    int tmpMax1 = maxShowItems <= allSceneRanks.size() ? maxShowItems : allSceneRanks.size();
                    for (int i = 0; i < tmpMax1; i++) {
                        sceneRanks.add(allSceneRanks.get(i));
                    }
                    sceneRankAdapter.notifyDataSetChanged();
                } else {
                    loadingOver(false);
                }
            }
 
            @Override
            public void onFailure(Call<RankVo> call, Throwable t) {
                loadingOver(false);
            }
        });
    }
    //</editor-fold>
 
    //<editor-fold desc="场景排名">
    @BindView(R.id.rv_rank_scene) RecyclerView rv_rank_scene;
    AllRecyclerViewAdapter<RankVo.SceneRank> sceneRankAdapter;
    List<RankVo.SceneRank> sceneRanks = new ArrayList<>();
    List<RankVo.SceneRank> allSceneRanks = new ArrayList<>();
 
    private void initBlock3() {
        sceneRankAdapter = new AllRecyclerViewAdapter<RankVo.SceneRank>(sceneRanks, R.layout.item_problem_count, getActivity()) {
            @Override
            public void bindView(AllRecyclerViewAdapter.MyViewHolder holder, RankVo.SceneRank obj, boolean isSelected, int position) {
                if (position < 3) {
                    int rank = obj.getRankNo();
                    holder.setText(R.id.text_name, obj.getSceneName())
                            .setText(R.id.text_firstCount, getScore(obj.getScore()))
                            .setVisibility(R.id.text_secondCount, View.GONE)
                            .setVisibility(R.id.image_rank, View.GONE)
                            .setText(R.id.text_no, String.valueOf(rank));
                    switch (rank) {
                        case 1:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_4);
                            break;
                        case 2:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_3);
                            break;
                        case 3:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_2);
                            break;
                        default:
                            holder.setImageResource(R.id.image_no, R.drawable.icon_rank_1);
                            break;
                    }
                }
            }
        };
        LinearLayoutManager lm = new LinearLayoutManager(getActivity());
        lm.setOrientation(LinearLayoutManager.VERTICAL);
        rv_rank_scene.setLayoutManager(lm);
        rv_rank_scene.setAdapter(sceneRankAdapter);
    }
    //</editor-fold>
 
    //<editor-fold desc="问题分析">
    @BindView(R.id.pie_chart_problem) PieChart pieChart;
    @BindView(R.id.ll_no_data) LinearLayout ll_no_data;
    HashMap<String, Float> datas = new HashMap<>();
 
    private void initBlock4() {
        ChartGenerator.quickSetupChart(pieChart);
    }
 
    private void refreshBlock4() {
        String id = getTopTaskId();
        Call<List<StatisticsVo>> getStatisticalResultbyId = retrofit.create(ProblemListService.class).getStatisticalResultbyId(id, curSceneTypeId);
        getStatisticalResultbyId.enqueue(new Callback<List<StatisticsVo>>() {
            @Override
            public void onResponse(Call<List<StatisticsVo>> call, Response<List<StatisticsVo>> response) {
                datas.clear();
                if (response.body() != null) {
                    List<StatisticsVo> statisticsVos = response.body();
                    for (StatisticsVo s :
                            statisticsVos) {
                        datas.put(s.getName(), (float) s.getCount());
                    }
                    if (datas.isEmpty()) {
                        pieChart.setVisibility(View.GONE);
                        ll_no_data.setVisibility(View.VISIBLE);
                    } else {
                        pieChart.setVisibility(View.VISIBLE);
                        ll_no_data.setVisibility(View.GONE);
                    }
                    ChartGenerator.quickSetData(pieChart, datas, "问题统计");
                    loadingOver(true);
                } else {
                    loadingOver(false);
                }
            }
 
            @Override
            public void onFailure(Call<List<StatisticsVo>> call, Throwable t) {
                datas.clear();
                ChartGenerator.quickSetData(pieChart, datas, "问题统计");
                loadingOver(false);
            }
        });
    }
    //</editor-fold>
 
    //<editor-fold desc="获取查询参数">
    private String getTopTaskId() {
        return showingTasks.get(offset).getTguid();//返回顶层任务id
    }
    //</editor-fold>
 
    //<editor-fold desc="联网刷新">
    private void refresh() {
        showDialog();
        refreshBlock1();
        refreshBlock2and3();
        refreshBlock4();
    }
    //</editor-fold>
 
 
    //<editor-fold desc="获取弹出框">
    @BindView(R.id.text_type) TextView text_type;
    @BindView(R.id.image_type) ImageView image_type;
 
    RecyclerView rv_popup;
    AllRecyclerViewAdapter<Domainitem> sceneAdapter;
    private List<Domainitem> sceneTypeData = new ArrayList<>();//场景类型
    PopupGenerator popup;
 
    private void initPopup() {
        final DomainitemDao domainitemDao = app.getDaoSession().getDomainitemDao();
        //场景类型
        QueryBuilder<Domainitem> queryBuilder = domainitemDao.queryBuilder()
                .where(DomainitemDao.Properties.Dcguid.eq(Domain.DOMAINGUID_SCENSETYPE))
                .orderAsc(DomainitemDao.Properties.Value);
        sceneTypeData.addAll(queryBuilder.list());
 
        popup = new PopupGenerator(getActivity(), R.layout.popup_scene_selector);
        rv_popup = popup.findViewById(R.id.rv_popup);
        sceneAdapter = new AllRecyclerViewAdapter<Domainitem>(sceneTypeData, R.layout.item_scene, getActivity()) {
            @Override
            public void bindView(AllRecyclerViewAdapter.MyViewHolder holder, final Domainitem obj, boolean isSelected, int position) {
                String sceneType = String.valueOf(obj.getValue());
                holder.setText(R.id.text_scene, obj.getText())
                        .setImageResource(R.id.image_scene, CommonUtils.getIconBySceneType(sceneType))
                        .setOnItemClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                curSceneTypeId = obj.getValue();
                                curSceneTypeName = obj.getText();
                            }
                        });
            }
        };
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 3);
        layoutManager.setOrientation(GridLayoutManager.VERTICAL);
        layoutManager.setAutoMeasureEnabled(true);
        rv_popup.setLayoutManager(layoutManager);
        rv_popup.setAdapter(sceneAdapter);
 
        popup.setPopupWindowFullScreen(false);
    }
    //</editor-fold>
 
    //<editor-fold desc="点击事件">
    //切换顶层任务
    @OnClick({R.id.image_left, R.id.image_right})
    void onClick(View view) {
        int tmpOffset = offset;
        switch (view.getId()) {
            case R.id.image_left:
                int tmp = offset + 1;
                offset = tmp >= showingTasks.size() ? offset : tmp;
                break;
            case R.id.image_right:
                int tmp1 = offset - 1;
                offset = tmp1 < 0 ? offset : tmp1;
                break;
        }
        if (tmpOffset != offset) {
            refreshPannel();
        }
    }
 
    //场景选择菜单
    @OnClick(R.id.ll_menu_text)
    void onClickMenu() {
//        if (popup.isShowing()) {
//            popup.dismiss();
//        } else {
//            popup.showPopupWindow();
//
//        }
    }
 
    //详细内容按钮
    @OnClick({R.id.text_all_2, R.id.text_all_3})
    void onClickMoreInfo(View v) {
        Intent intent = new Intent(getActivity(), AnalysisRankActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable(AnalysisRankActivity.ARG_PARAM1, rankVo);
        bundle.putString(AnalysisRankActivity.ARG_PARAM2, rankVo.getTopTaskName());
        bundle.putString(AnalysisRankActivity.ARG_PARAM3, curSceneTypeName);
        switch (v.getId()) {
            case R.id.text_all_2:
                bundle.putInt(AnalysisRankActivity.ARG_PARAM4, 1);
                break;
            case R.id.text_all_3:
                bundle.putInt(AnalysisRankActivity.ARG_PARAM4, 0);
                break;
        }
        intent.putExtras(bundle);
        startActivity(intent);
    }
 
    //重新加载按钮
    @OnClick(R.id.button_refresh)
    void onClickRefreshButton() {
        refresh();
    }
    //</editor-fold>
 
    //<editor-fold desc="更新当前场景">
    private void refreshCurScene(String id, String name) {
        curSceneTypeId = id;
        curSceneTypeName = name;
 
    }
    //</editor-fold>
 
    //<editor-fold desc="网络加载完成">
    @BindView(R.id.sl_content) ScrollView scrollView;//内容页面
    @BindView(R.id.no_data) View no_data;//加载失败页面
    private void loadingOver(boolean b) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        }, 500);
        if (b) {//加载成功
            scrollView.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
        } else {//加载失败
            scrollView.setVisibility(View.GONE);
            no_data.setVisibility(View.VISIBLE);
        }
    }
    //</editor-fold>
 
    private void showDialog() {
        if (dialog == null) {
            dialog = DialogUtil.createLoadingDialog(getActivity(), "");
        }
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }
 
    private String getScore(int score) {
        return String.valueOf(score == -1 ? "未评分" : score);
    }
 
    //刷新排名信息
    public static void rankS(List<RankVo.SceneRank> sceneRanks) {
        if (sceneRanks == null) return;
        RankVo.SceneRank last = null;
        RankVo.SceneRank current = null;
        int rankNo = 1;
        for (int i = 0; i < sceneRanks.size(); i++) {
            if (i > 0) {
                last = sceneRanks.get(i - 1);
            }
            current = sceneRanks.get(i);
            if (last != null) {
                //同分时并列排名
                if (current.getScore() == last.getScore()) {
                    current.setRankNo(last.getRankNo());
                } else {
                    current.setRankNo(rankNo);
                }
            } else {
                current.setRankNo(rankNo);
            }
            rankNo++;
        }
    }
 
    //刷新排名信息
    private void rankT(List<RankVo.TownRank> townRanks) {
        if (townRanks == null) return;
        RankVo.TownRank last = null;
        RankVo.TownRank current = null;
        int rankNo = 1;
        for (int i = 0; i < townRanks.size(); i++) {
            if (i > 0) {
                last = townRanks.get(i - 1);
            }
            current = townRanks.get(i);
            if (last != null) {
                //同分时并列排名
                if (current.getAverageScore() == last.getAverageScore()) {
                    current.setRankNo(last.getRankNo());
                } else {
                    current.setRankNo(rankNo);
                }
            } else {
                current.setRankNo(rankNo);
            }
            rankNo++;
        }
    }
}