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
package cn.flightfeather.thirdapp.dataanalysis.rank;
 
 
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
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 java.util.ArrayList;
import java.util.List;
 
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.flightfeather.thirdapp.R;
import cn.flightfeather.thirdapp.adapter.AllRecyclerViewAdapter;
import cn.flightfeather.thirdapp.bean.vo.RankVo;
 
public class SceneRankContentFragment extends Fragment {
 
    //<editor-fold desc="全局变量">
    private static final String ARG_PARAM1 = "param1";
 
    private List<RankVo.SceneRank> sceneRanks;
 
    private Unbinder unbinder;
    //</editor-fold>
 
    //<editor-fold desc="constructor">
    public SceneRankContentFragment() {
        // Required empty public constructor
    }
 
    // TODO: Rename and change types and number of parameters
    public static SceneRankContentFragment newInstance(ArrayList<RankVo.SceneRank> params) {
        SceneRankContentFragment fragment = new SceneRankContentFragment();
        Bundle args = new Bundle();
        args.putSerializable(ARG_PARAM1, params);
        fragment.setArguments(args);
        return fragment;
    }
    //</editor-fold>
 
    //<editor-fold desc="lifecycle">
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            sceneRanks = (List<RankVo.SceneRank>) getArguments().getSerializable(ARG_PARAM1);
        }
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_rank_content, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }
 
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }
 
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
 
    //</editor-fold>
 
    //<editor-fold desc="initView">
    @BindView(R.id.rv_content) RecyclerView rv_rank_content;
    AllRecyclerViewAdapter<RankVo.SceneRank> adapter;
 
    private void initView() {
        adapter = 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) {
                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_5);
                        break;
                }
            }
        };
 
        LinearLayoutManager lm = new LinearLayoutManager(getActivity());
        lm.setOrientation(LinearLayoutManager.VERTICAL);
        rv_rank_content.setLayoutManager(lm);
        rv_rank_content.setAdapter(adapter);
    }
    //</editor-fold>
 
    private String getScore(int score) {
        return String.valueOf(score == -1 ? "未评分" : score);
    }
 
 
}